stories 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
data/README.markdown CHANGED
@@ -32,22 +32,83 @@ If you are using Rails, you can use stories for your integration tests with Webr
32
32
  class UserStoriesTest < ActionController::IntegrationTest
33
33
  story "As a user I want to log in so that I can access restricted features" do
34
34
  setup do
35
- @user = User.spawn
35
+ @user = User.spawn :name => "Albert", :email => "albert@example.com"
36
36
  end
37
37
 
38
38
  scenario "Using good information" do
39
39
  visit "/"
40
40
  click_link "Log in"
41
- fill_in :session_email, :with => user.email
42
- fill_in :session_password, :with => user.password
41
+ fill_in "Email", :with => user.email
42
+ fill_in "Password", :with => user.password
43
43
  click_button "Sign in"
44
44
 
45
- assert_not_contain "Log in"
46
- assert_not_contain "Sign up"
45
+ assert_contain "Logout"
46
+ assert_contain "Welcome Albert"
47
47
  end
48
48
  end
49
49
  end
50
50
 
51
+ This will produce the following output:
52
+
53
+ - As a user I want to lo in so that I can access restricted features
54
+ Using good information
55
+ Go to “/”
56
+ Click “Log in”
57
+ Fill in “Email” with “albert@example.com”
58
+ Fill in “Password” with “secret”
59
+ Click “Sign in”
60
+ I should see “Logout”
61
+ I should see “Welcome Albert”
62
+
63
+ Custom reports
64
+ --------------
65
+
66
+ Stories ships with reports for many Webrat helpers, but you can write your own version or add reports
67
+ for other helpers.
68
+
69
+ For instance, let's say you add this assertion:
70
+
71
+ module Test::Unit::Assertions
72
+ def assert_current_page(path)
73
+ assert_equal path, current_url.sub(%r{^http://www\.example\.com}, '')
74
+ end
75
+ end
76
+
77
+ When you run it, no output will be generated because Stories doesn't know what to say about this assertion.
78
+ Adding a custom report is easy:
79
+
80
+ module Stories::Webrat
81
+ report_for :assert_current_page do |page|
82
+ "I should be on #{quote(page)}"
83
+ end
84
+ end
85
+
86
+ All this should reside in your `stories_helper.rb`.
87
+
88
+ Step wrappers
89
+ ---------------
90
+
91
+ There are two other methods that are useful for reporting steps or assertions: `silent` and `report`.
92
+
93
+ The `silent` helper gives you the ability to suspend the steps and assertions' normal output:
94
+
95
+ ...
96
+ silent do
97
+ assert_contain "Some obscure hash"
98
+ end
99
+ ...
100
+
101
+ In a similar fashion, `report` lets you replace the normal output with your own message:
102
+
103
+ ...
104
+ report "I verify that the hash generated correctly" do
105
+ assert_contain "The same obscure hash"
106
+ end
107
+ ...
108
+
109
+ Running stories
110
+ ---------------
111
+
51
112
  You can run it normally, it's Test::Unit after all. If you want to run a particular test, say "yet more tests", try this:
52
113
 
53
114
  $ ruby my_test.rb -n test_yet_more_tests
@@ -36,6 +36,23 @@ class Test::Unit::TestCase
36
36
  end
37
37
  end
38
38
 
39
+ module Test::Unit::Assertions
40
+ def report(text, &block)
41
+ @scenario.steps << text
42
+ silent(&block) if block_given?
43
+ end
44
+
45
+ def silent(&block)
46
+ scenario, @scenario = @scenario, Stories::Scenario.new("#{@scenario.name} (Silent)")
47
+
48
+ begin
49
+ block.call
50
+ ensure
51
+ @scenario = scenario
52
+ end
53
+ end
54
+ end
55
+
39
56
  module Stories
40
57
  class Story
41
58
  attr_accessor :name, :scenarios
@@ -126,7 +143,7 @@ module Stories::Webrat
126
143
  report_for :click_link do |name|
127
144
  "Click #{quote(name)}"
128
145
  end
129
-
146
+
130
147
  report_for :click_button do |name|
131
148
  "Click #{quote(name)}"
132
149
  end
@@ -138,7 +155,7 @@ module Stories::Webrat
138
155
  report_for :visit do |page|
139
156
  "Go to #{quote(page)}"
140
157
  end
141
-
158
+
142
159
  report_for :check do |name|
143
160
  "Check #{quote(name)}"
144
161
  end
data/test/all_test.rb CHANGED
@@ -21,6 +21,9 @@ class UserStoryTest < Test::Unit::TestCase
21
21
  end
22
22
 
23
23
  scenario "A call to a helper" do
24
+ report "I use some helper" do
25
+ some_helper
26
+ end
24
27
  assert_equal 1, some_helper
25
28
  end
26
29
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: stories
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Damian Janowski
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2009-06-18 00:00:00 -03:00
13
+ date: 2009-07-11 00:00:00 -03:00
14
14
  default_executable:
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency