Feature: Todos
In order to remember things I still need to do
As a user
I want to have a manageable list of todos
Scenario: Add a new todo
Given I am on the todos page
When I follow "Add new todo"
And I fill in "description" with "Talk at ams.rb"
And I press "Add"
Then I should see "Successfully created a new todo"
Feature: Todos
In order to remember things I still need to do
As a user
I want to have a manageable list of todos
Feature: Todos
In order to [Business value]
As a [Role]
I want to [Feature]
Scenario: Add a new todo
Given I am on the todos page
When I follow "Add new todo"
And I fill in "description" with "Talk at ams.rb"
And I press "Add"
Then I should see "Successfully created a new todo"
Given /^(?:|I )am on (.+)$/ do |page_name|
visit path_to(page_name)
end
When /^(?:|I )follow "([^"]*)"$/ do |link|
click_link(link)
end
When /^(?:|I )fill in "([^"]*)" with "([^"]*)"$/ do |field, value|
fill_in(field, :with => value)
end
When /^(?:|I )press "([^"]*)"$/ do |button|
click_button(button)
end
Then /^(?:|I )should see "([^"]*)"$/ do |text|
page.should have_content text
end
Feature: --line option
To run a single example or group, you can use the --line option:
rspec path/to/example_spec.rb --line 37
Scenario: standard examples
Given a file named "example_spec.rb" with:
"""
require "rspec/expectations"
describe 9 do
it "should be > 8" do
9.should be > 8
end
it "should be < 10" do
9.should be < 10
end
end
"""
When I run "rspec example_spec.rb --line 5 --format doc"
Then the output should contain "1 example, 0 failures"
Then the output should contain "should be > 8"
But the stdout should not contain "should be < 10"
$ rails g rspec:install
create .rspec
create spec
create spec/spec_helper.rb
$ rails g steak:install
Defaulting to Capybara...
create spec/acceptance/support
create spec/acceptance/acceptance_helper.rb
create spec/acceptance/support/helpers.rb
create spec/acceptance/support/paths.rb
# spec/acceptance/acceptance_helper.rb
require File.expand_path(File.dirname(__FILE__) + "/../spec_helper")
require "steak"
require 'capybara/rails'
module Steak::Capybara
include Rack::Test::Methods
include Capybara
def app
::Rails.application
end
end
RSpec.configuration.include Steak::Capybara, :type => :acceptance
# Put your acceptance spec helpers inside /spec/acceptance/support
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
$ rails g steak:spec todos
exist spec/acceptance
create spec/acceptance/todos_spec.rb
# spec/acceptance/todos_spec.rb
require File.expand_path(File.dirname(__FILE__) + '/acceptance_helper')
feature "Todos", %q{
In order to ...
As a ...
I want to ...
} do
scenario "Scenario name" do
true.should == true
end
end
feature "Todos", %q{
In order to [Business value]
As a [Role]
I want to [Feature]
} do
feature "Todos", %q{
In order to remember things I still need to do
As a user
I want to have a managable list of todos
} do
scenario "Add a new todo" do
visit todos_page
click_link 'Add new todo'
fill_in 'description', :with => 'Talk at ams.rb'
click_button 'Add'
page.should have_content 'Successfully created a new todo'
end
$ bundle exec rspec spec
1) Todos In order to remember things I still need to do As a user I want to have a manageable list of todos Add a new todo
Failure/Error: visit todos_page NameError: undefined local variable or method `todos_page' for #<:core::examplegroup::nested_1:0x103a53d28>
# ./spec/acceptance/todos_spec.rb:10
1/1: 100% |==========================================| Time: 00:00:00
Finished in 0.076 seconds
1 example, 1 failure