/
rails3.feature
265 lines (253 loc) · 7.79 KB
/
rails3.feature
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
@announce
Feature: Rails 3
In order to take over the world
Cucumber-Rails should work on major versions
of Rails 3 and Ruby, with Capybara, Spork and DatabaseCleaner
Scenario: Install Cucumber-Rails
Given I have created a new Rails 3 app "rails-3-app" with cucumber-rails support
Then the following files should exist:
| config/cucumber.yml |
| script/cucumber |
| features/step_definitions/web_steps.rb |
| features/support/env.rb |
| features/support/paths.rb |
| features/support/selectors.rb |
| lib/tasks/cucumber.rake |
And the file "features/support/env.rb" should contain "require 'cucumber/rails'"
Scenario: Inspect query string
Given I have created a new Rails 3 app "rails-3-app" with cucumber-rails support
And I successfully run "rails generate cucumber:feature post title:string body:text published:boolean"
And I successfully run "rails generate scaffold post title:string body:text published:boolean"
And I successfully run "rails generate scaffold cukes name:string"
And I overwrite "app/controllers/cukes_controller.rb" with:
"""
class CukesController < ApplicationController
def index
redirect_to cuke_path(10, {:name => 'cucumber', :what => 'vegetable'})
end
def show
render :text => "Cuke #{params[:id]}"
end
end
"""
And I write to "features/tests.feature" with:
"""
Feature: Tests
Scenario: Tests
When I go to the cukes page
Then I should have the following query string:
| name | cucumber |
| what | vegetable |
And I should see "Cuke 10"
"""
And I successfully run "rake db:migrate"
And I run "rake cucumber"
Then it should pass with:
"""
3 scenarios (3 passed)
14 steps (14 passed)
"""
Scenario: Allow rescue
Given I have created a new Rails 3 app "rails-3-app" with cucumber-rails support
And I write to "app/controllers/posts_controller.rb" with:
"""
class PostsController < ApplicationController
def index
raise "There is an error in index"
end
end
"""
And I write to "config/routes.rb" with:
"""
Rails3App::Application.routes.draw do
resources :posts
end
"""
And I write to "features/posts.feature" with:
"""
Feature: posts
@allow-rescue
Scenario: See them
When I do it
"""
And I write to "features/step_definitions/posts_steps.rb" with:
"""
When /^I do it$/ do
visit '/posts'
puts page.body
end
"""
And I run "rake cucumber"
Then it should pass with:
"""
1 scenario (1 passed)
1 step (1 passed)
"""
Scenario: Don't allow rescue
Given I have created a new Rails 3 app "rails-3-app" with cucumber-rails support
And I write to "app/controllers/posts_controller.rb" with:
"""
class PostsController < ApplicationController
def index
raise "There is an error in index"
end
end
"""
And I write to "config/routes.rb" with:
"""
Rails3App::Application.routes.draw do
resources :posts
end
"""
And I write to "features/posts.feature" with:
"""
Feature: posts
Scenario: See them
When I do it
"""
And I write to "features/step_definitions/posts_steps.rb" with:
"""
When /^I do it$/ do
visit '/posts'
end
"""
And I run "rake cucumber"
Then it should fail with:
"""
1 scenario (1 failed)
1 step (1 failed)
"""
Scenario: No ActiveRecord and DatabaseCleaner
Given I have created a new Rails 3 app "rails-3-app" with cucumber-rails support
# Turn off ActiveRecord
And I write to "config/application.rb" with:
"""
require File.expand_path('../boot', __FILE__)
require 'action_controller/railtie'
require 'action_mailer/railtie'
require 'active_resource/railtie'
require 'rails/test_unit/railtie'
Bundler.require(:default, Rails.env) if defined?(Bundler)
module Rails3App
class Application < Rails::Application
config.encoding = "utf-8"
config.filter_parameters += [:password]
end
end
"""
And I remove the file "config/database.yml"
# Remove DatabaseCleaner and SQLite
And I write to "Gemfile" with:
"""
source 'http://rubygems.org'
gem 'rails'
gem "cucumber-rails", :group => :test, :path => "../../.."
gem "capybara", :group => :test
gem "rspec-rails", :group => :test
"""
And I write to "app/controllers/posts_controller.rb" with:
"""
class PostsController < ApplicationController
def index
raise "There is an error in index"
end
end
"""
And I write to "config/routes.rb" with:
"""
Rails3App::Application.routes.draw do
resources :posts
end
"""
And I write to "features/posts.feature" with:
"""
Feature: posts
Scenario: See them
When I do it
"""
And I write to "features/step_definitions/posts_steps.rb" with:
"""
When /^I do it$/ do
visit '/posts'
end
"""
And I run "rake cucumber"
Then it should fail with:
"""
There is an error in index
"""
Scenario: Compare JSON
Given I have created a new Rails 3 app "rails-3-app" with cucumber-rails support
And I write to "app/controllers/posts_controller.rb" with:
"""
class PostsController < ApplicationController
def index
render :json => {'hello' => 'world'}.to_json
end
end
"""
And I write to "config/routes.rb" with:
"""
Rails3App::Application.routes.draw do
resources :posts
end
"""
And I write to "features/posts.feature" with:
"""
Feature: posts
Scenario: See them
When the client requests GET /posts
Then the response should be JSON:
\"\"\"
{
"hello": "world"
}
\"\"\"
"""
And I write to "features/step_definitions/rest_steps.rb" with:
"""
When /^the client requests GET (.*)$/ do |path|
get(path)
end
Then /^the response should be JSON:$/ do |json|
JSON.parse(last_response.body).should == JSON.parse(json)
end
"""
And I run "rake cucumber"
Then it should pass with:
"""
1 scenario (1 passed)
2 steps (2 passed)
"""
Scenario: Look within named selector
Given I have created a new Rails 3 app "rails-3-app" with cucumber-rails support
And I successfully run "rails generate scaffold cukes name:string"
And I overwrite "app/views/cukes/index.html.erb" with:
"""
<div class="foo">foo</div>
<div class="bar">bar</div>
"""
And I write to "features/tests.feature" with:
"""
Feature: Tests
Scenario: Tests
When I go to the cukes page
Then I should see "foo" within the foo div
And I should not see "bar" within the foo div
"""
And I overwrite "features/support/selectors.rb" with:
"""
module HtmlSelectorsHelpers
def selector_for(locator)
return '.foo' if locator == 'the foo div'
end
end
World(HtmlSelectorsHelpers)
"""
And I successfully run "rake db:migrate"
And I run "rake cucumber"
Then it should pass with:
"""
1 scenario (1 passed)
3 steps (3 passed)
"""