Showing posts with label shoulda. Show all posts
Showing posts with label shoulda. Show all posts

Friday, February 5, 2010

Running Shoulda & Factory Girl in Rails 3

Rails 3 uses Bundler gem to handle gem dependencies. Encountered some problems with Shoulda and Factory Girl.

# Gemfile

group :test do
gem "shoulda"
gem "factory_girl"
end

Shoulda and Factory Girl macros are not loaded so I had to require the gems in test/test_helper.rb

# test/test_helper.rb

require 'shoulda'
require 'factory_girl'
Factory.definition_file_paths = [ File.join(Rails.root, 'test', 'factories') ]
Factory.find_definitions

Thursday, October 1, 2009

Setup object first before testing validates_uniqueness_of in Shoulda


# This will complain
class SubjectTest < ActiveSupport::TestCase
should_validate_uniqueness_of :name
end

# Error
1) Failure:
test: Subject should require case sensitive unique value for name. (SubjectTest)
[/usr/lib/ruby/gems/1.8/gems/thoughtbot-shoulda-2.10.2/lib/shoulda/assertions.rb:55:in `assert_accepts'
/usr/lib/ruby/gems/1.8/gems/thoughtbot-shoulda-2.10.2/lib/shoulda/active_record/macros.rb:74:in `__bind_1254386647_780301'
/usr/lib/ruby/gems/1.8/gems/thoughtbot-shoulda-2.10.2/lib/shoulda/context.rb:351:in `call'
/usr/lib/ruby/gems/1.8/gems/thoughtbot-shoulda-2.10.2/lib/shoulda/context.rb:351:in `test: Subject should require case sensitive unique value for name. ']:
Can't find first Subject

# Setup object first
class SubjectTest < ActiveSupport::TestCase
setup { Factory(:subject) }
should_validate_uniqueness_of :name
end

Thursday, August 13, 2009

Cucumber > 0.3.7 freezes hash table and changes loading of shoulda


diff --git a/config/environments/test.rb b/config/environments/test.rb

-config.gem "thoughtbot-shoulda", :lib => "shoulda/rails", :source => "http://gems.github.com"
+config.gem "thoughtbot-shoulda", :lib => "shoulda", :source => "http://gems.github.com"


diff --git a/features/step_definitions/enrollment_steps.rb b/features/step_definitions/enrollment_steps.rb

- enrollments.hashes.each do |hash|
+ enrollments.hashes.each do |h|
+ hash = h.dup # Hash is frozen by cucumber. Not sure why.