David Chelimsky announced today that an experimental version of the story runner for rspec has been committed to the trunk. This move is clearing the path which rspec is taking towards merging the rspec and rbehave frameworks. The code example he gave for this new feature is below:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
|
# The following is based on an experimental Rails-Story adapter
# in RSpec's trunk at rev2480.
#
# You run it by standing in RAILS_ROOT and saying:
# >ruby stories/add_person.rb
#
# Please forgive the lack of RESTful convention (get '/people/create' instead of '/people/new') -
# this works with the existing example app, which is, well, OLD.
# in RAILS_ROOT/stories/helper.rb
ENV["RAILS_ENV"] = "test"
require File.expand_path(File.dirname(__FILE__) + "/../config/environment")
require 'spec/rails/story_adapter'
# in RAILS_ROOT/stories/add_person.rb
require File.join(File.dirname(__FILE__), "helper")
Story "Add Person", %{
As an admin
I want to add people to the system
So that I show how many people use my system
}, :type => RailsStory do
Scenario "Successfully add person" do
Given "no people in the system" do
Person.destroy_all
end
When "creating a new person named", "Dan" do |name|
post "/people/create", :person => {:name => name}
end
Then "viewer should see", "/people/list" do
follow_redirect!
response.should render_template("people/list")
end
Then "list should include", "Dan" do
response.should have_text(/Dan/)
end
end
Scenario "Redirect to create form on failed create" do
Given "no people in the system" do
Person.destroy_all
end
When "creating a new person with no name" do
post "/people/create", :person => {:name => nil}
end
Then "viewer should see", "/people/create" do
assert_template "people/create"
end
Then "list should not include", "Dan" do
response.should_not have_text(/Dan/)
end
end
end
|