acceptance_test 1.5.5 → 1.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +8 -8
- data/CHANGES +5 -1
- data/Gemfile +4 -1
- data/Gemfile.lock +11 -11
- data/Rakefile +0 -6
- data/features/wikipedia/step_definitions/steps.rb +2 -2
- data/lib/acceptance_test/acceptance_test.rb +57 -140
- data/lib/acceptance_test/driver_manager.rb +138 -0
- data/lib/acceptance_test/{gherkin_helper.rb → gherkin_ext.rb} +2 -5
- data/lib/acceptance_test/page_set.rb +38 -1
- data/lib/acceptance_test/turnip_ext.rb +177 -0
- data/lib/acceptance_test/version.rb +1 -1
- data/lib/tasks/rspec.rake +7 -0
- data/spec/{features/data.csv → data.csv} +0 -0
- data/spec/features/search_with_drivers.feature +4 -3
- data/spec/features/search_with_examples_from_csv.feature +1 -1
- data/spec/features/search_with_pages.feature +13 -0
- data/spec/support/pages/main_page.rb +17 -0
- data/spec/support/{wikipedia/wikipedia_page_set.rb → pages/wikipedia_pages.rb} +8 -5
- data/spec/{features → support}/steps/common_steps.rb +0 -0
- data/spec/{features → support}/steps/search_with_drivers_steps.rb +2 -17
- data/spec/{features → support}/steps/search_with_examples_from_csv_steps.rb +1 -1
- data/spec/support/steps/search_with_pages_steps.rb +37 -0
- data/spec/{features → support}/steps/search_with_table_steps.rb +1 -1
- data/spec/test_helper.rb +1 -0
- data/spec/turnip_helper.rb +8 -9
- data/spec/wikipedia_search_spec.rb +5 -0
- data/spec/wikipedia_search_with_pages_spec.rb +8 -8
- metadata +26 -19
- data/lib/acceptance_test/turnip_helper.rb +0 -76
- data/spec/support/wikipedia/main_page.rb +0 -13
- data/turnip +0 -1
@@ -1,11 +1,8 @@
|
|
1
|
-
require 'singleton'
|
2
|
-
|
3
1
|
require 'gherkin/lexer/i18n_lexer'
|
4
2
|
|
5
|
-
class
|
6
|
-
include Singleton
|
3
|
+
class GherkinExt
|
7
4
|
|
8
|
-
def enable_external_source data_reader
|
5
|
+
def self.enable_external_source data_reader
|
9
6
|
lexer = Gherkin::Lexer::I18nLexer
|
10
7
|
|
11
8
|
lexer.class_eval do
|
@@ -5,8 +5,14 @@ require 'acceptance_test/page'
|
|
5
5
|
class PageSet
|
6
6
|
extend Forwardable
|
7
7
|
|
8
|
+
attr_reader :pages
|
8
9
|
attr_accessor :session
|
9
10
|
|
11
|
+
def initialize session=nil
|
12
|
+
@session = session
|
13
|
+
@pages = []
|
14
|
+
end
|
15
|
+
|
10
16
|
def page
|
11
17
|
session
|
12
18
|
end
|
@@ -22,16 +28,47 @@ class PageSet
|
|
22
28
|
end
|
23
29
|
|
24
30
|
def delegate_to_page page
|
31
|
+
@pages << page
|
32
|
+
|
25
33
|
self.class.send :attr_reader, page
|
26
34
|
|
35
|
+
self.class.def_delegators page, *page_methods(page)
|
36
|
+
end
|
37
|
+
|
38
|
+
def page_methods page
|
27
39
|
clazz = self.send(page).class
|
28
40
|
|
29
|
-
|
41
|
+
clazz.instance_methods - Page.instance_methods
|
42
|
+
end
|
43
|
+
|
44
|
+
def enable_smart_completion context
|
45
|
+
if context
|
46
|
+
context.class.send(:define_method, :method_missing) do |method_name, *args, &block|
|
47
|
+
page_set.send method_name, *args, &block
|
48
|
+
end
|
49
|
+
|
50
|
+
page_set = self
|
51
|
+
|
52
|
+
pages.each do |page|
|
53
|
+
page_methods(page).each do |method_name|
|
54
|
+
method = page_set.method(method_name)
|
55
|
+
|
56
|
+
context.class.step "I #{method_name.to_s.gsub('_', ' ')}" do |*args|
|
57
|
+
page_set.send method_name, *args
|
58
|
+
end
|
59
|
+
|
60
|
+
context.class.step "#{method.to_s.gsub('_', ' ')}" do
|
61
|
+
page_set.send method_name, *args
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
30
65
|
end
|
66
|
+
end
|
31
67
|
|
32
68
|
private
|
33
69
|
|
34
70
|
def camelize string
|
35
71
|
string.split("_").each {|s| s.capitalize! }.join("")
|
36
72
|
end
|
73
|
+
|
37
74
|
end
|
@@ -0,0 +1,177 @@
|
|
1
|
+
require 'turnip/define'
|
2
|
+
|
3
|
+
class TurnipExt
|
4
|
+
def self.shared_context_with_turnip context_name
|
5
|
+
turnip_rspec = Turnip::RSpec
|
6
|
+
|
7
|
+
turnip_rspec.class_eval do
|
8
|
+
@context_name = context_name # class instance variable
|
9
|
+
|
10
|
+
def self.context_name # access to class instance variable
|
11
|
+
@context_name
|
12
|
+
end
|
13
|
+
|
14
|
+
class << self
|
15
|
+
def run(feature_file)
|
16
|
+
Turnip::Builder.build(feature_file).features.each do |feature|
|
17
|
+
::RSpec.describe feature.name, feature.metadata_hash do
|
18
|
+
|
19
|
+
include_context Turnip::RSpec.context_name
|
20
|
+
|
21
|
+
before do
|
22
|
+
example = Turnip::RSpec.fetch_current_example(self)
|
23
|
+
# This is kind of a hack, but it will make RSpec throw way nicer exceptions
|
24
|
+
example.metadata[:file_path] ||= feature_file
|
25
|
+
|
26
|
+
feature.backgrounds.map(&:steps).flatten.each do |step|
|
27
|
+
run_step(feature_file, step)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
feature.scenarios.each do |scenario|
|
31
|
+
instance_eval <<-EOS, feature_file, scenario.line
|
32
|
+
describe scenario.name, scenario.metadata_hash do it(scenario.steps.map(&:to_s).join(' -> ')) do
|
33
|
+
scenario.steps.each do |step|
|
34
|
+
run_step(feature_file, step)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
EOS
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
def self.build_dynamic_steps page_set, context
|
48
|
+
# if context
|
49
|
+
# context.class.send(:define_method, :method_missing) do |meth, *args, &block|
|
50
|
+
# page_set.send meth, *args, &block
|
51
|
+
# end
|
52
|
+
# end
|
53
|
+
|
54
|
+
##self.class.step :enter_word, "I enter word :word"
|
55
|
+
|
56
|
+
# turnip_rspec_execute = Turnip::RSpec::Execute
|
57
|
+
#
|
58
|
+
# turnip_rspec_execute.class_eval do
|
59
|
+
# alias_method :old_run_step, :run_step
|
60
|
+
#
|
61
|
+
# def run_step(feature_file, step)
|
62
|
+
# begin
|
63
|
+
# instance_eval <<-EOS, feature_file, step.line
|
64
|
+
# step(step)
|
65
|
+
# EOS
|
66
|
+
# rescue Turnip::Pending => e
|
67
|
+
#
|
68
|
+
# # instance_eval <<-EOS, feature_file, step.line
|
69
|
+
# # step(:visit_home_page, "I am on wikipedia.com")
|
70
|
+
# # EOS
|
71
|
+
#
|
72
|
+
# # page_set.pages.each do |page|
|
73
|
+
# # page_set.page_methods(page).each do |method|
|
74
|
+
# # context.class.step "I #{method.to_s.gsub('_', ' ')}" do
|
75
|
+
# # send method
|
76
|
+
# # end
|
77
|
+
# #
|
78
|
+
# # # context.class.step method, "I #{method.to_s.gsub('_', ' ')}"
|
79
|
+
# # #
|
80
|
+
# # # context.class.step method, "#{method.to_s.gsub('_', ' ')}"
|
81
|
+
# # end
|
82
|
+
# # end
|
83
|
+
#
|
84
|
+
# old_run_step feature_file, step
|
85
|
+
# end
|
86
|
+
# end
|
87
|
+
# end
|
88
|
+
|
89
|
+
|
90
|
+
# page_set.pages.each do |page|
|
91
|
+
# page_set.page_methods(page).each do |method|
|
92
|
+
# page_set.class.step "I #{method.to_s.gsub('_', ' ')}" do
|
93
|
+
# send method
|
94
|
+
# end
|
95
|
+
#
|
96
|
+
# page_set.class.step "#{method.to_s.gsub('_', ' ')}" do
|
97
|
+
# send method
|
98
|
+
# end
|
99
|
+
# end
|
100
|
+
# end
|
101
|
+
end
|
102
|
+
|
103
|
+
def extend_turnip
|
104
|
+
turnip_define = Turnip::Define
|
105
|
+
|
106
|
+
turnip_define.class_eval do
|
107
|
+
def before &block
|
108
|
+
send(:define_method, "before", &block) if block
|
109
|
+
end
|
110
|
+
|
111
|
+
def after &block
|
112
|
+
send(:define_method, "after", &block) if block
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
turnip_rspec_execute = Turnip::RSpec::Execute
|
117
|
+
|
118
|
+
turnip_rspec_execute.class_eval do
|
119
|
+
def run_before rspec_root
|
120
|
+
self.class.send(:define_method, :rspec_root, lambda { rspec_root })
|
121
|
+
|
122
|
+
before
|
123
|
+
end
|
124
|
+
|
125
|
+
def run_after rspec_root
|
126
|
+
self.class.send(:define_method, :rspec_root, lambda { rspec_root })
|
127
|
+
|
128
|
+
after
|
129
|
+
end
|
130
|
+
end
|
131
|
+
|
132
|
+
turnip_rspec = Turnip::RSpec
|
133
|
+
|
134
|
+
turnip_rspec.class_eval do
|
135
|
+
@shared_context_name = shared_context_name # class instance variable
|
136
|
+
|
137
|
+
def self.shared_context_name # access to class instance variable
|
138
|
+
@shared_context_name
|
139
|
+
end
|
140
|
+
|
141
|
+
class << self
|
142
|
+
def run(feature_file)
|
143
|
+
Turnip::Builder.build(feature_file).features.each do |feature|
|
144
|
+
::RSpec.describe feature.name, feature.metadata_hash do
|
145
|
+
rspec_root = self
|
146
|
+
|
147
|
+
before do
|
148
|
+
run_before rspec_root
|
149
|
+
example = Turnip::RSpec.fetch_current_example(self)
|
150
|
+
# This is kind of a hack, but it will make RSpec throw way nicer exceptions
|
151
|
+
example.metadata[:file_path] ||= feature_file
|
152
|
+
|
153
|
+
feature.backgrounds.map(&:steps).flatten.each do |step|
|
154
|
+
run_step(feature_file, step)
|
155
|
+
end
|
156
|
+
end
|
157
|
+
feature.scenarios.each do |scenario|
|
158
|
+
instance_eval <<-EOS, feature_file, scenario.line
|
159
|
+
describe scenario.name, scenario.metadata_hash do it(scenario.steps.map(&:to_s).join(' -> ')) do
|
160
|
+
scenario.steps.each do |step|
|
161
|
+
run_step(feature_file, step)
|
162
|
+
end
|
163
|
+
end
|
164
|
+
end
|
165
|
+
EOS
|
166
|
+
end
|
167
|
+
after do
|
168
|
+
run_after rspec_root
|
169
|
+
end
|
170
|
+
end
|
171
|
+
end
|
172
|
+
end
|
173
|
+
end
|
174
|
+
end
|
175
|
+
end
|
176
|
+
|
177
|
+
end
|
File without changes
|
@@ -4,13 +4,14 @@ Feature: Using Wikipedia
|
|
4
4
|
Given I am within wikipedia.com
|
5
5
|
|
6
6
|
@selenium
|
7
|
+
@chrome
|
7
8
|
@search_with_drivers
|
8
9
|
Scenario: Searching with selenium for a term with submit
|
9
10
|
|
10
11
|
Given I am on wikipedia.com
|
11
12
|
When I enter word "Capybara"
|
12
13
|
And I click submit button
|
13
|
-
Then I should see "
|
14
|
+
Then I should see "Hydrochoerus hydrochaeris"
|
14
15
|
|
15
16
|
@webkit
|
16
17
|
@search_with_drivers
|
@@ -19,7 +20,7 @@ Feature: Using Wikipedia
|
|
19
20
|
Given I am on wikipedia.com
|
20
21
|
When I enter word "Capybara"
|
21
22
|
And I click submit button
|
22
|
-
Then I should see "
|
23
|
+
Then I should see "Hydrochoerus hydrochaeris"
|
23
24
|
|
24
25
|
@poltergeist
|
25
26
|
@search_with_drivers
|
@@ -28,4 +29,4 @@ Feature: Using Wikipedia
|
|
28
29
|
Given I am on wikipedia.com
|
29
30
|
When I enter word "Capybara"
|
30
31
|
And I click submit button
|
31
|
-
Then I should see "
|
32
|
+
Then I should see "Hydrochoerus hydrochaeris"
|
@@ -0,0 +1,13 @@
|
|
1
|
+
Feature: Using Wikipedia
|
2
|
+
|
3
|
+
Background: within wikipedia.com context
|
4
|
+
Given I am within wikipedia.com
|
5
|
+
|
6
|
+
@selenium
|
7
|
+
@search_with_pages
|
8
|
+
Scenario: Searching with selenium for a term with submit
|
9
|
+
|
10
|
+
Given I am on wikipedia.com
|
11
|
+
When I enter word "Capybara"
|
12
|
+
And I submit request
|
13
|
+
Then I should see "Capybara"
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'acceptance_test/page'
|
2
|
+
|
3
|
+
class MainPage < Page
|
4
|
+
def visit_home_page
|
5
|
+
session.visit('/')
|
6
|
+
end
|
7
|
+
|
8
|
+
def enter_word word
|
9
|
+
with_session do
|
10
|
+
fill_in "searchInput", :with => word
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def submit_request
|
15
|
+
session.find(".formBtn", match: :first).click
|
16
|
+
end
|
17
|
+
end
|
@@ -1,18 +1,21 @@
|
|
1
1
|
require 'rspec/expectations'
|
2
2
|
require 'acceptance_test/page_set'
|
3
3
|
|
4
|
-
require '
|
4
|
+
require 'pages/main_page'
|
5
5
|
|
6
|
-
class
|
6
|
+
class WikipediaPages < PageSet
|
7
7
|
include Capybara::DSL
|
8
8
|
include RSpec::Matchers
|
9
9
|
|
10
|
-
|
11
|
-
|
10
|
+
attr_reader :context
|
11
|
+
|
12
|
+
def initialize session
|
13
|
+
super session
|
12
14
|
|
13
15
|
@main_page = MainPage.new self
|
14
16
|
|
15
17
|
delegate_to_pages :main_page
|
16
18
|
end
|
17
19
|
|
18
|
-
end
|
20
|
+
end
|
21
|
+
|
File without changes
|
@@ -1,27 +1,12 @@
|
|
1
|
-
require '
|
2
|
-
|
3
|
-
RSpec.configure do |config|
|
4
|
-
config.before(:search_with_drivers => true) do |example|
|
5
|
-
AcceptanceTest.instance.configure_rspec example
|
6
|
-
end
|
7
|
-
end
|
1
|
+
require 'steps/common_steps'
|
8
2
|
|
9
3
|
steps_for :search_with_drivers do
|
10
4
|
include CommonSteps
|
11
5
|
|
12
|
-
# before do
|
13
|
-
# AcceptanceTest.instance.configure_rspec rspec_root
|
14
|
-
#
|
15
|
-
# end
|
16
|
-
#
|
17
|
-
# after do
|
18
|
-
# puts "after"
|
19
|
-
# end
|
20
|
-
|
21
6
|
step "I am within wikipedia.com" do
|
22
7
|
puts Capybara.current_driver
|
23
8
|
|
24
|
-
AcceptanceTest.instance.
|
9
|
+
AcceptanceTest.instance.setup
|
25
10
|
end
|
26
11
|
|
27
12
|
step "I am on wikipedia.com" do
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require 'steps/common_steps'
|
2
|
+
require 'pages/wikipedia_pages'
|
3
|
+
|
4
|
+
steps_for :search_with_pages do
|
5
|
+
include CommonSteps
|
6
|
+
|
7
|
+
attr_reader :page_set
|
8
|
+
|
9
|
+
step "I am within wikipedia.com" do
|
10
|
+
AcceptanceTest.instance.setup
|
11
|
+
|
12
|
+
puts Capybara.current_driver
|
13
|
+
|
14
|
+
@page_set = WikipediaPages.new(page)
|
15
|
+
|
16
|
+
page_set.enable_smart_completion(self)
|
17
|
+
end
|
18
|
+
|
19
|
+
step :visit_home_page, "I am on wikipedia.com"
|
20
|
+
|
21
|
+
step :enter_word, "I enter word :word"
|
22
|
+
|
23
|
+
# step :submit_request, "I submit request"
|
24
|
+
|
25
|
+
# step "I am on wikipedia.com" do
|
26
|
+
# page_set.visit_home_page
|
27
|
+
# end
|
28
|
+
|
29
|
+
# step "I enter word :word" do |word|
|
30
|
+
# page_set.enter_word word
|
31
|
+
# end
|
32
|
+
|
33
|
+
# step "I submit request" do
|
34
|
+
# page_set.submit_request
|
35
|
+
# end
|
36
|
+
|
37
|
+
end
|