Skip to content

Instantly share code, notes, and snippets.

@jccarbonfive
Created March 16, 2012 04:41
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 jccarbonfive/2048540 to your computer and use it in GitHub Desktop.
Save jccarbonfive/2048540 to your computer and use it in GitHub Desktop.
$ rspec spec/requests/homepage_spec.rb
F
Failures:
1) The homepage displays recent posts from Hacker News
Failure/Error: visit '/'
NoMethodError:
undefined method `recent' for HN::Post:Class
# ./app/models/post.rb:3:in `recent'
# ./app/controllers/posts_controller.rb:3:in `index'
# ./spec/requests/homepage_spec.rb:5:in `block (2 levels) in <top (required)>'
Finished in 0.066 seconds
1 example, 1 failure
require 'spec_helper'
describe HN::Post do
describe '.recent', :vcr do
before do
@posts = HN::Post.recent
end
it 'returns recently submitted posts from Hacker News' do
@posts.should_not be_empty
@posts.each do |post|
post.should have_key(:title)
post.should have_key(:url)
post[:url].should match(%r{http://news\.ycombinator\.com})
end
end
end
end
require 'rss'
module HN
class Post
def self.recent
response = Typhoeus::Request.get 'http://news.ycombinator.com/rss'
feed = RSS::Parser.parse response.body
feed.items.collect do |item|
{ title: item.title,
url: item.comments }
end
end
end
end
$ rspec spec/requests/homepage_spec.rb
.
Finished in 0.1785 seconds
1 example, 0 failures
VCR.configure do |config|
config.hook_into :webmock
config.cassette_library_dir = 'spec/fixtures/vcr_cassettes'
config.configure_rspec_metadata!
config.preserve_exact_body_bytes { true }
config.default_cassette_options = {
re_record_interval: 1.week
}
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment