howitzer 2.0.1 → 2.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (40) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +6 -0
  3. data/.travis.yml +4 -3
  4. data/CHANGELOG.md +18 -1
  5. data/Gemfile +1 -1
  6. data/README.md +3 -1
  7. data/Rakefile +1 -1
  8. data/bin/howitzer +3 -3
  9. data/features/cli_new.feature +2 -0
  10. data/generators/config/templates/capybara.rb +13 -11
  11. data/generators/config/templates/default.yml +2 -0
  12. data/generators/cucumber/cucumber_generator.rb +2 -1
  13. data/generators/cucumber/templates/cuke_sniffer.rake +21 -0
  14. data/generators/cucumber/templates/env.rb +6 -0
  15. data/generators/root/templates/Gemfile.erb +1 -0
  16. data/generators/rspec/templates/spec_helper.rb +2 -1
  17. data/generators/turnip/templates/spec_helper.rb +2 -1
  18. data/howitzer.gemspec +2 -1
  19. data/lib/howitzer.rb +1 -0
  20. data/lib/howitzer/capybara_helpers.rb +1 -1
  21. data/lib/howitzer/exceptions.rb +1 -0
  22. data/lib/howitzer/version.rb +1 -1
  23. data/lib/howitzer/web/capybara_methods_proxy.rb +26 -1
  24. data/lib/howitzer/web/element_dsl.rb +16 -3
  25. data/lib/howitzer/web/iframe_dsl.rb +34 -17
  26. data/lib/howitzer/web/page.rb +1 -0
  27. data/lib/howitzer/web/page_dsl.rb +2 -1
  28. data/lib/howitzer/web/page_validator.rb +5 -1
  29. data/spec/spec_helper.rb +1 -2
  30. data/spec/support/shared_examples/capybara_methods_proxy.rb +8 -8
  31. data/spec/support/shared_examples/dynamic_section_methods.rb +4 -4
  32. data/spec/support/shared_examples/element_dsl.rb +66 -53
  33. data/spec/unit/generators/cucumber_generator_spec.rb +8 -2
  34. data/spec/unit/lib/cache_spec.rb +1 -1
  35. data/spec/unit/lib/mailgun_api/client_spec.rb +6 -6
  36. data/spec/unit/lib/web/iframe_dsl_spec.rb +67 -22
  37. data/spec/unit/lib/web/page_spec.rb +25 -25
  38. data/spec/unit/lib/web/page_validator_spec.rb +37 -22
  39. data/spec/unit/lib/web/section_dsl_spec.rb +3 -3
  40. metadata +20 -5
@@ -22,6 +22,7 @@ module Howitzer
22
22
  include SectionDsl
23
23
  include PageValidator
24
24
  include ::RSpec::Matchers
25
+ include RSpec::Wait
25
26
 
26
27
  # This Ruby callback makes all inherited classes as singleton classes.
27
28
 
@@ -5,6 +5,7 @@ module Howitzer
5
5
  # This class is for private usage only
6
6
  class PageScope
7
7
  include RSpec::Matchers
8
+ include RSpec::Wait
8
9
 
9
10
  def initialize(page_klass, &block)
10
11
  self.page_klass = page_klass
@@ -38,7 +39,7 @@ module Howitzer
38
39
  # @see #method_missing
39
40
 
40
41
  def respond_to_missing?(name, include_private = false)
41
- !(name =~ /\A(?:be|have)_/) || super
42
+ name !~ /\A(?:be|have)_/ || super
42
43
  end
43
44
 
44
45
  private
@@ -21,7 +21,6 @@ module Howitzer
21
21
 
22
22
  def check_validations_are_defined!
23
23
  return if self.class.validations.present?
24
-
25
24
  raise Howitzer::NoValidationError, "No any page validation was found for '#{self.class.name}' page"
26
25
  end
27
26
 
@@ -34,6 +33,7 @@ module Howitzer
34
33
  # For :element_presence must be one of element names described for page
35
34
  # @param additional_value [Object, nil] any value required to pass for a labmda selector
36
35
  # @raise [Howitzer::UnknownValidationError] if unknown validation type
36
+ # @raise [Howitzer::UndefinedElementError] if :element_presence validations refers to undefined element name
37
37
  # @example
38
38
  # class ArticleListPage < Howitzer::Web::Page
39
39
  # validate :title, /\ADemo web application - Listing Articles\z/
@@ -81,6 +81,10 @@ module Howitzer
81
81
  def validate_element(element_name, value = nil)
82
82
  validations[:element_presence] =
83
83
  lambda do |web_page, sync|
84
+ if element_name.present? && !private_method_defined?("#{element_name}_element")
85
+ raise(Howitzer::UndefinedElementError, ':element_presence validation refers to ' \
86
+ "undefined '#{element_name}' element on '#{name}' page.")
87
+ end
84
88
  if sync
85
89
  web_page.instance.public_send(*["has_#{element_name}_element?", value].compact)
86
90
  else
@@ -68,6 +68,5 @@ Dir[File.join(__dir__, 'support', '**', '*.rb')].each { |f| require f }
68
68
 
69
69
  RSpec.configure do |config|
70
70
  config.include Howitzer::GeneratorHelper
71
- config.disable_monkey_patching = true
72
- config.around(:each, &:run)
71
+ config.disable_monkey_patching!
73
72
  end
@@ -47,10 +47,10 @@ RSpec.shared_examples :capybara_methods_proxy do
47
47
  let(:switch_to) { double }
48
48
  let(:driver_name) { 'selenium' }
49
49
  it do
50
- expect(session).to receive(:driver).ordered { driver }
51
- expect(driver).to receive(:browser).ordered { browser }
52
- expect(browser).to receive(:switch_to).ordered { switch_to }
53
- expect(switch_to).to receive(:alert).ordered { alert }
50
+ expect(session).to receive(:driver).ordered.and_return(driver)
51
+ expect(driver).to receive(:browser).ordered.and_return(browser)
52
+ expect(browser).to receive(:switch_to).ordered.and_return(switch_to)
53
+ expect(switch_to).to receive(:alert).ordered.and_return(alert)
54
54
  expect(alert).to receive(:accept).once
55
55
  subject
56
56
  end
@@ -64,10 +64,10 @@ RSpec.shared_examples :capybara_methods_proxy do
64
64
  let(:switch_to) { double }
65
65
  let(:driver_name) { 'selenium' }
66
66
  it do
67
- expect(session).to receive(:driver).ordered { driver }
68
- expect(driver).to receive(:browser).ordered { browser }
69
- expect(browser).to receive(:switch_to).ordered { switch_to }
70
- expect(switch_to).to receive(:alert).ordered { alert }
67
+ expect(session).to receive(:driver).ordered.and_return(driver)
68
+ expect(driver).to receive(:browser).ordered.and_return(browser)
69
+ expect(browser).to receive(:switch_to).ordered.and_return(switch_to)
70
+ expect(switch_to).to receive(:alert).ordered.and_return(alert)
71
71
  expect(alert).to receive(:dismiss).once
72
72
  subject
73
73
  end
@@ -5,7 +5,7 @@ RSpec.shared_examples :dynamic_section_methods do
5
5
  describe '#name_section' do
6
6
  let(:capybara_element) { double }
7
7
  subject { web_page_object.send("#{section_name}_section") }
8
- before { expect(session).to receive(:find).with(*finder_args).once { capybara_element } }
8
+ before { expect(session).to receive(:find).with(*finder_args).once.and_return(capybara_element) }
9
9
  it { is_expected.to be_a(section_class) }
10
10
  end
11
11
  describe '#name_sections' do
@@ -13,7 +13,7 @@ RSpec.shared_examples :dynamic_section_methods do
13
13
  let(:capybara_element1) { double }
14
14
  let(:capybara_element2) { double }
15
15
  before do
16
- expect(session).to receive(:all).with(*finder_args).once { [capybara_element1, capybara_element2] }
16
+ expect(session).to receive(:all).with(*finder_args).once.and_return([capybara_element1, capybara_element2])
17
17
  end
18
18
  it 'should return collection of sections' do
19
19
  res = subject
@@ -24,12 +24,12 @@ RSpec.shared_examples :dynamic_section_methods do
24
24
  end
25
25
  describe '#has_name_section?' do
26
26
  subject { web_page_object.send("has_#{section_name}_section?") }
27
- before { expect(session).to receive(:has_selector?).with(*finder_args).once { true } }
27
+ before { expect(session).to receive(:has_selector?).with(*finder_args).once.and_return(true) }
28
28
  it { is_expected.to eq(true) }
29
29
  end
30
30
  describe '#has_no_name_element?' do
31
31
  subject { web_page_object.send("has_no_#{section_name}_section?") }
32
- before { expect(session).to receive(:has_no_selector?).with(*finder_args).once { true } }
32
+ before { expect(session).to receive(:has_no_selector?).with(*finder_args).once.and_return(true) }
33
33
  it { is_expected.to eq(true) }
34
34
  end
35
35
  end
@@ -75,38 +75,39 @@ RSpec.shared_examples :element_dsl do
75
75
  before do
76
76
  allow(Capybara).to receive(:current_session) { kontext }
77
77
  klass.class_eval do
78
- element :foo, :xpath, ->(title, name) { "//a[.='#{title}']/*[@name='#{name}']" }
79
- element :bar, '.someclass'
80
- element :top_panel, '.top'
78
+ element :foo, :xpath,
79
+ ->(title, name) { "//a[.='#{title}']/*[@name='#{name}']" }, text: 'original', match: :first
80
+ element :bar, '.someclass', text: 'origin', match: :first
81
+ element :top_panel, '.top', text: 'origin', match: :first
81
82
  end
82
83
  end
83
84
 
84
85
  describe '#name_element' do
85
86
  context 'when simple selector' do
86
- subject { klass_object.send(:bar_element, wait: 10) }
87
+ subject { klass_object.send(:bar_element, text: 'new', wait: 10) }
87
88
  after { subject }
88
- it { expect(klass_object.capybara_context).to receive(:find).with('.someclass', wait: 10) }
89
+ it do
90
+ expect(klass_object.capybara_context).to receive(:find)
91
+ .with('.someclass', wait: 10, text: 'new', match: :first)
92
+ end
89
93
  end
90
94
  context 'when lambda selector' do
91
- subject { klass_object.send(:foo_element, 'Hello', 'super', wait: 10) }
95
+ subject { klass_object.send(:foo_element, 'Hello', 'super', text: 'new', wait: 10) }
92
96
  after { subject }
93
97
  it do
94
- expect(
95
- klass_object.capybara_context
96
- ).to receive(:find).with(:xpath, "//a[.='Hello']/*[@name='super']", wait: 10)
98
+ expect(klass_object.capybara_context).to receive(:find)
99
+ .with(:xpath, "//a[.='Hello']/*[@name='super']", wait: 10, text: 'new', match: :first)
97
100
  end
98
101
 
99
102
  context 'when several execution with different data' do
100
103
  it 'does not cache previous data' do
101
- expect(
102
- klass_object.capybara_context
103
- ).to receive(:find).with(:xpath, "//a[.='Hello']/*[@name='super']", wait: 10).at_least(:once)
104
- klass_object.send(:foo_element, 'Hello', 'super', wait: 10)
104
+ expect(klass_object.capybara_context).to receive(:find)
105
+ .with(:xpath, "//a[.='Hello']/*[@name='super']", wait: 10, text: 'new', match: :first).at_least(:once)
106
+ klass_object.send(:foo_element, 'Hello', 'super', text: 'new', wait: 10)
105
107
 
106
- expect(
107
- klass_object.capybara_context
108
- ).to receive(:find).with(:xpath, "//a[.='Bye']/*[@name='puper']", wait: 15).at_least(:once)
109
- klass_object.send(:foo_element, 'Bye', 'puper', wait: 15)
108
+ expect(klass_object.capybara_context).to receive(:find)
109
+ .with(:xpath, "//a[.='Bye']/*[@name='puper']", wait: 15, text: 'new', match: :first).at_least(:once)
110
+ klass_object.send(:foo_element, 'Bye', 'puper', text: 'new', wait: 15)
110
111
  end
111
112
  end
112
113
  end
@@ -114,32 +115,36 @@ RSpec.shared_examples :element_dsl do
114
115
  describe '#name_elements' do
115
116
  after { subject }
116
117
  context 'when simple selector' do
117
- subject { klass_object.send(:bar_elements, wait: 10) }
118
- it { expect(klass_object.capybara_context).to receive(:all).with('.someclass', wait: 10) }
118
+ subject { klass_object.send(:bar_elements, text: 'new', wait: 10) }
119
+ it do
120
+ expect(klass_object.capybara_context).to receive(:all)
121
+ .with('.someclass', wait: 10, text: 'new', match: :first)
122
+ end
119
123
  end
120
124
  context 'when lambda selector' do
121
- subject { klass_object.send(:foo_elements, 'Hello', 'super', wait: 10) }
125
+ subject { klass_object.send(:foo_elements, 'Hello', 'super', text: 'new', wait: 10) }
122
126
  it do
123
127
  expect(
124
128
  klass_object.capybara_context
125
- ).to receive(:all).with(:xpath, "//a[.='Hello']/*[@name='super']", wait: 10)
129
+ ).to receive(:all).with(:xpath, "//a[.='Hello']/*[@name='super']", wait: 10, text: 'new', match: :first)
126
130
  end
127
131
  end
128
132
  end
129
133
  describe '#wait_for_name_element' do
130
134
  context 'when simple selector' do
131
- subject { klass_object.send(:wait_for_bar_element, wait: 10) }
135
+ subject { klass_object.send(:wait_for_bar_element, text: 'new', wait: 10) }
132
136
  it do
133
- expect(klass_object.capybara_context).to receive(:find).with('.someclass', wait: 10)
137
+ expect(klass_object.capybara_context).to receive(:find)
138
+ .with('.someclass', wait: 10, text: 'new', match: :first)
134
139
  is_expected.to eq(nil)
135
140
  end
136
141
  end
137
142
  context 'when lambda selector' do
138
- subject { klass_object.send(:wait_for_foo_element, 'Hello', 'super', wait: 10) }
143
+ subject { klass_object.send(:wait_for_foo_element, 'Hello', 'super', text: 'new', wait: 10) }
139
144
  it do
140
145
  expect(
141
146
  klass_object.capybara_context
142
- ).to receive(:find).with(:xpath, "//a[.='Hello']/*[@name='super']", wait: 10)
147
+ ).to receive(:find).with(:xpath, "//a[.='Hello']/*[@name='super']", wait: 10, text: 'new', match: :first)
143
148
  is_expected.to eq(nil)
144
149
  end
145
150
  end
@@ -151,29 +156,30 @@ RSpec.shared_examples :element_dsl do
151
156
  context 'when simple selector' do
152
157
  subject do
153
158
  klass_object.instance_eval do
154
- within_bar_element(wait: 10) do
155
- foo_element('Hello', 'super', wait: 10)
159
+ within_bar_element(wait: 5, text: 'new') do
160
+ foo_element('Hello', 'super', wait: 10, text: 'new')
156
161
  end
157
162
  end
158
163
  end
159
164
  it do
160
- expect(klass_object.capybara_context).to receive(:find).with('.someclass', wait: 10) { within_scope }
161
- expect(within_scope).to receive(:find).with(:xpath, "//a[.='Hello']/*[@name='super']", wait: 10)
165
+ expect(klass_object.capybara_context).to receive(:find)
166
+ .with('.someclass', wait: 5, text: 'new', match: :first) { within_scope }
167
+ expect(within_scope).to receive(:find)
168
+ .with(:xpath, "//a[.='Hello']/*[@name='super']", wait: 10, text: 'new', match: :first)
162
169
  end
163
170
  end
164
171
  context 'when lambda selector' do
165
172
  subject do
166
173
  klass_object.instance_eval do
167
- within_foo_element('Hello', 'super', wait: 10) do
168
- bar_element(wait: 10)
174
+ within_foo_element('Hello', 'super', wait: 10, text: 'new') do
175
+ bar_element(wait: 10, text: 'new')
169
176
  end
170
177
  end
171
178
  end
172
179
  it do
173
- expect(
174
- klass_object.capybara_context
175
- ).to receive(:find).with(:xpath, "//a[.='Hello']/*[@name='super']", wait: 10) { within_scope }
176
- expect(within_scope).to receive(:find).with('.someclass', wait: 10)
180
+ expect(klass_object.capybara_context).to receive(:find)
181
+ .with(:xpath, "//a[.='Hello']/*[@name='super']", wait: 10, text: 'new', match: :first) { within_scope }
182
+ expect(within_scope).to receive(:find).with('.someclass', wait: 10, text: 'new', match: :first)
177
183
  end
178
184
  end
179
185
  end
@@ -181,47 +187,54 @@ RSpec.shared_examples :element_dsl do
181
187
  let(:nested_within_scope) { double }
182
188
  subject do
183
189
  klass_object.instance_eval do
184
- within_top_panel_element(wait: 10) do
185
- within_bar_element(wait: 10) do
186
- foo_element('Hello', 'super', wait: 10)
190
+ within_top_panel_element(wait: 10, text: 'new') do
191
+ within_bar_element(wait: 10, text: 'new') do
192
+ foo_element('Hello', 'super', wait: 10, text: 'new')
187
193
  end
188
194
  end
189
195
  end
190
196
  end
191
197
  it do
192
- expect(klass_object.capybara_context).to receive(:find).with('.top', wait: 10) { within_scope }
193
- expect(within_scope).to receive(:find).with('.someclass', wait: 10) { nested_within_scope }
194
- expect(nested_within_scope).to receive(:find).with(:xpath, "//a[.='Hello']/*[@name='super']", wait: 10)
198
+ expect(klass_object.capybara_context).to receive(:find)
199
+ .with('.top', wait: 10, text: 'new', match: :first) { within_scope }
200
+ expect(within_scope).to receive(:find)
201
+ .with('.someclass', wait: 10, text: 'new', match: :first) { nested_within_scope }
202
+ expect(nested_within_scope).to receive(:find)
203
+ .with(:xpath, "//a[.='Hello']/*[@name='super']", wait: 10, text: 'new', match: :first)
195
204
  end
196
205
  end
197
206
  end
198
207
  describe '#has_name_element?' do
199
208
  after { subject }
200
209
  context 'when simple selector' do
201
- subject { klass_object.send(:has_bar_element?, wait: 10) }
202
- it { expect(klass_object.capybara_context).to receive(:has_selector?).with('.someclass', wait: 10) }
210
+ subject { klass_object.send(:has_bar_element?, wait: 10, text: 'new') }
211
+ it do
212
+ expect(klass_object.capybara_context).to receive(:has_selector?)
213
+ .with('.someclass', wait: 10, text: 'new', match: :first)
214
+ end
203
215
  end
204
216
  context 'when lambda selector' do
205
- subject { klass_object.send(:has_foo_element?, 'Hello', 'super', wait: 10) }
217
+ subject { klass_object.send(:has_foo_element?, 'Hello', 'super', wait: 10, text: 'new') }
206
218
  it do
207
- expect(
208
- klass_object.capybara_context
209
- ).to receive(:has_selector?).with(:xpath, "//a[.='Hello']/*[@name='super']", wait: 10)
219
+ expect(klass_object.capybara_context).to receive(:has_selector?)
220
+ .with(:xpath, "//a[.='Hello']/*[@name='super']", wait: 10, text: 'new', match: :first)
210
221
  end
211
222
  end
212
223
  end
213
224
  describe '#has_no_name_element?' do
214
225
  after { subject }
215
226
  context 'when simple selector' do
216
- subject { klass_object.send(:has_no_bar_element?, wait: 10) }
217
- it { expect(klass_object.capybara_context).to receive(:has_no_selector?).with('.someclass', wait: 10) }
227
+ subject { klass_object.send(:has_no_bar_element?, wait: 10, text: 'new') }
228
+ it do
229
+ expect(klass_object.capybara_context).to receive(:has_no_selector?)
230
+ .with('.someclass', wait: 10, text: 'new', match: :first)
231
+ end
218
232
  end
219
233
  context 'when lambda selector' do
220
- subject { klass_object.send(:has_no_foo_element?, 'Hello', 'super', wait: 10) }
234
+ subject { klass_object.send(:has_no_foo_element?, 'Hello', 'super', wait: 10, text: 'new', match: :first) }
221
235
  it do
222
- expect(
223
- klass_object.capybara_context
224
- ).to receive(:has_no_selector?).with(:xpath, "//a[.='Hello']/*[@name='super']", wait: 10)
236
+ expect(klass_object.capybara_context).to receive(:has_no_selector?)
237
+ .with(:xpath, "//a[.='Hello']/*[@name='super']", wait: 10, text: 'new', match: :first)
225
238
  end
226
239
  end
227
240
  end
@@ -35,7 +35,12 @@ RSpec.describe 'Generators' do
35
35
  size: template_file_size('cucumber', 'transformers.rb')
36
36
  },
37
37
  { name: '/tasks', is_directory: true },
38
- { name: '/tasks/cucumber.rake', is_directory: false, size: template_file_size('cucumber', 'cucumber.rake') }
38
+ { name: '/tasks/cucumber.rake', is_directory: false, size: template_file_size('cucumber', 'cucumber.rake') },
39
+ {
40
+ name: '/tasks/cuke_sniffer.rake',
41
+ is_directory: false,
42
+ size: template_file_size('cucumber', 'cuke_sniffer.rake')
43
+ }
39
44
  ]
40
45
  end
41
46
  it { is_expected.to eql(expected_result) }
@@ -47,7 +52,8 @@ RSpec.describe 'Generators' do
47
52
  Added 'features/support/hooks.rb' file
48
53
  Added 'features/support/transformers.rb' file
49
54
  Added 'features/example.feature' file
50
- Added 'tasks/cucumber.rake' file\n"
55
+ Added 'tasks/cucumber.rake' file
56
+ Added 'tasks/cuke_sniffer.rake' file\n"
51
57
  end
52
58
  subject { output.string }
53
59
  it { is_expected.to eql(expected_output) }
@@ -70,7 +70,7 @@ RSpec.describe Howitzer::Cache do
70
70
  it { expect(described_class.data).to eq(cloud: { status: false }, foo: {}, bar: {}, baz: {}) }
71
71
  end
72
72
  context 'when custom argument' do
73
- let(:exception_list) { [:foo, :bar] }
73
+ let(:exception_list) { %i(foo bar) }
74
74
  before { described_class.clear_all_ns(exception_list) }
75
75
  it do
76
76
  expect(described_class.data).to eq(
@@ -14,7 +14,7 @@ RSpec.describe Howitzer::MailgunApi::Client do
14
14
  context 'when simulation of client' do
15
15
  before do
16
16
  expect(RestClient::Resource).to receive(:new)
17
- .once { Howitzer::MailgunApi::UnitClient.new('Fake-API-Key', 'api.mailgun.net', 'v2') }
17
+ .once.and_return(Howitzer::MailgunApi::UnitClient.new('Fake-API-Key', 'api.mailgun.net', 'v2'))
18
18
  end
19
19
  it do
20
20
  expect(subject.body).to include('total_count')
@@ -24,9 +24,9 @@ RSpec.describe Howitzer::MailgunApi::Client do
24
24
  context 'when real client' do
25
25
  let(:resource) { double }
26
26
  before do
27
- allow(resource).to receive('[]') { resource }
27
+ allow(resource).to receive('[]').and_return(resource)
28
28
  allow(resource).to receive(:get).and_raise(StandardError, '401 Unauthorized: Forbidden')
29
- allow(RestClient::Resource).to receive(:new) { resource }
29
+ allow(RestClient::Resource).to receive(:new).and_return(resource)
30
30
  end
31
31
  it do
32
32
  expect { subject }.to raise_error(Howitzer::CommunicationError, '401 Unauthorized: Forbidden')
@@ -41,14 +41,14 @@ RSpec.describe Howitzer::MailgunApi::Client do
41
41
  let(:response_raw) { double }
42
42
  let(:response_real) { double }
43
43
  before do
44
- allow(RestClient::Request).to receive(:execute).with(any_args) { response_raw }
45
- allow(Howitzer::MailgunApi::Response).to receive(:new).with(response_raw) { response_real }
44
+ allow(RestClient::Request).to receive(:execute).with(any_args).and_return(response_raw)
45
+ allow(Howitzer::MailgunApi::Response).to receive(:new).with(response_raw).and_return(response_real)
46
46
  end
47
47
  it { is_expected.to eq(response_real) }
48
48
  end
49
49
  context 'when error happens' do
50
50
  before do
51
- allow(RestClient::Resource).to receive(:new).with(any_args) { response_raw }
51
+ allow(RestClient::Resource).to receive(:new).with(any_args).and_return(response_raw)
52
52
  mg_obj
53
53
  allow(RestClient::Request).to receive(:execute).with(any_args).and_raise(StandardError, 'Some message')
54
54
  end
@@ -43,6 +43,19 @@ RSpec.describe Howitzer::Web::IframeDsl do
43
43
  expect(subject.protected_methods(true)).to include(:iframe)
44
44
  end
45
45
  end
46
+
47
+ context 'when selector is not specified' do
48
+ subject do
49
+ web_page_class.class_eval do
50
+ iframe :fb
51
+ end
52
+ web_page_class
53
+ end
54
+
55
+ it 'should raise error' do
56
+ expect { subject }.to raise_error(ArgumentError, 'iframe selector arguments must be specified')
57
+ end
58
+ end
46
59
  end
47
60
 
48
61
  include_examples :capybara_context_holder
@@ -57,42 +70,74 @@ RSpec.describe Howitzer::Web::IframeDsl do
57
70
 
58
71
  describe '#name_iframe' do
59
72
  let(:block) { proc {} }
60
- subject { web_page_object.send(:fb_iframe, &block) }
61
- context 'when integer selector' do
62
- before { web_page_class.class_eval { iframe :fb, 1 } }
73
+ context 'when no options' do
74
+ subject { web_page_object.fb_iframe(&block) }
75
+ before { web_page_class.class_eval { iframe :fb, 'foo' } }
63
76
  it do
64
- expect(kontext).to receive(:within_frame).with(1) { |&block| block.call }
77
+ expect(kontext).to receive(:within_frame)
78
+ .with('foo') { |&block| block.call }
65
79
  expect(block).to receive(:call).with(fb_page_class.instance)
80
+ expect(fb_page_class).to receive(:displayed?).with(no_args)
66
81
  end
67
82
  end
68
- context 'when string selector' do
69
- before { web_page_class.class_eval { iframe :fb, 'loko' } }
83
+ context 'when all possible options' do
84
+ subject { web_page_object.fb_iframe(wait: 10, text: 'new', &block) }
85
+ before { web_page_class.class_eval { iframe :fb, :xpath, './/foo', match: :first, text: 'origin' } }
70
86
  it do
71
- expect(kontext).to receive(:within_frame).with('loko') { |&block| block.call }
87
+ expect(kontext).to receive(:within_frame)
88
+ .with(:xpath, './/foo', match: :first, wait: 10, text: 'new') { |&block| block.call }
72
89
  expect(block).to receive(:call).with(fb_page_class.instance)
90
+ expect(fb_page_class).to receive(:displayed?).with(no_args)
73
91
  end
74
92
  end
75
93
  end
76
94
  describe '#has_name_iframe?' do
77
- subject { web_page_object.has_fb_iframe? }
78
- context 'when integer selector' do
79
- before { web_page_class.class_eval { iframe :fb, 1 } }
80
- it { expect(kontext).to receive(:has_selector?).with('iframe:nth-of-type(2)') }
95
+ subject { web_page_object.has_fb_iframe?(wait: 1, text: 'new') }
96
+ context 'when first argument is integer' do
97
+ before { web_page_class.class_eval { iframe :fb, 1, match: :first, text: 'origin' } }
98
+ it do
99
+ expect(kontext).to receive(:has_selector?)
100
+ .with('iframe:nth-of-type(2)', match: :first, wait: 1, text: 'new')
101
+ end
81
102
  end
82
- context 'when string selector' do
83
- before { web_page_class.class_eval { iframe :fb, 'loko' } }
84
- it { expect(kontext).to receive(:has_selector?).with(:frame, 'loko') }
103
+ context 'when first argument is string' do
104
+ before { web_page_class.class_eval { iframe :fb, 'loko', match: :first, text: 'origin' } }
105
+ it { expect(kontext).to receive(:has_selector?).with(:frame, 'loko', match: :first, wait: 1, text: 'new') }
106
+ end
107
+ context 'when first argument is hash' do
108
+ before { web_page_class.class_eval { iframe :fb, name: 'loko', match: :first, text: 'origin' } }
109
+ it do
110
+ expect(kontext).to receive(:has_selector?)
111
+ .with(:frame, name: 'loko', match: :first, wait: 1, text: 'new')
112
+ end
113
+ end
114
+ context 'when first argument is symbol' do
115
+ before { web_page_class.class_eval { iframe :fb, :xpath, './/foo', match: :first, text: 'origin' } }
116
+ it { expect(kontext).to receive(:has_selector?).with(:xpath, './/foo', match: :first, wait: 1, text: 'new') }
85
117
  end
86
118
  end
87
119
  describe '#has_no_name_iframe?' do
88
- subject { web_page_object.has_no_fb_iframe? }
89
- context 'when integer selector' do
90
- before { web_page_class.class_eval { iframe :fb, 1 } }
91
- it { expect(kontext).to receive(:has_no_selector?).with('iframe:nth-of-type(2)') }
92
- end
93
- context 'when string selector' do
94
- before { web_page_class.class_eval { iframe :fb, 'loko' } }
95
- it { expect(kontext).to receive(:has_no_selector?).with(:frame, 'loko') }
120
+ subject { web_page_object.has_no_fb_iframe?(wait: 1, text: 'new') }
121
+ context 'when first argument is integer' do
122
+ before { web_page_class.class_eval { iframe :fb, 1, match: :first, text: 'origin' } }
123
+ it do
124
+ expect(kontext).to receive(:has_no_selector?)
125
+ .with('iframe:nth-of-type(2)', match: :first, wait: 1, text: 'new')
126
+ end
127
+ end
128
+ context 'when first argument is string' do
129
+ before { web_page_class.class_eval { iframe :fb, 'loko', match: :first, text: 'origin' } }
130
+ it { expect(kontext).to receive(:has_no_selector?).with(:frame, 'loko', match: :first, wait: 1, text: 'new') }
131
+ end
132
+ context 'when first argument is hash' do
133
+ before { web_page_class.class_eval { iframe :fb, name: 'loko', match: :first, text: 'origin' } }
134
+ it do
135
+ expect(kontext).to receive(:has_no_selector?).with(:frame, name: 'loko', match: :first, wait: 1, text: 'new')
136
+ end
137
+ end
138
+ context 'when first argument is symbol' do
139
+ before { web_page_class.class_eval { iframe :fb, :xpath, './/foo', match: :first, text: 'origin' } }
140
+ it { expect(kontext).to receive(:has_no_selector?).with(:xpath, './/foo', match: :first, wait: 1, text: 'new') }
96
141
  end
97
142
  end
98
143
  end