-
-
Save jccarbonfive/2048534 to your computer and use it in GitHub Desktop.
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' | |
| describe 'The homepage', :vcr do | |
| before do | |
| visit '/' | |
| end | |
| it 'displays recent posts from Hacker News' do | |
| hacker_news_links = all '#hn .post a' | |
| hacker_news_links.should_not be_empty | |
| hacker_news_links.each do |link| | |
| link[:href].should match(%r{http://news\.ycombinator\.com}) | |
| end | |
| 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
| $ rspec spec/requests/homepage_spec.rb | |
| F | |
| Failures: | |
| 1) The homepage displays recent posts from Hacker News | |
| Failure/Error: visit '/' | |
| ActionController::RoutingError: | |
| No route matches [GET] "/" | |
| # ./spec/requests/homepage_spec.rb:5:in `block (2 levels) in <top (required)>' | |
| Finished in 0.05392 seconds | |
| 1 example, 1 failure |
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
| Sample::Application.routes.draw do | |
| root to: 'posts#index' | |
| 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
| #hn | |
| - @recent_posts.each do |post| | |
| .post | |
| = link_to post.title, post.url |
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
| class PostsController < ApplicationController | |
| def index | |
| @recent_posts = Post.recent | |
| 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
| $ rspec spec/requests/homepage_spec.rb F | |
| Failures: | |
| 1) The homepage displays recent posts from Hacker News | |
| Failure/Error: visit '/' | |
| NameError: | |
| uninitialized constant PostsController::Post | |
| # ./app/controllers/posts_controller.rb:3:in `index' | |
| # ./spec/requests/homepage_spec.rb:5:in `block (2 levels) in <top (required)>' | |
| Finished in 0.07371 seconds | |
| 1 example, 1 failure |
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' | |
| describe Post do | |
| describe '.recent' do | |
| before do | |
| posts = [ | |
| { title: 'Post #1', url: 'http://example.com/1' }, | |
| { title: 'Post #2', url: 'http://example.com/2' }, | |
| { title: 'Post #3', url: 'http://example.com/3' } | |
| ] | |
| HN::Post | |
| .should_receive(:recent) | |
| .and_return(posts) | |
| @recent_posts = Post.recent | |
| end | |
| it 'returns recent posts' do | |
| @recent_posts.should have(3).posts | |
| end | |
| it 'sets their title' do | |
| @recent_posts.each do |post| | |
| post.title.should be | |
| end | |
| end | |
| it 'sets their url' do | |
| @recent_posts.each do |post| | |
| post.url.should be | |
| end | |
| end | |
| 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
| module HN | |
| class Post | |
| 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
| class Post | |
| def self.recent | |
| posts = HN::Post.recent | |
| posts.collect do |post| | |
| new post | |
| end | |
| end | |
| attr_accessor :title, | |
| :url | |
| def initialize(attributes) | |
| self.title = attributes[:title] | |
| self.url = attributes[:url] | |
| 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
| In order to find interesting links for the intellectually curious | |
| As a user | |
| I want to see the latest Hacker News posts on the homepage |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment