howitzer 1.1.1 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/.rubocop.yml +32 -0
- data/.travis.yml +1 -4
- data/.yardopts +1 -2
- data/CHANGELOG.md +28 -1
- data/Gemfile +6 -0
- data/LICENSE +1 -1
- data/README.md +55 -85
- data/Rakefile +7 -7
- data/bin/howitzer +56 -31
- data/features/cli_new.feature +162 -79
- data/features/cli_update.feature +114 -21
- data/features/step_definitions/common_steps.rb +29 -9
- data/features/support/env.rb +1 -1
- data/features/support/transformers.rb +2 -2
- data/generators/base_generator.rb +121 -49
- data/generators/config/config_generator.rb +8 -5
- data/generators/config/templates/boot.rb +14 -0
- data/generators/config/templates/capybara.rb +156 -0
- data/generators/config/templates/custom.yml +2 -3
- data/generators/config/templates/default.yml +50 -82
- data/generators/cucumber/cucumber_generator.rb +9 -9
- data/generators/cucumber/templates/common_steps.rb +4 -4
- data/generators/cucumber/templates/cucumber.rake +63 -54
- data/generators/cucumber/templates/env.rb +24 -23
- data/generators/cucumber/templates/transformers.rb +23 -15
- data/generators/emails/emails_generator.rb +4 -2
- data/generators/emails/templates/example_email.rb +4 -4
- data/generators/prerequisites/prerequisites_generator.rb +24 -0
- data/generators/prerequisites/templates/base.rb +22 -0
- data/generators/prerequisites/templates/factory_girl.rb +30 -0
- data/generators/prerequisites/templates/user.rb +7 -0
- data/generators/prerequisites/templates/users.rb +12 -0
- data/generators/root/root_generator.rb +11 -7
- data/generators/root/templates/.rubocop.yml +32 -0
- data/generators/root/templates/Gemfile.erb +27 -0
- data/generators/root/templates/Rakefile +6 -8
- data/generators/rspec/rspec_generator.rb +7 -7
- data/generators/rspec/templates/example_spec.rb +1 -1
- data/generators/rspec/templates/rspec.rake +48 -29
- data/generators/rspec/templates/spec_helper.rb +33 -32
- data/generators/tasks/tasks_generator.rb +4 -2
- data/generators/tasks/templates/common.rake +1 -16
- data/generators/turnip/templates/.rspec +1 -0
- data/generators/turnip/templates/common_steps.rb +25 -0
- data/generators/turnip/templates/example.feature +8 -0
- data/generators/turnip/templates/spec_helper.rb +56 -0
- data/generators/turnip/templates/turnip.rake +61 -0
- data/generators/turnip/templates/turnip_helper.rb +6 -0
- data/generators/turnip/turnip_generator.rb +26 -0
- data/generators/web/templates/example_page.rb +15 -0
- data/generators/web/templates/menu_section.rb +13 -0
- data/generators/web/web_generator.rb +22 -0
- data/howitzer.gemspec +14 -21
- data/lib/howitzer.rb +47 -7
- data/lib/howitzer/cache.rb +70 -0
- data/lib/howitzer/capybara_helpers.rb +194 -0
- data/lib/howitzer/email.rb +96 -104
- data/lib/howitzer/exceptions.rb +10 -6
- data/lib/howitzer/log.rb +120 -0
- data/lib/howitzer/mail_adapters.rb +7 -0
- data/lib/howitzer/mail_adapters/abstract.rb +84 -0
- data/lib/howitzer/mail_adapters/mailgun.rb +115 -0
- data/lib/howitzer/mailgun_api.rb +9 -0
- data/lib/howitzer/mailgun_api/client.rb +79 -0
- data/lib/howitzer/mailgun_api/connector.rb +37 -0
- data/lib/howitzer/mailgun_api/response.rb +28 -0
- data/lib/howitzer/tasks/framework.rake +2 -2
- data/lib/howitzer/utils.rb +7 -1
- data/lib/howitzer/utils/string_extensions.rb +66 -0
- data/lib/howitzer/version.rb +2 -1
- data/lib/howitzer/web.rb +11 -0
- data/lib/howitzer/web/base_section.rb +27 -0
- data/lib/howitzer/web/blank_page.rb +12 -0
- data/lib/howitzer/web/capybara_methods_proxy.rb +29 -0
- data/lib/howitzer/web/element_dsl.rb +109 -0
- data/lib/howitzer/web/iframe_dsl.rb +93 -0
- data/lib/howitzer/web/page.rb +173 -0
- data/lib/howitzer/web/page_dsl.rb +64 -0
- data/lib/howitzer/web/page_validator.rb +118 -0
- data/lib/howitzer/web/section.rb +27 -0
- data/lib/howitzer/web/section_dsl.rb +154 -0
- data/spec/config/custom.yml +10 -1
- data/spec/spec_helper.rb +37 -19
- data/spec/support/generator_helper.rb +12 -11
- data/spec/support/logger_helper.rb +10 -9
- data/spec/support/mailgun_unit_client.rb +52 -44
- data/spec/support/shared_examples/capybara_context_holder.rb +33 -0
- data/spec/support/shared_examples/capybara_methods_proxy.rb +94 -0
- data/spec/support/shared_examples/dynamic_section_methods.rb +35 -0
- data/spec/support/shared_examples/element_dsl.rb +119 -0
- data/spec/unit/generators/base_generator_spec.rb +64 -33
- data/spec/unit/generators/config_generator_spec.rb +11 -7
- data/spec/unit/generators/cucumber_generator_spec.rb +26 -17
- data/spec/unit/generators/emails_generator_spec.rb +10 -6
- data/spec/unit/generators/prerequisites_generator_spec.rb +53 -0
- data/spec/unit/generators/root_generator_spec.rb +50 -13
- data/spec/unit/generators/rspec_generator_spec.rb +9 -9
- data/spec/unit/generators/tasks_generator_spec.rb +6 -6
- data/spec/unit/generators/turnip_generator_spec.rb +52 -0
- data/spec/unit/generators/web_generator_spec.rb +52 -0
- data/spec/unit/lib/cache_spec.rb +85 -0
- data/spec/unit/lib/capybara_helpers_spec.rb +696 -0
- data/spec/unit/lib/email_spec.rb +104 -91
- data/spec/unit/lib/howitzer.rb +31 -0
- data/spec/unit/lib/init_spec.rb +0 -1
- data/spec/unit/lib/log_spec.rb +122 -0
- data/spec/unit/lib/mail_adapters/abstract_spec.rb +62 -0
- data/spec/unit/lib/mail_adapters/mailgun_spec.rb +163 -0
- data/spec/unit/lib/mailgun_api/client_spec.rb +58 -0
- data/spec/unit/lib/mailgun_api/connector_spec.rb +54 -0
- data/spec/unit/lib/mailgun_api/response_spec.rb +28 -0
- data/spec/unit/lib/utils/string_extensions_spec.rb +77 -0
- data/spec/unit/lib/web/base_section_spec.rb +41 -0
- data/spec/unit/lib/web/element_dsl_spec.rb +17 -0
- data/spec/unit/lib/web/iframe_dsl_spec.rb +99 -0
- data/spec/unit/lib/web/page_dsl_spec.rb +52 -0
- data/spec/unit/lib/web/page_spec.rb +304 -0
- data/spec/unit/lib/web/page_validator_spec.rb +218 -0
- data/spec/unit/lib/web/section_dsl_spec.rb +165 -0
- data/spec/unit/lib/web/section_spec.rb +61 -0
- data/spec/unit/version_spec.rb +1 -1
- metadata +116 -203
- data/GETTING_STARTED.md +0 -774
- data/generators/cucumber/templates/cucumber.yml +0 -10
- data/generators/pages/pages_generator.rb +0 -21
- data/generators/pages/templates/example_menu.rb +0 -15
- data/generators/pages/templates/example_page.rb +0 -15
- data/generators/root/templates/Gemfile +0 -7
- data/generators/root/templates/boot.rb +0 -10
- data/lib/howitzer/blank_page.rb +0 -6
- data/lib/howitzer/capybara/dsl_ex.rb +0 -15
- data/lib/howitzer/capybara/settings.rb +0 -343
- data/lib/howitzer/helpers.rb +0 -230
- data/lib/howitzer/init.rb +0 -1
- data/lib/howitzer/mailgun/client.rb +0 -65
- data/lib/howitzer/mailgun/connector.rb +0 -34
- data/lib/howitzer/mailgun/response.rb +0 -28
- data/lib/howitzer/patches/rawler_patched.rb +0 -86
- data/lib/howitzer/settings.rb +0 -27
- data/lib/howitzer/utils/data_generator/data_storage.rb +0 -88
- data/lib/howitzer/utils/data_generator/gen.rb +0 -135
- data/lib/howitzer/utils/locator_store.rb +0 -217
- data/lib/howitzer/utils/log.rb +0 -139
- data/lib/howitzer/utils/page_validator.rb +0 -133
- data/lib/howitzer/vendor/firebug-1.12.1-fx.xpi +0 -0
- data/lib/howitzer/vendor/firepath-0.9.7-fx.xpi +0 -0
- data/lib/howitzer/web_page.rb +0 -253
- data/spec/active_resource.rb +0 -0
- data/spec/config/default.yml +0 -26
- data/spec/support/boot_helper.rb +0 -15
- data/spec/unit/generators/pages_generator_spec.rb +0 -33
- data/spec/unit/lib/capybara/dsl_ex_spec.rb +0 -60
- data/spec/unit/lib/capybara/settings_spec.rb +0 -441
- data/spec/unit/lib/helpers_spec.rb +0 -1129
- data/spec/unit/lib/mailgun/client_spec.rb +0 -36
- data/spec/unit/lib/mailgun/connector_spec.rb +0 -70
- data/spec/unit/lib/mailgun/response_spec.rb +0 -28
- data/spec/unit/lib/settings_spec.rb +0 -17
- data/spec/unit/lib/utils/data_generator/data_storage_spec.rb +0 -80
- data/spec/unit/lib/utils/data_generator/gen_spec.rb +0 -90
- data/spec/unit/lib/utils/locator_store_spec.rb +0 -157
- data/spec/unit/lib/utils/log_spec.rb +0 -107
- data/spec/unit/lib/utils/page_validator_spec.rb +0 -265
- data/spec/unit/lib/web_page_spec.rb +0 -346
@@ -1,20 +1,21 @@
|
|
1
1
|
require 'fileutils'
|
2
2
|
require_relative '../../generators/base_generator'
|
3
3
|
|
4
|
-
module
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
4
|
+
module Howitzer
|
5
|
+
module GeneratorHelper
|
6
|
+
def file_tree_info(root)
|
7
|
+
Dir["#{root}/**/.*", "#{root}/**/*"].sort_by { |name| name.sub(root, '') }.map do |name|
|
8
|
+
hash = { name: name.sub(root, ''), is_directory: File.directory?(name) }
|
9
|
+
hash[:size] = File.stat(name).size unless hash[:is_directory]
|
10
|
+
hash
|
11
|
+
end
|
10
12
|
end
|
11
|
-
end
|
12
13
|
|
13
|
-
|
14
|
-
|
14
|
+
def template_file_size(root_directory, file)
|
15
|
+
File.size(File.join(generators_path, root_directory, 'templates', file))
|
16
|
+
end
|
15
17
|
end
|
16
18
|
end
|
17
|
-
|
18
19
|
Howitzer::BaseGenerator.logger = StringIO.new
|
19
20
|
Howitzer::BaseGenerator.destination = Dir.mktmpdir
|
20
|
-
Dir[File.join(generators_path, '**', '*_generator.rb')].each{ |f| require f }
|
21
|
+
Dir[File.join(generators_path, '**', '*_generator.rb')].each { |f| require f }
|
@@ -1,12 +1,13 @@
|
|
1
|
-
module
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
1
|
+
module Howitzer
|
2
|
+
module LoggerHelper
|
3
|
+
def read_file(file)
|
4
|
+
path = File.expand_path(file, __FILE__)
|
5
|
+
IO.read(path)
|
6
|
+
end
|
6
7
|
|
7
|
-
|
8
|
-
|
9
|
-
|
8
|
+
def clear_file(file)
|
9
|
+
path = File.expand_path(file, __FILE__)
|
10
|
+
File.open(path, 'w') {}
|
11
|
+
end
|
10
12
|
end
|
11
13
|
end
|
12
|
-
|
@@ -1,60 +1,68 @@
|
|
1
|
-
require
|
2
|
-
require
|
1
|
+
require 'time'
|
2
|
+
require 'json'
|
3
3
|
require 'howitzer/exceptions'
|
4
4
|
|
5
|
-
module
|
6
|
-
|
5
|
+
module Howitzer
|
6
|
+
module MailgunApi
|
7
|
+
class UnitClient
|
8
|
+
attr_reader :url, :options, :block, :body, :code
|
7
9
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
@code = nil
|
16
|
-
end
|
10
|
+
def initialize(url, options = {}, _backwards_compatibility = nil, &block)
|
11
|
+
@url = url
|
12
|
+
@block = block
|
13
|
+
@options = options
|
14
|
+
@body = nil
|
15
|
+
@code = nil
|
16
|
+
end
|
17
17
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
when block then self.class.new(resource_path, options, &block)
|
18
|
+
def [](resource_path, &new_block)
|
19
|
+
if block_given? then self.class.new(resource_path, options, &new_block)
|
20
|
+
elsif block then self.class.new(resource_path, options, &block)
|
22
21
|
else
|
23
22
|
self.class.new(resource_path, options)
|
23
|
+
end
|
24
24
|
end
|
25
|
-
end
|
26
|
-
|
27
|
-
def get(options, query_string = nil)
|
28
|
-
begin
|
29
|
-
if query_string
|
30
25
|
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
Response.new(response)
|
36
|
-
rescue Exception => e
|
37
|
-
log.error Howitzer::CommunicationError.new(e), e.response
|
26
|
+
def get(_options, _query_string = nil)
|
27
|
+
Response.new(response_generator('bounces'))
|
28
|
+
rescue StandardError => e
|
29
|
+
raise Howitzer::CommunicationError.new(e), e.response
|
38
30
|
end
|
39
|
-
end
|
40
31
|
|
41
|
-
|
32
|
+
private
|
42
33
|
|
43
|
-
|
44
|
-
|
45
|
-
when
|
34
|
+
def response_generator(resource_endpoint)
|
35
|
+
case resource_endpoint
|
36
|
+
when 'messages'
|
46
37
|
t = Time.now
|
47
|
-
id = "<#{t.to_i}.#{rand(
|
48
|
-
@body = JSON.generate(
|
49
|
-
when
|
50
|
-
@body = JSON.generate(
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
38
|
+
id = "<#{t.to_i}.#{rand(99_999_999)}.5817@example.com>"
|
39
|
+
@body = JSON.generate('message' => 'Queued. Thank you.', 'id' => id)
|
40
|
+
when 'bounces'
|
41
|
+
@body = JSON.generate(
|
42
|
+
'total_count' => 1,
|
43
|
+
'items' => {
|
44
|
+
'created_at' => 'Fri, 21 Oct 2011 11:02:55 GMT',
|
45
|
+
'code' => 550,
|
46
|
+
'address' => 'baz@example.com',
|
47
|
+
'error' => 'Message was not accepted -- invalid mailbox. Local mailbox baz@example.com is" +
|
48
|
+
" unavailable: user not found'
|
49
|
+
}
|
50
|
+
)
|
51
|
+
when 'lists'
|
52
|
+
@body = JSON.generate(
|
53
|
+
'member' => {
|
54
|
+
'vars' => { 'age' => 26 },
|
55
|
+
'name' => 'Foo Bar',
|
56
|
+
'subscribed' => false,
|
57
|
+
'address' => 'bar@example.com'
|
58
|
+
},
|
59
|
+
'message' => 'Mailing list member has been updated'
|
60
|
+
)
|
61
|
+
when 'campaigns'
|
62
|
+
@body = JSON.generate('message' => 'Campaign has been deleted', 'id' => 'ABC123')
|
63
|
+
end
|
64
|
+
self
|
55
65
|
end
|
56
|
-
self
|
57
66
|
end
|
58
67
|
end
|
59
|
-
|
60
68
|
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
RSpec.shared_examples :capybara_context_holder do
|
4
|
+
describe '#capybara_context' do
|
5
|
+
let(:web_page_class) do
|
6
|
+
klass = described_class
|
7
|
+
Class.new do
|
8
|
+
include klass
|
9
|
+
end
|
10
|
+
end
|
11
|
+
subject { web_page_class.new.capybara_context }
|
12
|
+
context 'when parent class has the method' do
|
13
|
+
before do
|
14
|
+
web_page_class.class_eval do
|
15
|
+
def capybara_context
|
16
|
+
true
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
it 'should execute parent method' do
|
21
|
+
is_expected.to eq(true)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
context 'when parent class does not have the method' do
|
25
|
+
it 'should raise error' do
|
26
|
+
expect { subject }.to raise_error(
|
27
|
+
NotImplementedError,
|
28
|
+
"Please define 'capybara_context' method for class holder"
|
29
|
+
)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,94 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
RSpec.shared_examples :capybara_methods_proxy do
|
4
|
+
let(:session) { double(:session) }
|
5
|
+
before do
|
6
|
+
allow(Capybara).to receive(:current_session) { session }
|
7
|
+
allow(Howitzer).to receive(:driver) { driver_name }
|
8
|
+
allow(session).to receive(:current_url) { 'google.com' }
|
9
|
+
end
|
10
|
+
|
11
|
+
describe '#driver' do
|
12
|
+
it 'should proxy #driver method' do
|
13
|
+
expect(session).to receive(:driver).once
|
14
|
+
reciever.driver
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
describe '#text' do
|
19
|
+
it 'should proxy #text method' do
|
20
|
+
expect(session).to receive(:text).once
|
21
|
+
reciever.text
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
context 'when capybara session method' do
|
26
|
+
it 'should proxy method' do
|
27
|
+
expect(session).to receive(:visit).once
|
28
|
+
reciever.visit
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
context 'when capybara modal method' do
|
33
|
+
it 'should proxy method' do
|
34
|
+
expect(session).to receive(:dismiss_prompt).with(:some_text).once
|
35
|
+
reciever.dismiss_prompt(:some_text)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
describe '#click_alert_box' do
|
40
|
+
subject { reciever.click_alert_box(flag_value) }
|
41
|
+
context 'when flag true and correct driver specified' do
|
42
|
+
let(:flag_value) { true }
|
43
|
+
let(:page) { double }
|
44
|
+
let(:alert) { double }
|
45
|
+
let(:driver) { double }
|
46
|
+
let(:browser) { double }
|
47
|
+
let(:switch_to) { double }
|
48
|
+
let(:driver_name) { 'selenium' }
|
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 }
|
54
|
+
expect(alert).to receive(:accept).once
|
55
|
+
subject
|
56
|
+
end
|
57
|
+
end
|
58
|
+
context 'when flag false and correct driver specified' do
|
59
|
+
let(:flag_value) { false }
|
60
|
+
let(:page) { double }
|
61
|
+
let(:alert) { double }
|
62
|
+
let(:driver) { double }
|
63
|
+
let(:browser) { double }
|
64
|
+
let(:switch_to) { double }
|
65
|
+
let(:driver_name) { 'selenium' }
|
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 }
|
71
|
+
expect(alert).to receive(:dismiss).once
|
72
|
+
subject
|
73
|
+
end
|
74
|
+
end
|
75
|
+
context 'when flag true and wrong driver specified' do
|
76
|
+
let(:flag_value) { true }
|
77
|
+
let(:page) { double }
|
78
|
+
let(:driver_name) { 'ff' }
|
79
|
+
it do
|
80
|
+
expect(session).to receive(:evaluate_script).with('window.confirm = function() { return true; }')
|
81
|
+
subject
|
82
|
+
end
|
83
|
+
end
|
84
|
+
context 'when flag false and wrong driver specified' do
|
85
|
+
let(:driver_name) { 'ff' }
|
86
|
+
let(:flag_value) { false }
|
87
|
+
let(:page) { double }
|
88
|
+
it do
|
89
|
+
expect(session).to receive(:evaluate_script).with('window.confirm = function() { return false; }')
|
90
|
+
subject
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
RSpec.shared_examples :dynamic_section_methods do
|
3
|
+
let(:web_page_object) { web_page_class.new }
|
4
|
+
|
5
|
+
describe '#name_section' do
|
6
|
+
let(:capybara_element) { double }
|
7
|
+
subject { web_page_object.send("#{section_name}_section") }
|
8
|
+
before { expect(session).to receive(:find).with(*finder_args).once { capybara_element } }
|
9
|
+
it { is_expected.to be_a(section_class) }
|
10
|
+
end
|
11
|
+
describe '#name_sections' do
|
12
|
+
subject { web_page_object.send("#{section_name}_sections") }
|
13
|
+
let(:capybara_element1) { double }
|
14
|
+
let(:capybara_element2) { double }
|
15
|
+
before do
|
16
|
+
expect(session).to receive(:all).with(*finder_args).once { [capybara_element1, capybara_element2] }
|
17
|
+
end
|
18
|
+
it 'should return collection of sections' do
|
19
|
+
res = subject
|
20
|
+
expect(res.size).to eq(2)
|
21
|
+
expect(res.first).to be_a(section_class)
|
22
|
+
expect(res.last).to be_a(section_class)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
describe '#has_name_section?' do
|
26
|
+
subject { web_page_object.send("has_#{section_name}_section?") }
|
27
|
+
before { expect(session).to receive(:has_selector?).with(*finder_args).once { true } }
|
28
|
+
it { is_expected.to eq(true) }
|
29
|
+
end
|
30
|
+
describe '#has_no_name_element?' do
|
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 } }
|
33
|
+
it { is_expected.to eq(true) }
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,119 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
RSpec.shared_examples :element_dsl do
|
4
|
+
describe '.element' do
|
5
|
+
context 'when regular capybara params' do
|
6
|
+
before do
|
7
|
+
klass.class_eval do
|
8
|
+
element :foo, :xpath, '//a'
|
9
|
+
end
|
10
|
+
end
|
11
|
+
it 'should create private :foo_element instance method' do
|
12
|
+
expect(klass_object.private_methods(false)).to include(:foo_element)
|
13
|
+
end
|
14
|
+
it 'should create private :foo_elements instance method' do
|
15
|
+
expect(klass_object.private_methods(false)).to include(:foo_elements)
|
16
|
+
end
|
17
|
+
it 'should create public :has_foo_element? instance method' do
|
18
|
+
expect(klass_object.public_methods(false)).to include(:has_foo_element?)
|
19
|
+
end
|
20
|
+
it 'should create public :has_no_foo_element? instance method' do
|
21
|
+
expect(klass_object.public_methods(false)).to include(:has_no_foo_element?)
|
22
|
+
end
|
23
|
+
it 'should be protected class method' do
|
24
|
+
expect { klass.element :bar }.to raise_error(NoMethodError)
|
25
|
+
expect(klass.protected_methods(true)).to include(:element)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
context 'when 1 param is proc' do
|
29
|
+
before do
|
30
|
+
klass.class_eval do
|
31
|
+
element :foo, :xpath, ->(title) { "//a[.='#{title}']" }
|
32
|
+
end
|
33
|
+
end
|
34
|
+
it 'should create private :foo_element instance method' do
|
35
|
+
expect(klass_object.private_methods(false)).to include(:foo_element)
|
36
|
+
end
|
37
|
+
it 'should create private :foo_elements instance method' do
|
38
|
+
expect(klass_object.private_methods(false)).to include(:foo_elements)
|
39
|
+
end
|
40
|
+
it 'should create public :has_foo_element? instance method' do
|
41
|
+
expect(klass_object.public_methods(false)).to include(:has_foo_element?)
|
42
|
+
end
|
43
|
+
it 'should create public :has_no_foo_element? instance method' do
|
44
|
+
expect(klass_object.public_methods(false)).to include(:has_no_foo_element?)
|
45
|
+
end
|
46
|
+
it 'should be protected class method' do
|
47
|
+
expect { klass.element :bar }.to raise_error(NoMethodError)
|
48
|
+
expect(klass.protected_methods(true)).to include(:element)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
context 'when 2 params are proc' do
|
52
|
+
subject do
|
53
|
+
klass.class_eval do
|
54
|
+
element :foo, -> { puts 1 }, ->(title) { "//a[.='#{title}']" }
|
55
|
+
end
|
56
|
+
end
|
57
|
+
it 'should generate error' do
|
58
|
+
expect { subject.element :bar }.to raise_error(
|
59
|
+
Howitzer::BadElementParamsError,
|
60
|
+
'Using more than 1 proc in arguments is forbidden'
|
61
|
+
)
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
describe 'dynamic_methods' do
|
67
|
+
let(:web_page_object) { web_page_class.new }
|
68
|
+
let(:kontext) { double(:kontext) }
|
69
|
+
before do
|
70
|
+
allow(Capybara).to receive(:current_session) { kontext }
|
71
|
+
klass.class_eval do
|
72
|
+
element :foo, :xpath, ->(title) { "//a[.='#{title}']" }
|
73
|
+
element :bar, '.someclass'
|
74
|
+
end
|
75
|
+
end
|
76
|
+
after { subject }
|
77
|
+
|
78
|
+
describe '#name_element' do
|
79
|
+
context 'when simple selector' do
|
80
|
+
subject { klass_object.send(:bar_element) }
|
81
|
+
it { expect(kontext).to receive(:find).with('.someclass') }
|
82
|
+
end
|
83
|
+
context 'when lambda selector' do
|
84
|
+
subject { klass_object.send(:foo_element, 'Hello') }
|
85
|
+
it { expect(kontext).to receive(:find).with(:xpath, "//a[.='Hello']") }
|
86
|
+
end
|
87
|
+
end
|
88
|
+
describe '#name_elements' do
|
89
|
+
context 'when simple selector' do
|
90
|
+
subject { klass_object.send(:bar_elements) }
|
91
|
+
it { expect(kontext).to receive(:all).with('.someclass') }
|
92
|
+
end
|
93
|
+
context 'when lambda selector' do
|
94
|
+
subject { klass_object.send(:foo_elements, 'Hello') }
|
95
|
+
it { expect(kontext).to receive(:all).with(:xpath, "//a[.='Hello']") }
|
96
|
+
end
|
97
|
+
end
|
98
|
+
describe '#has_name_element?' do
|
99
|
+
context 'when simple selector' do
|
100
|
+
subject { klass_object.send(:has_bar_element?) }
|
101
|
+
it { expect(kontext).to receive(:has_selector?).with('.someclass') }
|
102
|
+
end
|
103
|
+
context 'when lambda selector' do
|
104
|
+
subject { klass_object.send(:has_foo_element?, 'Hello') }
|
105
|
+
it { expect(kontext).to receive(:has_selector?).with(:xpath, "//a[.='Hello']") }
|
106
|
+
end
|
107
|
+
end
|
108
|
+
describe '#has_no_name_element?' do
|
109
|
+
context 'when simple selector' do
|
110
|
+
subject { klass_object.send(:has_no_bar_element?) }
|
111
|
+
it { expect(kontext).to receive(:has_no_selector?).with('.someclass') }
|
112
|
+
end
|
113
|
+
context 'when lambda selector' do
|
114
|
+
subject { klass_object.send(:has_no_foo_element?, 'Hello') }
|
115
|
+
it { expect(kontext).to receive(:has_no_selector?).with(:xpath, "//a[.='Hello']") }
|
116
|
+
end
|
117
|
+
end
|
118
|
+
end
|
119
|
+
end
|