How I Roll - A Cucumber/git workflow

43
How I Roll: A Cucumber/git Workflow Matt Buck, Capital Thought

description

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

Transcript of How I Roll - A Cucumber/git workflow

Page 1: How I Roll - A Cucumber/git workflow

How I Roll: A Cucumber/git

WorkflowMatt Buck, Capital Thought

Page 2: How I Roll - A Cucumber/git workflow

Capital Thought

I work for

We make

Page 3: How I Roll - A Cucumber/git workflow

Agenda

• Creating topic branches in git

• Outside-In model of Rails development

• Merging topic branches

• BONUS ROUND: Getting non-technical stakeholders involved

Page 4: How I Roll - A Cucumber/git workflow

$ 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

Page 5: How I Roll - A Cucumber/git workflow

$ 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

Page 6: How I Roll - A Cucumber/git workflow

$ git checkout -b 13_authors_manage_posts

Page 7: How I Roll - A Cucumber/git workflow

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

Page 8: How I Roll - A Cucumber/git workflow
Page 9: How I Roll - A Cucumber/git workflow

• Write a step definition

Page 10: How I Roll - A Cucumber/git workflow

• red/green/refactor View

Page 11: How I Roll - A Cucumber/git workflow

• red/green/refactor Controller

Page 12: How I Roll - A Cucumber/git workflow

• red/green/refactor Model

Page 13: How I Roll - A Cucumber/git workflow

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 | [email protected] | 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"

Page 14: How I Roll - A Cucumber/git workflow

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

Page 15: How I Roll - A Cucumber/git workflow

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 | [email protected] | 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"

Page 16: How I Roll - A Cucumber/git workflow

features/env/paths.rb

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

Page 17: How I Roll - A Cucumber/git workflow

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 | [email protected] | 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"

Page 18: How I Roll - A Cucumber/git workflow

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

Page 19: How I Roll - A Cucumber/git workflow

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"

Page 20: How I Roll - A Cucumber/git workflow

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 | [email protected] | 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"

Page 21: How I Roll - A Cucumber/git workflow

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

Page 22: How I Roll - A Cucumber/git workflow

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

Page 23: How I Roll - A Cucumber/git workflow

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 | [email protected] | 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"

Page 24: How I Roll - A Cucumber/git workflow

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)

Page 25: How I Roll - A Cucumber/git workflow

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 | [email protected] | 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"

Page 26: How I Roll - A Cucumber/git workflow

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

Page 27: How I Roll - A Cucumber/git workflow

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 | [email protected] | 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"

Page 28: How I Roll - A Cucumber/git workflow

Fast forward...

Page 29: How I Roll - A Cucumber/git workflow

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 | [email protected] | 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"

Page 30: How I Roll - A Cucumber/git workflow

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 | [email protected] | 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"

Page 31: How I Roll - A Cucumber/git workflow

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

Page 32: How I Roll - A Cucumber/git workflow

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

Page 33: How I Roll - A Cucumber/git workflow

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 | [email protected] | 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"

Page 34: How I Roll - A Cucumber/git workflow

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

Page 35: How I Roll - A Cucumber/git workflow
Page 36: How I Roll - A Cucumber/git workflow

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

Page 37: How I Roll - A Cucumber/git workflow

$ git checkout master$ git merge 13_authors_manage_posts

Page 38: How I Roll - A Cucumber/git workflow
Page 39: How I Roll - A Cucumber/git workflow

Bonus Round

Page 40: How I Roll - A Cucumber/git workflow

How do we get non-technical

stakeholders involved in the story creation

process?

Page 41: How I Roll - A Cucumber/git workflow
Page 42: How I Roll - A Cucumber/git workflow