Created
December 4, 2013 22:22
-
-
Save kalleth/7796677 to your computer and use it in GitHub Desktop.
shoulda-matchers attempting to create errors container
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' | |
class FakeOrder | |
include ActiveModel::Validations | |
attr_accessor :site_ids, :user_id | |
validate :validate_at_least_one_site_chosen | |
validates_presence_of :user_id | |
def validate_at_least_one_site_chosen | |
errors.add(:site, "please choose at least one site") | |
end | |
end | |
puts "Validating FakeOrder" | |
f = FakeOrder.new | |
f.valid? | |
puts "--> f.errors.messages: #{f.errors.messages}" | |
describe FakeOrder do | |
describe 'validations' do | |
it { should validate_presence_of :user_id } | |
end | |
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
$ be rspec spec/models/fake_order_spec.rb | |
Validating FakeOrder | |
--> f.errors.messages: | |
:site => please choose at least one site | |
FakeOrder | |
validations | |
should require user_id to be set (FAILED - 1) | |
Failures: | |
1) FakeOrder validations | |
Failure/Error: it { should validate_presence_of :user_id } | |
NoMethodError: | |
undefined method `site' for #<FakeOrder:0x1090b88f8> | |
# ./spec/models/fake_order_spec.rb:21 | |
Finished in 0.99055 seconds | |
1 example, 1 failure | |
Failed examples: | |
rspec ./spec/models/fake_order_spec.rb:21 # FakeOrder validations |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment