forked from cucumber/cucumber-rails
-
Notifications
You must be signed in to change notification settings - Fork 0
/
emulate_javascript.feature
94 lines (91 loc) · 2.98 KB
/
emulate_javascript.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
Feature: Emulate Javascript
Scenario: See a widget
Given I have created a new Rails app and installed cucumber-rails
And I force selenium to run Firefox in headless mode
And I run `rails generate scaffold widget name:string`
And I write to "features/f.feature" with:
"""
@javascript
Feature: Widget inventory
Scenario: Delete a widget
Given there is a widget named "wrench"
When I go to the widgets page
Then I should see "wrench"
"""
And I write to "features/step_definitions/s.rb" with:
"""
Given /^there is a widget named "([^"]*)"$/ do |name|
FactoryBot.create(:widget, name: name)
end
"""
And I write to "features/support/factories.rb" with:
"""
FactoryBot.define do
factory :widget do
name 'testwidget'
end
end
"""
When I run `bundle exec rake db:migrate`
And I run `bundle exec rake cucumber`
Then the feature run should pass with:
"""
1 scenario (1 passed)
3 steps (3 passed)
"""
Scenario: Pass on the CSRF token
Given I have created a new Rails app and installed cucumber-rails
And I run `rails generate scaffold widget name:string`
And I run `sed -i -e 's/forgery_protection *= false/forgery_protection = true/' config/environments/test.rb`
And I run `rails generate controller session establish`
And I write to "app/controllers/session_controller.rb" with:
"""
class SessionController < ApplicationController
def establish
session[:verified] = true
end
end
"""
And I write to "app/controllers/application_controller.rb" with:
"""
class ApplicationController < ActionController::Base
protect_from_forgery
before_action except: :establish do
render text: "denied", status: :forbidden and return false unless session[:verified]
end
end
"""
And I write to "features/f.feature" with:
"""
Feature: Widget inventory
Scenario: Delete a widget
Given there is a widget named "wrench"
When I go to the session establish page
And I go to the widgets page
Then I should see "wrench"
When I follow "Destroy"
Then I should not see "denied"
And I should be on the widgets page
And I should not see "wrench"
"""
And I write to "features/step_definitions/s.rb" with:
"""
Given /^there is a widget named "([^"]*)"$/ do |name|
FactoryBot.create(:widget, name: name)
end
"""
And I write to "features/support/factories.rb" with:
"""
FactoryBot.define do
factory :widget do
name 'testwidget'
end
end
"""
When I run `bundle exec rake db:migrate`
And I run `bundle exec rake cucumber`
Then the feature run should pass with:
"""
1 scenario (1 passed)
8 steps (8 passed)
"""