Outlines a simple Rails workflow utilizing git, Github Issues, Cucumber, and RSpec. Demonstrates that Cucumber can be used to drive the implementation path.
3. Agenda
• Creating topic branches in git
• Outside-In model of Rails development
• Merging topic branches
• BONUS ROUND: Getting non-technical
stakeholders involved
4. $ issue list
3. Administrators should be able to manage Users
4. Access should be restricted by Role
6. Users should be able to edit account settings
7. Administrators should be able to import Contacts
13. Authors should be able to manage Posts
14. Authors should be able to register
5. $ issue list
3. Administrators should be able to manage Users
4. Access should be restricted by Role
6. Users should be able to edit account settings
7. Administrators should be able to import Contacts
13. Authors should be able to manage Posts
14. Authors should be able to register
7. Outside-in Rails development
• Write a scenario
• Execute the scenario
• Write a step definition
• red/green/refactor View
• red/green/refactor Controller
• ensure the proper instance variables are
assigned
• red/green/refactor Models
• ensure they provide methods needed by View
and Controller
13. Feature: author manages posts
As an author
I want to be able to manage the posts on my blog
So that my audience can read my content
Background:
Given I am logged in as the following active author account:
| Name | Email address | Password | Phone number | Fax number |
| John | john@myvenue.com | pass | 555-555-1212 | 555-555-1213 |
Scenario: Author adds a new post
When I am on the create post page for John
When I fill in the form with the following values:
| Title | Body |
| First post | Hello, blog! |
And I press "Add post"
Then I should be on the show post page for "First post"
And I should see "Your post has been added."
And I should see "First post"
And I should see "Hello, blog!"
And there should be a new post with the title "First post"
14. Outside-in Rails development
• Write a scenario
• Execute the scenario
• Write a step definition
• red/green/refactor View
• red/green/refactor Controller
• ensure the proper instance variables are
assigned
• red/green/refactor Models
• ensure they provide methods needed by View
and Controller
15. Feature: author manages posts
As an author
I want to be able to manage the posts on my blog
So that my audience can read my content
Background:
Given I am logged in as the following active author account:
| Name | Email address | Password | Phone number | Fax number |
| John | john@myvenue.com | pass | 555-555-1212 | 555-555-1213 |
Scenario: Author adds a new post
When I am on the create post page for John
When I fill in the form with the following values:
| Title | Body |
| First post | Hello, blog! |
And I press "Add post"
Then I should be on the show post page for "First post"
And I should see "Your post has been added."
And I should see "First post"
And I should see "Hello, blog!"
And there should be a new post with the title "First post"
17. Feature: author manages posts
As an author
I want to be able to manage the posts on my blog
So that my audience can read my content
Background:
Given I am logged in as the following active author account:
| Name | Email address | Password | Phone number | Fax number |
| John | john@myvenue.com | pass | 555-555-1212 | 555-555-1213 |
Scenario: Author adds a new post
When I am on the create post page for John
When I fill in the form with the following values:
| Title | Body |
| First post | Hello, blog! |
And I press "Add post"
Then I should be on the show post page for "First post"
And I should see "Your post has been added."
And I should see "First post"
And I should see "Hello, blog!"
And there should be a new post with the title "First post"
18. Outside-in Rails development
• Write a scenario
• Execute the scenario
• Write a step definition
• red/green/refactor View
• red/green/refactor Controller
• ensure the proper instance variables are
assigned
• red/green/refactor Models
• ensure they provide methods needed by View
and Controller
19. spec/views/posts/new.html.haml_spec.rb
describe "/posts/new.html.haml" do
before(:each) do
assigns[:post] = Factory.build :post
@author = Factory.create :author
assigns[:author] = @author
end
it "should render new form" do
render "/events/new.html.haml"
response.should have_tag("form[action=?][method=post]",
author_posts_path(@author))
end
end
app/views/posts/new.html.haml
%h1 New post
- form_for([@author, @post]) do |f|
= render :partial => "form", :locals => {:f => f}
%p= f.submit "Add Post"
20. Feature: author manages posts
As an author
I want to be able to manage the posts on my blog
So that my audience can read my content
Background:
Given I am logged in as the following active author account:
| Name | Email address | Password | Phone number | Fax number |
| John | john@myvenue.com | pass | 555-555-1212 | 555-555-1213 |
Scenario: Author adds a new post
When I am on the create post page for John
When I fill in the form with the following values:
| Title | Body |
| First post | Hello, blog! |
And I press "Add post"
Then I should be on the show post page for "First post"
And I should see "Your post has been added."
And I should see "First post"
And I should see "Hello, blog!"
And there should be a new post with the title "First post"
21. Outside-in Rails development
• Write a scenario
• Execute the scenario
• Write a step definition
• red/green/refactor View
• red/green/refactor Controller
• ensure the proper instance variables
are assigned
• red/green/refactor Models
• ensure they provide methods needed by View
and Controller
22. spec/controllers/posts_controller_spec.rb
describe "responding to GET new" do
def do_get(params = {})
stub_author
get :new, {:author_id => @author}
end
it "should expose a new post as @post" do
post = Factory.build(:post)
Post.should_receive(:new).and_return(post)
do_get
assigns[:post].should equal(post)
end
end
app/controllers/posts_controller.rb
def new
@post = Post.new(params[:post])
respond_to do |format|
format.html # new.html.erb
format.xml { render :xml => @post }
end
end
23. Feature: author manages posts
As an author
I want to be able to manage the posts on my blog
So that my audience can read my content
Background:
Given I am logged in as the following active author account:
| Name | Email address | Password | Phone number | Fax number |
| John | john@myvenue.com | pass | 555-555-1212 | 555-555-1213 |
Scenario: Author adds a new post
When I am on the create post page for John
When I fill in the form with the following values:
| Title | Body |
| First post | Hello, blog! |
And I press "Add post"
Then I should be on the show post page for "First post"
And I should see "Your post has been added."
And I should see "First post"
And I should see "Hello, blog!"
And there should be a new post with the title "First post"
24. features/env/paths.rb
when /the (create|show) post page for (.*)$/
author = Author.find_by_name($2)‚Ä®
case $1
when /create/
new_author_post_path(author)
when /show/
autho_post_path(author)
25. Feature: author manages posts
As an author
I want to be able to manage the posts on my blog
So that my audience can read my content
Background:
Given I am logged in as the following active author account:
| Name | Email address | Password | Phone number | Fax number |
| John | john@myvenue.com | pass | 555-555-1212 | 555-555-1213 |
Scenario: Author adds a new post
When I am on the create post page for John
When I fill in the form with the following values:
| Title | Body |
| First post | Hello, blog! |
And I press "Add post"
Then I should be on the show post page for "First post"
And I should see "Your post has been added."
And I should see "First post"
And I should see "Hello, blog!"
And there should be a new post with the title "First post"
26. spec/controllers/posts_controller_spec.rb
it "should redirect to the created post" do
Post.stub!(:new).and_return(@new_post)
post :create, :post => {}
response.should redirect_to(author_post_url(@author, @new_post))
end
app/controllers/posts_controller.rb
# POST /posts
# POST /posts.xml
def create
@post = @author.posts.new(params[:post])
respond_to do |format|
if @post.save
flash[:notice] = 'Post was successfully created.'
redirect_to author_post_url(@author, @post)
else
render :action => "new"
end
end
end
27. Feature: author manages posts
As an author
I want to be able to manage the posts on my blog
So that my audience can read my content
Background:
Given I am logged in as the following active author account:
| Name | Email address | Password | Phone number | Fax number |
| John | john@myvenue.com | pass | 555-555-1212 | 555-555-1213 |
Scenario: Author adds a new post
When I am on the post creation page for John
When I fill in the form with the following values:
| Title | Body |
| First post! | Hello, blog! |
And I press "Add post"
Then I should be on the show post page for "First post"
And I should see "Your post has been added."
And I should see "First post"
And I should see "Hello, blog!"
And there should be a new post with the title "First post"
29. Feature: author manages posts
As an author
I want to be able to manage the posts on my blog
So that my audience can read my content
Background:
Given I am logged in as the following active author account:
| Name | Email address | Password | Phone number | Fax number |
| John | john@myvenue.com | pass | 555-555-1212 | 555-555-1213 |
Scenario: Author adds a new post
When I am on the post creation page for John
When I fill in the form with the following values:
| Title | Body |
| First post | Hello, blog! |
And I press "Add post"
Then I should be on the show post page for “First Post”
And I should see "Your post has been added."
And I should see "First post"
And I should see "Hello, blog!"
And there should be a new post with the title "First post"
30. Feature: author manages posts
As an author
I want to be able to manage the posts on my blog
So that my audience can read my content
Background:
Given I am logged in as the following active author account:
| Name | Email address | Password | Phone number | Fax number |
| John | john@myvenue.com | pass | 555-555-1212 | 555-555-1213 |
Scenario: Author adds a new post
When I am on the post creation page for John
When I fill in the form with the following values:
| Title | Body |
| First post | Hello, blog! |
And I press "Add post"
Then I should be on the show post page for “First Post”
And I should see "Your post has been added."
And I should see "First post"
And I should see "Hello, blog!"
And I should see "This post contains 22 characters"
And there should be a new post with the title "First post"
31. spec/views/posts/show.html.haml_spec.rb
describe "/posts/show.html.haml" do
before(:each) do
@post = Factory.create :post
@author = Factory.create :author
assigns[:author] = @author
assigns[:post] = @post
@post.stub!(:total_length).and_return(24)
end
it "should display the length of the post in characters" do
render "/events/show.html.haml"
response.should have_tag("span#length", :text => 24)
end
end
app/views/posts/new.html.haml
%h1= @post.title
%span#length= @post.total_length
32. spec/models/post_spec.rb
it "should return the length of the body and title in characters" do
post = Post.create :title => "Title", :body => "Body"
post.total_length.should == 9
end
spec/models/post.rb
def total_length
title.size + body.size
end
33. Feature: author manages posts
As an author
I want to be able to manage the posts on my blog
So that my audience can read my content
Background:
Given I am logged in as the following active author account:
| Name | Email address | Password | Phone number | Fax number |
| John | john@myvenue.com | pass | 555-555-1212 | 555-555-1213 |
Scenario: Author adds a new post
When I am on the post creation page for John
When I fill in the form with the following values:
| Title | Body |
| First post | Hello, blog! |
And I press "Add post"
Then I should be on the show post page for “First Post”
And I should see "Your post has been added."
And I should see "First post"
And I should see "Hello, blog!"
And I should see "This post contains 22 characters"
And there should be a new post with the title "First post"