Skip to content

Commit 7939ad3

Browse files
committed
Posts display at index, rspec set up
Now /posts displays all posts, and we managed to set up rspec so that it works with a test. Sweet.
1 parent 755c942 commit 7939ad3

7 files changed

Lines changed: 50 additions & 0 deletions

File tree

Rakefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ require 'cucumber/rake/task'
44

55
Spec::Rake::SpecTask.new do |t|
66
t.spec_files = FileList['spec/*_spec.rb',]
7+
t.spec_opts = ["--colour", "--backtrace"]
78
end
89

910
Cucumber::Rake::Task.new(:features) do |t|

features/blog.feature

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,9 @@ Feature: The Hackety Blog
1212
Then I should see "Post Created"
1313
And I should see "new title"
1414
And I should see "new body"
15+
Scenario: I can view all posts
16+
Given there is a blog post with the title "First Post"
17+
And there is a blog post with the title "Second Post"
18+
When I go to the posts page
19+
Then I should see "First Post"
20+
And I should see "Second Post"

features/support/paths.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ def path_to(page_name)
1818

1919
when /the new post\s? page/
2020
'/posts/new'
21+
22+
when /the posts page/
23+
'/posts'
2124

2225
# Add more mappings here.
2326
# Here is an example that pulls values out of the Regexp:

hackety.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
use Rack::Session::Cookie, :secret => 'h4ck3ty h4ck f0r gr347 g00d'
99
use Rack::Flash
1010

11+
set :views, File.join(File.dirname(__FILE__), 'views')
12+
1113
configure do
1214
MongoMapper.connection = Mongo::Connection.new('localhost')
1315
MongoMapper.database = 'hackety'
@@ -35,6 +37,11 @@
3537
redirect "/posts/#{@post.id}"
3638
end
3739

40+
get "/posts" do
41+
@posts = Post.all
42+
haml :posts_index
43+
end
44+
3845
get "/posts/:id" do
3946
@post = Post.find(params[:id])
4047
haml :posts_show

spec/hackety_spec.rb

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
require 'rubygems'
2+
require 'sinatra'
3+
require 'spec'
4+
require 'rack/test'
5+
set :environment, :test
6+
7+
require 'hackety'
8+
9+
describe "Hackety Website" do
10+
include Rack::Test::Methods
11+
def app; Sinatra::Application; end
12+
13+
describe "routes" do
14+
it "should display all posts at /posts" do
15+
post1 = mock("Post", :title => "title", :body => "body")
16+
post2 = mock("post", :title => "title", :body => "body")
17+
Post.should_receive(:all).and_return([post1,post2])
18+
get "/posts"
19+
last_response.status.should == 200
20+
end
21+
end
22+
end

spec/posts_spec.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
require 'rubygems'
2+
require 'spec'
3+
require 'mongo_mapper'
4+
require 'models/post'
5+
6+
describe Post do
7+
8+
end

views/posts_index.haml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
%ul
2+
- @posts.each do |post|
3+
%li= post.title

0 commit comments

Comments
 (0)