howitzer 1.0.2 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.coveralls.yml +1 -0
- data/.gitignore +3 -1
- data/.ruby-gemset +1 -0
- data/.travis.yml +4 -1
- data/.yardopts +5 -0
- data/CHANGELOG.md +23 -1
- data/CONTRIBUTING.md +14 -0
- data/GETTING_STARTED.md +283 -183
- data/Gemfile +3 -2
- data/LICENSE +1 -1
- data/README.md +93 -39
- data/Rakefile +4 -0
- data/bin/howitzer +34 -5
- data/features/cli_help.feature +3 -2
- data/features/cli_new.feature +1 -1
- data/features/cli_unknown.feature +1 -1
- data/features/cli_update.feature +84 -0
- data/features/step_definitions/common_steps.rb +9 -1
- data/generators/base_generator.rb +30 -15
- data/generators/config/config_generator.rb +7 -7
- data/generators/config/templates/custom.yml +1 -0
- data/generators/config/templates/default.yml +35 -5
- data/generators/cucumber/templates/env.rb +2 -2
- data/generators/cucumber/templates/transformers.rb +3 -1
- data/generators/root/templates/Gemfile +5 -3
- data/generators/root/templates/Rakefile +2 -0
- data/generators/rspec/templates/example_spec.rb +3 -3
- data/generators/rspec/templates/spec_helper.rb +6 -7
- data/howitzer.gemspec +15 -15
- data/lib/howitzer/capybara/settings.rb +125 -49
- data/lib/howitzer/helpers.rb +161 -94
- data/lib/howitzer/mailgun/client.rb +1 -1
- data/lib/howitzer/tasks/framework.rake +3 -0
- data/lib/howitzer/utils.rb +1 -1
- data/lib/howitzer/utils/locator_store.rb +1 -1
- data/lib/howitzer/utils/log.rb +1 -1
- data/lib/howitzer/utils/page_validator.rb +1 -1
- data/lib/howitzer/version.rb +1 -1
- data/lib/howitzer/web_page.rb +11 -11
- data/spec/spec_helper.rb +25 -22
- data/spec/support/generator_helper.rb +8 -1
- data/spec/unit/generators/base_generator_spec.rb +242 -0
- data/spec/unit/generators/config_generator_spec.rb +34 -0
- data/spec/unit/generators/cucumber_generator_spec.rb +45 -0
- data/spec/unit/generators/emails_generator_spec.rb +31 -0
- data/spec/unit/generators/pages_generator_spec.rb +33 -0
- data/spec/unit/generators/root_generator_spec.rb +35 -0
- data/spec/unit/generators/rspec_generator_spec.rb +36 -0
- data/spec/unit/generators/tasks_generator_spec.rb +31 -0
- data/spec/unit/lib/capybara/dsl_ex_spec.rb +11 -11
- data/spec/unit/lib/capybara/settings_spec.rb +336 -58
- data/spec/unit/lib/email_spec.rb +17 -17
- data/spec/unit/lib/helpers_spec.rb +699 -315
- data/spec/unit/lib/mailgun/client_spec.rb +9 -9
- data/spec/unit/lib/mailgun/connector_spec.rb +20 -20
- data/spec/unit/lib/mailgun/response_spec.rb +9 -9
- data/spec/unit/lib/settings_spec.rb +6 -6
- data/spec/unit/lib/utils/data_generator/data_storage_spec.rb +31 -31
- data/spec/unit/lib/utils/data_generator/gen_spec.rb +20 -20
- data/spec/unit/lib/utils/locator_store_spec.rb +39 -39
- data/spec/unit/lib/utils/log_spec.rb +42 -42
- data/spec/unit/lib/utils/page_validator_spec.rb +69 -70
- data/spec/unit/lib/web_page_spec.rb +91 -69
- data/spec/unit/version_spec.rb +3 -3
- metadata +100 -78
- data/spec/unit/generators/generators_spec.rb +0 -175
@@ -1,26 +1,26 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
require 'howitzer/mailgun/client'
|
3
3
|
|
4
|
-
describe Mailgun::Client do
|
5
|
-
let(:mg_obj) { Mailgun::Client.new(
|
6
|
-
describe
|
4
|
+
RSpec.describe Mailgun::Client do
|
5
|
+
let(:mg_obj) { Mailgun::Client.new('Fake-API-Key') }
|
6
|
+
describe '.new' do
|
7
7
|
subject { mg_obj }
|
8
8
|
it { expect { subject }.not_to raise_error }
|
9
9
|
end
|
10
10
|
|
11
|
-
describe
|
11
|
+
describe '#get' do
|
12
12
|
let(:query_string){ {'skip' => '10', 'limit' => '5'} }
|
13
|
-
subject { mg_obj.get(
|
14
|
-
context
|
13
|
+
subject { mg_obj.get('test.com/bounces', query_string) }
|
14
|
+
context 'when simulation of client' do
|
15
15
|
before do
|
16
16
|
expect(RestClient::Resource).to receive(:new).once { Mailgun::UnitClient::new('Fake-API-Key', 'api.mailgun.net', 'v2') }
|
17
17
|
end
|
18
18
|
it do
|
19
|
-
expect(subject.body).to include(
|
20
|
-
expect(subject.body).to include(
|
19
|
+
expect(subject.body).to include('total_count')
|
20
|
+
expect(subject.body).to include('items')
|
21
21
|
end
|
22
22
|
end
|
23
|
-
context
|
23
|
+
context 'when real client' do
|
24
24
|
let(:resource) { double }
|
25
25
|
before do
|
26
26
|
allow(resource).to receive('[]'){ resource }
|
@@ -1,68 +1,68 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
require 'howitzer/mailgun/connector'
|
3
3
|
|
4
|
-
describe Mailgun::Connector do
|
4
|
+
RSpec.describe Mailgun::Connector do
|
5
5
|
let(:connector) { Mailgun::Connector.instance }
|
6
6
|
let(:domain_name) { 'test@domain.com' }
|
7
|
-
describe
|
7
|
+
describe '#client' do
|
8
8
|
subject { connector.client }
|
9
|
-
context
|
10
|
-
context
|
11
|
-
it {
|
9
|
+
context 'when api_key is default' do
|
10
|
+
context 'when client is not initialized' do
|
11
|
+
it { is_expected.to be_an_instance_of Mailgun::Client }
|
12
12
|
end
|
13
|
-
context
|
13
|
+
context 'when client is already initialized' do
|
14
14
|
it do
|
15
15
|
object_id = connector.client.object_id
|
16
16
|
expect(subject.object_id).to eq(object_id)
|
17
17
|
end
|
18
18
|
end
|
19
19
|
end
|
20
|
-
context
|
21
|
-
let(:key) {
|
20
|
+
context 'when api_key is custom' do
|
21
|
+
let(:key) { 'some api key' }
|
22
22
|
subject { connector.client(key) }
|
23
|
-
it {
|
23
|
+
it { is_expected.to be_an_instance_of Mailgun::Client }
|
24
24
|
end
|
25
|
-
context
|
25
|
+
context 'when api_key is nil' do
|
26
26
|
let(:key) { nil }
|
27
27
|
subject { connector.client(key) }
|
28
28
|
it do
|
29
|
-
expect(log).to receive(:error).with(Howitzer::InvalidApiKeyError,
|
29
|
+
expect(log).to receive(:error).with(Howitzer::InvalidApiKeyError, 'Api key can not be blank').once.and_call_original
|
30
30
|
expect { subject }.to raise_error(Howitzer::InvalidApiKeyError)
|
31
31
|
end
|
32
32
|
end
|
33
|
-
context
|
34
|
-
let(:key) {
|
33
|
+
context 'when api_key is blank string' do
|
34
|
+
let(:key) { '' }
|
35
35
|
subject { connector.client(key) }
|
36
36
|
it do
|
37
|
-
expect(log).to receive(:error).with(Howitzer::InvalidApiKeyError,
|
37
|
+
expect(log).to receive(:error).with(Howitzer::InvalidApiKeyError, 'Api key can not be blank').once.and_call_original
|
38
38
|
expect { subject }.to raise_error(Howitzer::InvalidApiKeyError)
|
39
39
|
end
|
40
40
|
end
|
41
41
|
end
|
42
42
|
describe '#domain' do
|
43
43
|
subject { connector.domain }
|
44
|
-
context
|
44
|
+
context 'when domain is not set' do
|
45
45
|
before { connector.instance_variable_set(:@domain, nil)}
|
46
46
|
it do
|
47
47
|
expect(connector).to receive(:change_domain).once{ domain_name }
|
48
|
-
|
48
|
+
is_expected.to eq(domain_name)
|
49
49
|
end
|
50
50
|
end
|
51
|
-
context
|
51
|
+
context 'when domain is already set' do
|
52
52
|
before do
|
53
53
|
expect(connector).to receive(:change_domain).never
|
54
54
|
connector.instance_variable_set(:@domain, domain_name)
|
55
55
|
end
|
56
|
-
it {
|
56
|
+
it { is_expected.to eql(domain_name) }
|
57
57
|
end
|
58
58
|
end
|
59
59
|
|
60
60
|
describe '#change_domain' do
|
61
|
-
context
|
61
|
+
context 'when default' do
|
62
62
|
before { connector.change_domain }
|
63
63
|
it { expect(connector.instance_variable_get(:@domain)).to eq(settings.mailgun_domain)}
|
64
64
|
end
|
65
|
-
context
|
65
|
+
context 'when custom' do
|
66
66
|
before { connector.change_domain(domain_name) }
|
67
67
|
it { expect(connector.instance_variable_get(:@domain)).to eq(domain_name) }
|
68
68
|
end
|
@@ -2,23 +2,23 @@ require 'spec_helper'
|
|
2
2
|
require 'howitzer/mailgun/client'
|
3
3
|
require 'howitzer/exceptions'
|
4
4
|
|
5
|
-
describe Mailgun::Response do
|
5
|
+
RSpec.describe Mailgun::Response do
|
6
6
|
let(:body) { {foo: 'bar'}.to_json }
|
7
7
|
let(:response) { double(:response, body: body, code: 201)}
|
8
|
-
describe
|
8
|
+
describe '#body' do
|
9
9
|
subject { Mailgun::Response.new(response).body }
|
10
|
-
it {
|
10
|
+
it { is_expected.to eq("{\"foo\":\"bar\"}")}
|
11
11
|
end
|
12
|
-
describe
|
12
|
+
describe '#code' do
|
13
13
|
subject { Mailgun::Response.new(response).code }
|
14
|
-
it {
|
14
|
+
it { is_expected.to eq(201)}
|
15
15
|
end
|
16
|
-
describe
|
16
|
+
describe '#to_h' do
|
17
17
|
subject { Mailgun::Response.new(response).to_h }
|
18
|
-
context
|
19
|
-
it {
|
18
|
+
context 'when possible parse body' do
|
19
|
+
it { is_expected.to eq({'foo' => 'bar'})}
|
20
20
|
end
|
21
|
-
context
|
21
|
+
context 'when impossible parse body' do
|
22
22
|
let(:body) { '123' }
|
23
23
|
it do
|
24
24
|
expect(log).to receive(:error).with(Howitzer::ParseError, "757: unexpected token at '123'").once.and_call_original
|
@@ -1,17 +1,17 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe
|
4
|
-
context
|
3
|
+
RSpec.describe 'Settings' do
|
4
|
+
context '#settings' do
|
5
5
|
subject { settings }
|
6
|
-
context
|
6
|
+
context 'when method called two times' do
|
7
7
|
let(:other_settings) { settings }
|
8
|
-
it {
|
8
|
+
it { is_expected.to equal(other_settings) }
|
9
9
|
it { expect(other_settings).to be_a_kind_of(SexySettings::Base) }
|
10
10
|
end
|
11
11
|
end
|
12
|
-
context
|
12
|
+
context 'SexySettings configuration' do
|
13
13
|
subject { SexySettings.configuration }
|
14
14
|
it { expect(subject.path_to_custom_settings).to include('config/custom.yml') }
|
15
15
|
it { expect(subject.path_to_default_settings).to include('config/default.yml') }
|
16
16
|
end
|
17
|
-
end
|
17
|
+
end
|
@@ -1,79 +1,79 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
require 'howitzer/utils/data_generator/data_storage'
|
3
3
|
|
4
|
-
describe
|
5
|
-
describe
|
4
|
+
RSpec.describe 'DataGenerator' do
|
5
|
+
describe 'DataStorage' do
|
6
6
|
before { DataGenerator::DataStorage.data.clear }
|
7
|
-
describe
|
7
|
+
describe '.store' do
|
8
8
|
subject { DataGenerator::DataStorage.store(ns, 7, :halt) }
|
9
|
-
context
|
9
|
+
context 'when namespace specified' do
|
10
10
|
let(:ns) { :user }
|
11
|
-
it
|
12
|
-
|
11
|
+
it 'should return value' do
|
12
|
+
is_expected.to eql(:halt)
|
13
13
|
end
|
14
|
-
it
|
14
|
+
it 'should store namespace value' do
|
15
15
|
subject
|
16
16
|
expect(DataGenerator::DataStorage.data[:user]).to eql({7 => :halt})
|
17
17
|
end
|
18
18
|
end
|
19
|
-
context
|
19
|
+
context 'when namespace empty' do
|
20
20
|
let(:ns) { nil }
|
21
|
-
it { expect {subject}.to raise_error(RuntimeError,
|
21
|
+
it { expect {subject}.to raise_error(RuntimeError, 'Data storage namespace can not be empty') }
|
22
22
|
end
|
23
23
|
end
|
24
|
-
describe
|
24
|
+
describe '.extract' do
|
25
25
|
subject { DataGenerator::DataStorage.extract(ns, key) }
|
26
26
|
before { DataGenerator::DataStorage.data[:user] = {7 => :exit} }
|
27
|
-
describe
|
27
|
+
describe 'when namespace specified' do
|
28
28
|
let(:ns) { :user }
|
29
|
-
context
|
29
|
+
context 'and namespace key found' do
|
30
30
|
let(:key) { 7 }
|
31
|
-
it {
|
31
|
+
it { is_expected.to eql(:exit) }
|
32
32
|
end
|
33
|
-
context
|
33
|
+
context 'and namespace key not found' do
|
34
34
|
let(:key) { 5 }
|
35
|
-
it {
|
35
|
+
it { is_expected.to be_nil }
|
36
36
|
end
|
37
|
-
context
|
37
|
+
context 'but namespace key not specified' do
|
38
38
|
let(:key) { nil }
|
39
|
-
it {
|
39
|
+
it { is_expected.to eql({ 7 => :exit }) }
|
40
40
|
end
|
41
41
|
end
|
42
|
-
context
|
42
|
+
context 'when namespace not found' do
|
43
43
|
let(:ns) { :guest }
|
44
44
|
let(:key) { 11 }
|
45
|
-
it {
|
45
|
+
it { is_expected.to be_nil }
|
46
46
|
end
|
47
|
-
context
|
47
|
+
context 'when namespace not specified' do
|
48
48
|
let(:ns) { nil }
|
49
49
|
let(:key) { nil }
|
50
|
-
it { expect {subject}.to raise_error(RuntimeError,
|
50
|
+
it { expect {subject}.to raise_error(RuntimeError, 'Data storage namespace can not be empty') }
|
51
51
|
end
|
52
52
|
end
|
53
|
-
describe
|
53
|
+
describe '.clear_ns' do
|
54
54
|
subject { DataGenerator::DataStorage.clear_ns(:user) }
|
55
55
|
before { DataGenerator::DataStorage.data[:user]= {7 => :exit}}
|
56
|
-
it
|
56
|
+
it 'should return empty hash' do
|
57
57
|
subject
|
58
58
|
adata = DataGenerator::DataStorage.instance_variable_get(:@data)
|
59
59
|
expect(adata[:user]).to eql({})
|
60
60
|
end
|
61
61
|
end
|
62
|
-
describe
|
62
|
+
describe '.clear_all_ns' do
|
63
63
|
before do
|
64
64
|
DataGenerator::DataStorage.store('sauce', :status, false)
|
65
|
-
DataGenerator::DataStorage.store(:foo,
|
66
|
-
DataGenerator::DataStorage.store(:bar,
|
67
|
-
DataGenerator::DataStorage.store(:baz,
|
65
|
+
DataGenerator::DataStorage.store(:foo, 'foo', 'some value1')
|
66
|
+
DataGenerator::DataStorage.store(:bar, 'bar', 'some value2')
|
67
|
+
DataGenerator::DataStorage.store(:baz, 'baz', 'some value3')
|
68
68
|
end
|
69
|
-
context
|
69
|
+
context 'when default argument' do
|
70
70
|
before { DataGenerator::DataStorage.clear_all_ns }
|
71
|
-
it { expect(DataGenerator::DataStorage.data).to eq({
|
71
|
+
it { expect(DataGenerator::DataStorage.data).to eq({'sauce' =>{:status=>false}, :foo=>{}, :bar=>{}, :baz=>{}}) }
|
72
72
|
end
|
73
|
-
context
|
73
|
+
context 'when custom argument' do
|
74
74
|
let(:exception_list) { [:foo, :bar] }
|
75
75
|
before { DataGenerator::DataStorage.clear_all_ns(exception_list) }
|
76
|
-
it { expect(DataGenerator::DataStorage.data).to eq({
|
76
|
+
it { expect(DataGenerator::DataStorage.data).to eq({'sauce' =>{}, :foo=>{'foo' => 'some value1'}, :bar=>{'bar' => 'some value2'}, :baz=>{}}) }
|
77
77
|
end
|
78
78
|
end
|
79
79
|
end
|
@@ -1,18 +1,18 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
require 'howitzer/utils/data_generator/gen'
|
3
3
|
|
4
|
-
describe
|
5
|
-
describe
|
6
|
-
describe
|
4
|
+
RSpec.describe 'DataGenerator' do
|
5
|
+
describe 'Gen' do
|
6
|
+
describe '.user' do
|
7
7
|
subject { DataGenerator::Gen.user(params) }
|
8
8
|
before do
|
9
9
|
allow(settings).to receive(:def_test_pass) { 'test_pass' }
|
10
10
|
allow(settings).to receive(:mailgun_domain) { 'mail.com' }
|
11
11
|
allow(DataGenerator::Gen).to receive(:serial) { '012345678abcde' }
|
12
12
|
end
|
13
|
-
context
|
13
|
+
context 'when params specified' do
|
14
14
|
let(:params) { { login: 'alex', password: 'pa$$w0rd', mailbox: 'member@test.com' } }
|
15
|
-
it {
|
15
|
+
it { is_expected.to be_an_instance_of DataGenerator::Gen::User }
|
16
16
|
it { expect(subject.email).to eql 'u012345678abcde@mail.com' }
|
17
17
|
it do
|
18
18
|
email_nm = subject.instance_variable_get(:@email_name)
|
@@ -24,9 +24,9 @@ describe "DataGenerator" do
|
|
24
24
|
it { expect(subject.first_name).to eql 'FirstName012345678abcde' }
|
25
25
|
it { expect(subject.last_name).to eql 'LastName012345678abcde' }
|
26
26
|
end
|
27
|
-
context
|
27
|
+
context 'with empty params' do
|
28
28
|
let(:params) { {} }
|
29
|
-
it {
|
29
|
+
it { is_expected.to be_an_instance_of DataGenerator::Gen::User }
|
30
30
|
it { expect(subject.email).to eql 'u012345678abcde@mail.com' }
|
31
31
|
it do
|
32
32
|
email_nm = subject.instance_variable_get(:@email_name)
|
@@ -39,40 +39,40 @@ describe "DataGenerator" do
|
|
39
39
|
it { expect(subject.last_name).to eql 'LastName012345678abcde' }
|
40
40
|
end
|
41
41
|
end
|
42
|
-
describe
|
42
|
+
describe '.given_user_by_number' do
|
43
43
|
subject { DataGenerator::Gen.given_user_by_number(7) }
|
44
|
-
before { stub_const(
|
45
|
-
context
|
44
|
+
before { stub_const('DataGenerator::DataStorage', double) }
|
45
|
+
context 'when namespace key found' do
|
46
46
|
before { expect(DataGenerator::DataStorage).to receive(:extract).with('user', 7) { :namespace_value } }
|
47
|
-
it {
|
47
|
+
it { is_expected.to eql(:namespace_value) }
|
48
48
|
end
|
49
|
-
context
|
49
|
+
context 'when namespace key not found' do
|
50
50
|
let(:dat) { :data_store }
|
51
51
|
before do
|
52
52
|
allow(DataGenerator::Gen).to receive(:user) { dat }
|
53
53
|
expect(DataGenerator::DataStorage).to receive(:extract).with('user', 7) { nil }
|
54
54
|
allow(DataGenerator::DataStorage).to receive(:store).with('user', 7, dat)
|
55
55
|
end
|
56
|
-
it {
|
56
|
+
it { is_expected.to eql :data_store }
|
57
57
|
end
|
58
58
|
end
|
59
|
-
describe
|
59
|
+
describe '.serial' do
|
60
60
|
subject { DataGenerator::Gen.serial }
|
61
61
|
let(:ser) { 1 }
|
62
|
-
context
|
62
|
+
context 'received value should conform to template' do
|
63
63
|
let(:ser) { subject }
|
64
64
|
it { expect(ser).to match /\d{9}\w{5}/ }
|
65
65
|
end
|
66
|
-
context
|
67
|
-
it {
|
66
|
+
context 'received values should be different' do
|
67
|
+
it { is_expected.to_not eql ser }
|
68
68
|
end
|
69
69
|
end
|
70
|
-
describe
|
71
|
-
describe
|
70
|
+
describe 'User' do
|
71
|
+
describe '#initialize' do
|
72
72
|
subject { DataGenerator::Gen::User.new(params) }
|
73
73
|
let(:params) { { email: 'alex.petrenko@mail.com', login: 'alex', password: 'pa$$w0rd',
|
74
74
|
first_name: 'Alexey', last_name: 'Petrenko', mailbox: 'member@test.com' } }
|
75
|
-
it {
|
75
|
+
it { is_expected.to be_an_instance_of DataGenerator::Gen::User }
|
76
76
|
it { expect(subject.email).to eql 'alex.petrenko@mail.com' }
|
77
77
|
it do
|
78
78
|
email_nm = subject.instance_variable_get(:@email_name)
|
@@ -1,80 +1,80 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
require 'howitzer/utils/locator_store'
|
3
3
|
|
4
|
-
describe
|
4
|
+
RSpec.describe 'Locator store' do
|
5
5
|
let(:bad_name) { 'name' }
|
6
6
|
let(:error) { Howitzer::LocatorNotDefinedError }
|
7
7
|
|
8
|
-
shared_examples
|
8
|
+
shared_examples 'locator methods' do |prefix, web_page|
|
9
9
|
describe "#{prefix}locator" do
|
10
|
-
context
|
10
|
+
context 'when bad locator given' do
|
11
11
|
subject { web_page.locator(bad_name) }
|
12
12
|
it do
|
13
13
|
expect(log).to receive(:error).with(error, bad_name).once.and_call_original
|
14
14
|
expect { subject }.to raise_error(error)
|
15
15
|
end
|
16
16
|
end
|
17
|
-
context
|
17
|
+
context 'when CSS locator given' do
|
18
18
|
before { web_page.add_locator :base_locator, 'base_locator' }
|
19
19
|
subject { web_page.locator(:base_locator) }
|
20
|
-
it {
|
20
|
+
it { is_expected.to eq('base_locator') }
|
21
21
|
end
|
22
|
-
context
|
22
|
+
context 'when XPATH locator given' do
|
23
23
|
before { web_page.add_locator :test_xpath, xpath: "//select[@id='modelOptions']/option[@value='m6']" }
|
24
24
|
subject { web_page.locator(:test_xpath) }
|
25
|
-
it {
|
25
|
+
it { is_expected.to eq([:xpath, "//select[@id='modelOptions']/option[@value='m6']"]) }
|
26
26
|
end
|
27
27
|
end
|
28
28
|
|
29
29
|
describe "#{prefix}link_locator" do
|
30
|
-
context
|
30
|
+
context 'when bad locator given' do
|
31
31
|
subject { web_page.link_locator(bad_name) }
|
32
32
|
it { expect {subject}. to raise_error(error) }
|
33
33
|
end
|
34
|
-
context
|
34
|
+
context 'when correct locator given' do
|
35
35
|
before { web_page.add_link_locator :link_locator, 'link_locator' }
|
36
36
|
subject { web_page.link_locator(:link_locator) }
|
37
|
-
it {
|
37
|
+
it { is_expected.to eq('link_locator') }
|
38
38
|
end
|
39
39
|
end
|
40
40
|
|
41
41
|
describe "#{prefix}field_locator" do
|
42
|
-
context
|
42
|
+
context 'when bad locator given' do
|
43
43
|
subject { web_page.field_locator(bad_name) }
|
44
44
|
it { expect {subject}. to raise_error(error) }
|
45
45
|
end
|
46
|
-
context
|
46
|
+
context 'when correct locator given' do
|
47
47
|
before { web_page.add_field_locator :field_locator, 'field_locator' }
|
48
48
|
subject { web_page.field_locator(:field_locator) }
|
49
|
-
it {
|
49
|
+
it { is_expected.to eq('field_locator') }
|
50
50
|
end
|
51
51
|
end
|
52
52
|
|
53
53
|
describe "#{prefix}button_locator" do
|
54
|
-
context
|
54
|
+
context 'when bad locator given' do
|
55
55
|
subject { web_page.button_locator(bad_name) }
|
56
56
|
it { expect {subject}. to raise_error(error) }
|
57
57
|
end
|
58
|
-
context
|
58
|
+
context 'when correct locator given' do
|
59
59
|
before { web_page.add_button_locator :button_locator, 'button_locator' }
|
60
60
|
subject { web_page.button_locator(:button_locator) }
|
61
|
-
it {
|
61
|
+
it { is_expected.to eq('button_locator') }
|
62
62
|
end
|
63
63
|
end
|
64
64
|
|
65
65
|
describe "#{prefix}find_element" do
|
66
|
-
context
|
67
|
-
context
|
66
|
+
context 'when existing locator name given' do
|
67
|
+
context 'of base type' do
|
68
68
|
before { web_page.add_locator :test_locator, '.foo' }
|
69
69
|
subject { web_page.find_element(name) }
|
70
|
-
context
|
71
|
-
let(:name) {
|
70
|
+
context 'as string' do
|
71
|
+
let(:name) { 'test_locator' }
|
72
72
|
it do
|
73
73
|
expect(web_page.is_a?(Class) ? web_page : web_page.class).to receive(:find).with('.foo')
|
74
74
|
subject
|
75
75
|
end
|
76
76
|
end
|
77
|
-
context
|
77
|
+
context 'as symbol' do
|
78
78
|
let(:name) { :test_locator }
|
79
79
|
it do
|
80
80
|
expect(web_page.is_a?(Class) ? web_page : web_page.class).to receive(:find).with('.foo')
|
@@ -82,7 +82,7 @@ describe "Locator store" do
|
|
82
82
|
end
|
83
83
|
end
|
84
84
|
end
|
85
|
-
context
|
85
|
+
context 'when link locator or other' do
|
86
86
|
before { web_page.add_link_locator :test_link_locator, 'foo' }
|
87
87
|
subject { web_page.find_element(:test_link_locator) }
|
88
88
|
it do
|
@@ -91,24 +91,24 @@ describe "Locator store" do
|
|
91
91
|
end
|
92
92
|
end
|
93
93
|
end
|
94
|
-
context
|
94
|
+
context 'when not existing locator name' do
|
95
95
|
subject { web_page.find_element(:unknown_locator) }
|
96
|
-
it { expect{ subject }.to raise_error(Howitzer::LocatorNotDefinedError,
|
96
|
+
it { expect{ subject }.to raise_error(Howitzer::LocatorNotDefinedError, 'unknown_locator') }
|
97
97
|
end
|
98
98
|
end
|
99
99
|
describe "#{prefix}first_element" do
|
100
|
-
context
|
101
|
-
context
|
100
|
+
context 'when existing locator name given' do
|
101
|
+
context 'of base type' do
|
102
102
|
before { web_page.add_locator :test_locator, '.foo' }
|
103
103
|
subject { web_page.first_element(name) }
|
104
|
-
context
|
105
|
-
let(:name) {
|
104
|
+
context 'as string' do
|
105
|
+
let(:name) { 'test_locator' }
|
106
106
|
it do
|
107
107
|
expect(web_page.is_a?(Class) ? web_page : web_page.class).to receive(:first).with('.foo')
|
108
108
|
subject
|
109
109
|
end
|
110
110
|
end
|
111
|
-
context
|
111
|
+
context 'as symbol' do
|
112
112
|
let(:name) { :test_locator }
|
113
113
|
it do
|
114
114
|
expect(web_page.is_a?(Class) ? web_page : web_page.class).to receive(:first).with('.foo')
|
@@ -116,7 +116,7 @@ describe "Locator store" do
|
|
116
116
|
end
|
117
117
|
end
|
118
118
|
end
|
119
|
-
context
|
119
|
+
context 'when link locator or other' do
|
120
120
|
before { web_page.add_link_locator :test_link_locator, 'foo' }
|
121
121
|
subject { web_page.first_element(:test_link_locator) }
|
122
122
|
it do
|
@@ -125,33 +125,33 @@ describe "Locator store" do
|
|
125
125
|
end
|
126
126
|
end
|
127
127
|
end
|
128
|
-
context
|
128
|
+
context 'when not existing locator name' do
|
129
129
|
subject { web_page.first_element(:unknown_locator) }
|
130
|
-
it { expect{ subject }.to raise_error(Howitzer::LocatorNotDefinedError,
|
130
|
+
it { expect{ subject }.to raise_error(Howitzer::LocatorNotDefinedError, 'unknown_locator') }
|
131
131
|
end
|
132
132
|
end
|
133
133
|
describe "#{prefix}apply" do
|
134
|
-
context
|
134
|
+
context 'when bad locator given' do
|
135
135
|
before { web_page.add_locator :test_locator, lambda{|test| test} }
|
136
136
|
let(:locator) { lambda{|test| test} }
|
137
137
|
subject { web_page.apply(locator, 'test') }
|
138
138
|
it { expect {subject}.to raise_error(NoMethodError) }
|
139
139
|
end
|
140
|
-
context
|
140
|
+
context 'when correct locator given' do
|
141
141
|
before { web_page.add_locator :test_locator, lambda{|location_name| {xpath: ".//a[contains(.,'#{location_name}')]"}} }
|
142
142
|
let(:locator) { lambda{|location_name| {xpath: ".//a[contains(.,'#{location_name}')]"}} }
|
143
143
|
subject { web_page.apply(locator, 'Kiev') }
|
144
|
-
it {
|
144
|
+
it { is_expected.to eq([:xpath, ".//a[contains(.,'Kiev')]"]) }
|
145
145
|
end
|
146
146
|
end
|
147
147
|
end
|
148
148
|
|
149
|
-
context
|
150
|
-
it_behaves_like
|
149
|
+
context 'Class methods' do
|
150
|
+
it_behaves_like 'locator methods', '.', Class.new{ include LocatorStore }
|
151
151
|
end
|
152
152
|
|
153
|
-
context
|
154
|
-
it_behaves_like
|
153
|
+
context 'Instance methods' do
|
154
|
+
it_behaves_like 'locator methods', '#', Class.new{ include LocatorStore }.new
|
155
155
|
end
|
156
156
|
|
157
157
|
end
|