Skip to content

Instantly share code, notes, and snippets.

@rhysforyou
Created November 14, 2011 07:32
Show Gist options
  • Select an option

  • Save rhysforyou/1363450 to your computer and use it in GitHub Desktop.

Select an option

Save rhysforyou/1363450 to your computer and use it in GitHub Desktop.
/Users/rpowell93/.rvm/rubies/ruby-1.9.2-p290/bin/ruby -rrubygems -S /Users/rpowell93/.rvm/gems/[email protected]/gems/rspec-core-2.6.4/bin/rspec --tty '/Users/rpowell93/Projects/rpowell.me/spec/models/post_spec.rb'
......F
Failures:
1) Post should only return published posts in the 'published' scope
Failure/Error: Post.published.count.should == 2
expected: 2
got: 1 (using ==)
# ./spec/models/post_spec.rb:52:in `block (2 levels) in <top (required)>'
Finished in 0.21074 seconds
7 examples, 1 failure
Failed examples:
rspec ./spec/models/post_spec.rb:43 # Post should only return published posts in the 'published' scope
# Test Code #
before(:each) do
@attr = {
:title => "A test post",
:content => "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."
}
end
it "should only return published posts in the 'published' scope" do
past_date = 1.day.ago
past_post = Post.create(@attr.merge(:publish_date => past_date))
present_post = Post.create(@attr)
future_date = 1.day.from_now
future_post = Post.create(@attr.merge(:publish_date => future_date))
Post.published.count.should == 2
end
# Scope definition in post.rb #
scope :published, where('publish_date <= ?', DateTime.now)
@rhysforyou
Copy link
Copy Markdown
Author

/Users/rpowell93/.rvm/rubies/ruby-1.9.2-p290/bin/ruby -rrubygems -S /Users/rpowell93/.rvm/gems/[email protected]/gems/rspec-core-2.6.4/bin/rspec --tty '/Users/rpowell93/Projects/rpowell.me/spec/models/post_spec.rb'
......F

Failures:

  1. Post should only return published posts in the 'published' scope
    Failure/Error: Post.published.count.should == 2
    expected: 2
    got: 1 (using ==)

    ./spec/models/post_spec.rb:52:in `block (2 levels) in <top (required)>'

Finished in 0.21074 seconds
7 examples, 1 failure

Failed examples:

rspec ./spec/models/post_spec.rb:43 # Post should only return published posts in the 'published' scope

@allenwyma
Copy link
Copy Markdown

Answer should be one. Not 2. Today is November 14th. 1 day from now is November 15th and 1 day ago is November 13th. You need to fix your test data.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment