How I Roll - A Cucumber/git workflow

Preview:

DESCRIPTION

Outlines a simple Rails workflow utilizing git, Github Issues, Cucumber, and RSpec. Demonstrates that Cucumber can be used to drive the implementation path.

Citation preview

How I Roll: A Cucumber/git

WorkflowMatt Buck, Capital Thought

Capital Thought

I work for

We make

Agenda

• Creating topic branches in git

• Outside-In model of Rails development

• Merging topic branches

• BONUS ROUND: Getting non-technical stakeholders involved

$ 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

$ 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

$ git checkout -b 13_authors_manage_posts

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

• Write a step definition

• red/green/refactor View

• red/green/refactor Controller

• red/green/refactor Model

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"

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

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"

features/env/paths.rb

when /the create post page for (.*)$/ author = Author.find_by_name($1) new_author_post_path(author)

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"

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

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)) endend

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"

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"

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

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) endend

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 } endend

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"

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)

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"

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.xmldef 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 endend

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"

Fast forward...

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"

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"

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) endend

app/views/posts/new.html.haml

%h1= @post.title

%span#length= @post.total_length

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 == 9end

spec/models/post.rb def total_length title.size + body.sizeend

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"

$ git checkout master$ git merge --squash 13_authors_manage_posts$ git commit -m “Implemented <...> Closes #13”

$ git checkout master$ git merge --squash 13_authors_manage_posts$ git commit -m “Implemented <...> Closes #13”

$ git checkout master$ git merge 13_authors_manage_posts

Bonus Round

How do we get non-technical

stakeholders involved in the story creation

process?

Recommended