Created
July 13, 2011 17:11
-
-
Save macarthy/1080771 to your computer and use it in GitHub Desktop.
Odd error with rspec, rails 3.10rc4 and should-matchers
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
group :test, :development do | |
gem 'ruby-debug19', :require => 'ruby-debug' | |
gem 'passenger' | |
gem 'rspec-rails', '>= 2.6.1' | |
gem 'factory_girl_rails', '>= 1.1.beta1' | |
gem 'cucumber-rails', '>= 0.5.2' | |
gem 'capybara', '>= 1.0.0' | |
gem 'database_cleaner', '>= 0.6.7' | |
gem "rcov" | |
gem "autotest" | |
gem "metric_fu" | |
gem "spork" | |
gem "rb-fsevent" | |
gem 'guard' | |
gem 'guard-cucumber' | |
gem 'guard-rspec' | |
gem 'guard-passenger' | |
gem 'shoulda-matchers', :require => 'shoulda-matchers' | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
F.... | |
Failures: | |
1) Product creating a new product | |
Failure/Error: it { should validate_uniqueness_of(:name) } | |
Can't find first Product | |
# ./spec/models/product_spec.rb:11:in `block (3 levels) in <top (required)>' | |
Finished in 0.43985 seconds | |
5 examples, 1 failure |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'spec_helper' | |
describe Product do | |
context "creating a new product" do | |
it { should validate_uniqueness_of(:name) } | |
it { should validate_presence_of(:name) } | |
it { should validate_presence_of(:description) } | |
it { should validate_presence_of(:price_in_dollars) } | |
it { should validate_numericality_of(:price_in_dollars) } | |
end | |
end |
Actually, it appears that this is the desired function of validate_uniqueness_of(:name)... the tests written for this proves it:
context "without an existing value" do
setup do
assert_nil Example.find(:first)
@matcher = validate_uniqueness_of(:attr)
end
should "fail to require a unique value" do
assert_rejects @matcher, @model
end
should "alert the tester that an existing value is not present" do
@matcher.matches?(@model)
assert @matcher.negative_failure_message =~ /^Can't find first .*/
end
end
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Yeah i am getting this error two, gonna look into it