Skip to content

Instantly share code, notes, and snippets.

@macarthy
Created July 13, 2011 17:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save macarthy/1080771 to your computer and use it in GitHub Desktop.
Save macarthy/1080771 to your computer and use it in GitHub Desktop.
Odd error with rspec, rails 3.10rc4 and should-matchers
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
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
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
@chaffeqa
Copy link

chaffeqa commented Sep 7, 2011

Yeah i am getting this error two, gonna look into it

@chaffeqa
Copy link

chaffeqa commented Sep 7, 2011

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