I have Rspec + Shoulda + FactoryGirl and I am receiving the following error when attempting to call Shoulda's have_many or belong_to methods. All Shoulda methods used in the "validations" group work fine:
> NoMethodError in 'A Project
> associations should When you call a
> matcher in an example without a
> String, like this:
>
> s...
Hi,
I'm using shoulda with Ruby on Rails, and I have the following test cases:
class BirdTest < Test::Unit::TestCase
context "An eagle" do
setup do
@eagle = Eagle.new
end
should "be able to fly" do
assert_true @eagle.can_fly?
end
end
context "A Crane" do
setup do
@cra...
I keep getting validation errors when running factories due to uniqueness constraints on fields. I am using shoulda with factory_girl. I have a both a unit test and a functional test creating 2 products in the database. I can run 'rake test:units' and 'rake test:functionals' over and over in any order and everything is will be green b...
I am (finally) attempting to write some integration tests for my application (because every deploy is getting scarier). Since testing is a horribly documented feature of Rails, this was the best I could get going with shoulda.
class DeleteBusinessTest < ActionController::IntegrationTest
context "log skydiver in and" do
setup do...
I am having some trouble getting the right usage of Machinist and Shoulda in my testing.
Here is my test:
context "on POST method rating" do
p = Product.make
u = nil
setup do
u = login_as
post :vote, :rating => 3, :id => p
end
should "set rating for product to 3" do
assert_equal p.get_user_vote(u), 3
end
And here's my bluepri...
I think shoulda is really neat, but what I don't understand is why some of the macros exist, such as:
should_validate_uniqueness_of :title
should_validate_presence_of :body, :message => /wtf/
should_validate_presence_of :title
should_validate_numericality_of :user_id
I'm relatively new to testing, but what purpose do these serve? The...
I've setup Rspec2 beta5 and shoulda as following to use shoulda macros inside rspec model tests.
Gemfile
group :test do
gem "rspec", ">= 2.0.0.beta.4"
gem "rspec-rails", ">= 2.0.0.beta.4"
gem 'shoulda', :git => 'git://github.com/bmaddy/
shoulda.git'
gem "faker"
gem "machinist"
gem "pickle", :git => 'git:/...
In one of my model's I'm using some meta programming to dynamically define some methods. I'd like to test this; thus, I need a compact way to assert my model has a readable/writable attribute with a certain name. Ideas?
I'm using shoulda for unit testing if it makes a difference.
...
I'm trying to do something like the following:
@special_attributes = Model.new.methods.select # a special subset
@special_attributes.each do |attribute|
context "A model with #{attribute}" do
setup do
@model = Model.new
end
should "respond to it by name" do
assert_respond_to @model, attribute
end
end
end
...
i am trying to simulate a session using factory girl/shoulda (it worked with fixtures but i am having problems with using factories). i have following factories (user login and email both have 'unique' validations):
Factory.define :user do |u|
u.login 'quentin'
u.email '[email protected]'
end
Factory.define :session_user, :class =...
Asking this question again with smaller code sample:
# this is a dummy shoulda macro that creates a context
def self.macro_context
context "macro" do
yield
end
end
# i am expecting this test to fail within the macro context
context "some context" do
macro_context do
should "test" do
fail
...
I'm able to get my Gemfile how I like it:
# Gemfile
source "http://gemcutter.org"
gem "rails", :git => "git://github.com/rails/rails.git"
git "git://github.com/rails/arel.git"
git "git://github.com/rails/rack.git"
gem "sqlite3-ruby"
group :test do
gem "shoulda", :git => "git://github.com/thoughtbot/shoulda.git", :branch => ...
I am trying to get the whole setup working with Autotest/Growl/Shoulda on my Mac to test a gem I'm working on for Authlogic. I've used RSpec in the past quite a bit but would like to switch to Shoulda.
This gem is going to work with Rails, but others gems I've made are just plain old ruby libraries with no dependencies on Rails modules...
Hello,
I'm having some difficulties in testing devise with shoulda:
2) Error:
test: handle :index logged as admin should redirect to Daily page.
(Admin::DailyClosesControllerTest):
NoMethodError: undefined method `env' for nil:NilClass
devise (1.0.6) [v] lib/devise/test_helpers.rb:52:in
`setup_controller_for_warden'
I have this in my...
Hi there.
It's rather hard to find any documentation on Mocha, so I'm afraid I'm totally at sea here. I have found a problem with stubbing methods that pass arguments. So for instance if I set up a class like this:
class Red
def gets(*args)
@input.gets(*args)
end
def puts(*args)
@output.puts(*args)
end
def initial...
I'm trying to implement shoulda unit tests on a rails 2.3.5 app using mongomapper.
So far I've:
Configured a rails app that uses mongomapper (the app works)
Added shoulda to my gems, and installed it with rake gems:install
Added config.frameworks -= [ :active_record, :active_resource ] to config/environment.rb so ActiveRecord isn't us...
Can someone provide a strategy/code samples/pointers to test Captcha validations + Authlogic using Shoulda, Factory Girl and Mocha?
For instance, my UsersController is something like:
class UsersController < ApplicationController
validates_captcha
...
def create
...
if captcha_validated?
# code to deal with user attributes
end
....
I have installed both shoulda and factory_girl, I can run shoulda just fine, but when I add this:
require 'factory_girl'
Factory.define :user do |u|
u.mail '[email protected]'
u.pass 'secret'
end
to my test/test_helper.rb I'm getting this error:
/test/test_helper.rb:1:in `require': no such file to load -- factory_girl (LoadError)...
I am trying to test a couple models that have an attachment with Paperclip. I have all of my validations passing except for the content-type check.
# myapp/test/unit/project_test.rb
should_have_attached_file :logo
should_validate_attachment_presence :logo
should validate_attachment_size(:logo).less_than(1.megabyte)
should_validate_atta...
I am trying to test a model's attributes for formatting with this:
# myapp/test/unit/comment_test.rb
require 'test_helper'
class CommentTest < ActiveSupport::TestCase
should_belong_to :article
should_validate_presence_of :name
should_validate_presence_of :email
should_validate_presence_of :content
should_validate_presence_of...