Professional Documents
Culture Documents
Development
With
Ben Mabey
Saturday, March 14, 2009
Who’s my
audience?
http://
www.theregister.co.uk/
2007/06/25/
Increase Revenue
Manage Cost
* business value
* stakeholder role
* user role
* action to be taken by
user
Given a widget
We ain’t got
no RSPEC!
SO DAT I CAN HAS HUGS TIEM AN PLAY TIEM AN SLEEP TIEM AN NOM TIEM
AS NICE GREEDEE KITTEH
I CAN PLZ MANEGE TEH WISHEZ
end
end
end
end
visit new_session_path
fill_in "Email", :with => @current_user.email
fill_in "Password", :with => valid_user_attributes["password"]
click_button
end
visit new_session_path
fill_in "Email", :with => @current_user.email
fill_in "Password", :with => valid_user_attributes["password"]
click_button
end
visit new_session_path
fill_in "Email", :with => @current_user.email
fill_in "Password", :with => valid_user_attributes["password"]
click_button
end
visit new_session_path
fill_in "Email", :with => @current_user.email
fill_in "Password", :with => valid_user_attributes["password"]
click_button
end
features/support/env.rb
require 'webrat'
Webrat.configure do |config|
config.mode = :rails
end
visit new_session_path
fill_in "Email", :with => @current_user.email
fill_in "Password", :with => valid_user_attributes["password"]
click_button
end
features/support/env.rb
require 'webrat'
Webrat.configure do |config|
config.mode = :rails
end
Adapter
visit new_session_path
fill_in "Email", :with => @current_user.email
fill_in "Password", :with => valid_user_attributes["password"]
click_button
end
features/step_definitions/webrat_steps.rb
When /^I press "(.*)"$/ do |button|
click_button(button)
end
19 Steps Out-of-box
When /^I follow "(.*)"$/ do |link|
click_link(link)
end
visit new_session_path
fill_in "Email", :with => @current_user.email
fill_in "Password", :with => valid_user_attributes["password"]
click_button
end
visit new_session_path
fill_in "Email", :with => @current_user.email
fill_in "Password", :with => valid_user_attributes["password"]
click_button
# make sure we have actually logged in- so we fail fast if not
session[:user_id].should == @current_user.id
end
visit new_session_path
fill_in "Email", :with => @current_user.email
fill_in "Password", :with => valid_user_attributes["password"]
click_button
# make sure we have actually logged in- so we fail fast if not
session[:user_id].should == @current_user.id
controller.current_user.should == @current_user
end
visit new_session_path
Specify outcome, not implementation.
fill_in "Email", :with => @current_user.email
fill_in "Password", :with => valid_user_attributes["password"]
click_button
# make sure we have actually logged in- so we fail fast if not
session[:user_id].should == @current_user.id
controller.current_user.should == @current_user
response.should contain("Signed in successfully")
end
visit new_session_path
fill_in "Email", :with => @current_user.email
fill_in "Password", :with => valid_user_attributes["password"]
click_button
# make sure we have actually logged in- so we fail fast if not
response.should contain("Signed in successfully")
end
end
end
end
end
end
map.resources :wishes
map.resources :wishes
map.resources :wishes
map.resources :wishes
app/views/wishes/new.html.erb
<% form_for :wish do |f| %>
<%= f.label :name, "Wish" %>
<%= f.text_field :name %>
<%= submit_tag "Make the wish!" %>
<% end %>
Controller
end
end
it "should create a new wish for the user with the params" do
user = mock_model(User, :wishes => mock("wishes association"))
controller.stub!(:current_user).and_return(user)
user.wishes.should_receive(:create).with(wish_params)
def create
current_user.wishes.create(params['wish'])
end
end
end
end
Controller
Model
app/models/user.rb
class User < ActiveRecord::Base
include Clearance::App::Models::User
has_many :wishes
end
app/models/user.rb
When I make a “New car” wish
class User < ActiveRecord::Base
Then “New car” should appear on my wish
include Clearance::App::Models::User
expected the following element’s content to include
has_many :wishes
“Your wish has been added!”
end
app/controllers/wishes_controller.rb
def create
current_user.wishes.create(params['wish'])
flash[:success] = "Your wish has been added!"
redirect_to :action => :index
end
app/controllers/wishes_controller.rb
Then “New car” should appear on my wish
expected the following element’s content to include
def create
“New car”
current_user.wishes.create(params['wish'])
flash[:success] = "Your wish has been added!"
redirect_to :action => :index
end
end
features/step_definitions/wish_steps.rb
Given /^the following wishes exist$/ do |table|
end
end
features/step_definitions/wish_steps.rb
Given /^the following wishes exist$/ do |table|
table.hashes.each do |row|
member = User.find_by_name(row["Family Member"]) ||
create_user(:name => row["Family Member"])
Examples:
| input_1 | input_2 | button | output |
| 20 | 30 | add | 50 |
| 2 | 5 | add | 7 |
| 0 | 40 | add | 40 |
Examples:
| input_1 | input_2 | button | output |
| 20 | 30 | add | 50 |
| 2 | 5 | add | 7 |
| 0 | 40 | add | 40 |
Examples:
| input_1 | input_2 | button | output |
| 20 | 30 | add | 50 |
| 2 | 5 | add | 7 |
| 0 | 40 | add | 40 |
Examples:
| input_1 | input_2 | button | output |
| 20 | 30 | add | 50 |
| 2 | 5 | add | 7 |
| 0 | 40 | add | 40 |
Examples:
| input_1 | input_2 | button | output |
| 20 | 30 | add | 50 |
| 2 | 5 | add | 7 |
| 0 | 40 | add | 40 |
visit new_session_path
fill_in "Email", :with => @current_user.email
fill_in "Password", :with => valid_user_attributes["password"]
click_button
end
def login_as(user)
visit new_session_path
fill_in "Email", :with => user.email
fill_in "Password", :with => valid_user_attributes["password"]
click_button
# make sure we have actually logged in- so we fail fast if not
response.should contain("Signed in successfully")
end
def login_as(user)
visit new_session_path
fill_in "Email", :with => user.email
fill_in "Password", :with => valid_user_attributes["password"]
click_button
# make sure we have actually logged in- so we fail fast if not
response.should contain("Signed in successfully")
end
def login_as(user)
visit new_session_path
fill_in "Email", :with => user.email
fill_in "Password", :with => valid_user_attributes["password"]
click_button “Every time you monkeypatch
# make sure we have actually logged in- so we fail fast if not
Object, a kitten dies.”
response.should contain("Signed in successfully")
end
http://seanohalpin.github.com/unobtrusive-metaprogramming/unobtrusive-metaprogramming.html