Created
March 16, 2012 04:41
-
-
Save jccarbonfive/2048540 to your computer and use it in GitHub Desktop.
This file contains 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
$ 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 |
This file contains 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' | |
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 |
This file contains 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 '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 |
This file contains 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
$ rspec spec/requests/homepage_spec.rb | |
. | |
Finished in 0.1785 seconds | |
1 example, 0 failures |
This file contains 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
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