Created
June 24, 2011 16:36
-
-
Save ivanoats/1045159 to your computer and use it in GitHub Desktop.
How does this validation fail in console but not in rspec?
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
ivan:~/Development/ruby/IvanEnviromanRefinery [git:master+] → bundle exec rspec ../refinerycms-link/ | |
.............................F. | |
Failures: | |
1) BlogPost bookmark links must have a link url if it is a link | |
Failure/Error: Factory.build(:post, | |
expected valid? to return false, got true | |
# /Users/ivan/Development/ruby/refinerycms-link/spec/models/blog_post_spec.rb:197:in `block (3 levels) in <top (required)>' | |
Finished in 6.56 seconds | |
31 examples, 1 failure | |
Failed examples: | |
rspec /Users/ivan/Development/ruby/refinerycms-link/spec/models/blog_post_spec.rb:196 # BlogPost bookmark links must have a link url if it is a link | |
ivan:~/Development/ruby/IvanEnviromanRefinery [git:master+] → rails console | |
Loading development environment (Rails 3.0.9) | |
ruby-1.9.2-p180 :001 > b = BlogPost.new | |
=> #<BlogPost id: nil, title: nil, body: nil, draft: nil, published_at: nil, created_at: nil, updated_at: nil, user_id: nil, cached_slug: nil, custom_url: nil, link_url: nil, is_link: nil, custom_teaser: nil> | |
ruby-1.9.2-p180 :002 > b.title=' 2011-06-24 8:34 ' | |
=> " 2011-06-24 8:34 " | |
ruby-1.9.2-p180 :003 > b.body='goo' | |
=> "goo" | |
ruby-1.9.2-p180 :004 > b.is_link = true | |
=> true | |
ruby-1.9.2-p180 :005 > b.valid? | |
=> false | |
ruby-1.9.2-p180 :007 > b.save | |
=> false | |
ruby-1.9.2-p180 :008 > b.errors | |
=> {:link_url=>["must have a link_url if is_link is true"]} | |
ruby-1.9.2-p180 :009 > |
blog_post_spec.rb
require 'spec_helper'
Dir[File.expand_path('../../../features/support/factories/*.rb', __FILE__)].each{|factory| require factory}
describe BlogPost do
let(:blog_post ) { Factory :post }
...
describe "bookmark links" do
it "may have a bookmark link" do
Factory.build(:post,
:title => "a link",
:body => "link text",
:is_link => true,
:link_url => "http://example.com").should be_valid
end
it "must have a link url if it is a link" do
Factory.build(:post,
:title => "a link",
:body => "link text",
:is_link => true).should_not be_valid
end
end
so, this all works fine if you use .should be_invalid
and now it's working the original way. perhaps re-starting spork did the trick? borked by spork
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
ok, so I also built the factory in console, and it's not a problem with factory_girl