Skip to content

Commit

Permalink
Merge 902d3b2 into ef429f9
Browse files Browse the repository at this point in the history
  • Loading branch information
romikoops committed Nov 5, 2016
2 parents ef429f9 + 902d3b2 commit d0c3d26
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 48 deletions.
4 changes: 3 additions & 1 deletion generators/base_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,9 @@ def initialize(_options)
end
end

def manifest; end
def manifest
[]
end

protected

Expand Down
8 changes: 6 additions & 2 deletions lib/howitzer/web/element_dsl.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,13 @@ def capybara_context
private

def convert_arguments(args, params)
args.map do |arg|
arg.is_a?(Proc) ? arg.call(*params) : arg
hash = params.pop if params.last.is_a?(Hash)
args.map! do |el|
next(el) unless el.is_a?(Proc)
el.call(*params.shift(el.arity))
end
args << hash unless hash.nil?
args
end

# This module holds element dsl methods methods
Expand Down
8 changes: 1 addition & 7 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,5 @@ def log_path
RSpec.configure do |config|
config.include Howitzer::GeneratorHelper
config.disable_monkey_patching = true
config.around(:each) do |ex|
$stdout = StringIO.new
$stderr = StringIO.new
ex.run
$stdout = STDOUT
$stderr = STDERR
end
config.around(:each, &:run)
end
36 changes: 19 additions & 17 deletions spec/support/shared_examples/element_dsl.rb
Original file line number Diff line number Diff line change
Expand Up @@ -69,50 +69,52 @@
before do
allow(Capybara).to receive(:current_session) { kontext }
klass.class_eval do
element :foo, :xpath, ->(title) { "//a[.='#{title}']" }
element :foo, :xpath, ->(title, name) { "//a[.='#{title}']/*[@name='#{name}']" }
element :bar, '.someclass'
end
end
after { subject }

describe '#name_element' do
context 'when simple selector' do
subject { klass_object.send(:bar_element) }
it { expect(kontext).to receive(:find).with('.someclass') }
subject { klass_object.send(:bar_element, wait: 10) }
it { expect(kontext).to receive(:find).with('.someclass', wait: 10) }
end
context 'when lambda selector' do
subject { klass_object.send(:foo_element, 'Hello') }
it { expect(kontext).to receive(:find).with(:xpath, "//a[.='Hello']") }
subject { klass_object.send(:foo_element, 'Hello', 'super', wait: 10) }
it { expect(kontext).to receive(:find).with(:xpath, "//a[.='Hello']/*[@name='super']", wait: 10) }
end
end
describe '#name_elements' do
context 'when simple selector' do
subject { klass_object.send(:bar_elements) }
it { expect(kontext).to receive(:all).with('.someclass') }
subject { klass_object.send(:bar_elements, wait: 10) }
it { expect(kontext).to receive(:all).with('.someclass', wait: 10) }
end
context 'when lambda selector' do
subject { klass_object.send(:foo_elements, 'Hello') }
it { expect(kontext).to receive(:all).with(:xpath, "//a[.='Hello']") }
subject { klass_object.send(:foo_elements, 'Hello', 'super', wait: 10) }
it { expect(kontext).to receive(:all).with(:xpath, "//a[.='Hello']/*[@name='super']", wait: 10) }
end
end
describe '#has_name_element?' do
context 'when simple selector' do
subject { klass_object.send(:has_bar_element?) }
it { expect(kontext).to receive(:has_selector?).with('.someclass') }
subject { klass_object.send(:has_bar_element?, wait: 10) }
it { expect(kontext).to receive(:has_selector?).with('.someclass', wait: 10) }
end
context 'when lambda selector' do
subject { klass_object.send(:has_foo_element?, 'Hello') }
it { expect(kontext).to receive(:has_selector?).with(:xpath, "//a[.='Hello']") }
subject { klass_object.send(:has_foo_element?, 'Hello', 'super', wait: 10) }
it { expect(kontext).to receive(:has_selector?).with(:xpath, "//a[.='Hello']/*[@name='super']", wait: 10) }
end
end
describe '#has_no_name_element?' do
context 'when simple selector' do
subject { klass_object.send(:has_no_bar_element?) }
it { expect(kontext).to receive(:has_no_selector?).with('.someclass') }
subject { klass_object.send(:has_no_bar_element?, wait: 10) }
it { expect(kontext).to receive(:has_no_selector?).with('.someclass', wait: 10) }
end
context 'when lambda selector' do
subject { klass_object.send(:has_no_foo_element?, 'Hello') }
it { expect(kontext).to receive(:has_no_selector?).with(:xpath, "//a[.='Hello']") }
subject { klass_object.send(:has_no_foo_element?, 'Hello', 'super', wait: 10) }
it do
expect(kontext).to receive(:has_no_selector?).with(:xpath, "//a[.='Hello']/*[@name='super']", wait: 10)
end
end
end
end
Expand Down
31 changes: 15 additions & 16 deletions spec/unit/generators/base_generator_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,19 +52,19 @@

describe '#manifest' do
subject { described_class.new({}).manifest }
before { allow_any_instance_of(described_class).to receive(:initialize) { nil } }
it { is_expected.to be_nil }
before { allow_any_instance_of(described_class).to receive(:print_banner) { nil } }
it { is_expected.to eq([]) }
end

describe '#banner' do
subject { described_class.new({}).send(:banner) }
before { allow_any_instance_of(described_class).to receive(:initialize) { nil } }
before { allow_any_instance_of(described_class).to receive(:print_banner) { nil } }
it { is_expected.to be_nil }
end

describe '#logger' do
subject { described_class.new({}).send(:logger) }
before { allow_any_instance_of(described_class).to receive(:initialize) { nil } }
before { allow_any_instance_of(described_class).to receive(:print_banner) { nil } }
context 'when not specified' do
before { described_class.instance_variable_set('@logger', nil) }
it { is_expected.to eq($stdout) }
Expand All @@ -79,7 +79,7 @@
describe '#destination' do
subject { described_class.new({}).send(:destination) }
before do
allow_any_instance_of(described_class).to receive(:initialize) { nil }
allow_any_instance_of(described_class).to receive(:print_banner) { nil }
allow(described_class).to receive(:destination) { '/' }
end
it { is_expected.to eq('/') }
Expand All @@ -91,7 +91,7 @@
let(:generator) { described_class.new({}) }
subject { generator.send(:copy_files, list) }
before do
allow_any_instance_of(described_class).to receive(:initialize) { nil }
allow_any_instance_of(described_class).to receive(:print_banner) { nil }
allow(generator).to receive(:source_path).with(list.first[:source]) { source_path }
end
after { subject }
Expand All @@ -112,7 +112,7 @@
let(:generator) { described_class.new('rspec' => true) }
subject { generator.send(:copy_templates, list) }
before do
allow_any_instance_of(described_class).to receive(:initialize) { nil }
allow_any_instance_of(described_class).to receive(:print_banner) { nil }
allow(generator).to receive(:source_path).with(list.first[:source]) { source_path }
allow(generator).to receive(:dest_path).with(list.first[:destination]) { destination_path }
allow(generator).to receive(:write_template).with(destination_path, source_path)
Expand Down Expand Up @@ -147,13 +147,12 @@
let(:generator) { described_class.new({}) }
subject { generator.send(:print_banner) }
before do
allow_any_instance_of(described_class).to receive(:initialize) { nil }
allow(generator).to receive(:banner) { banner }
allow_any_instance_of(described_class).to receive(:banner) { banner }
end
after { subject }
context 'when banner present' do
let(:banner) { 'banner' }
it { expect(described_class.logger).to receive(:puts).with(banner).once }
it { expect(described_class.logger).to receive(:puts).with(banner).twice }
end
context 'when banner blank' do
let(:banner) { '' }
Expand All @@ -163,36 +162,36 @@

describe '#print_info' do
subject { described_class.new({}).send(:print_info, 'data') }
before { allow_any_instance_of(described_class).to receive(:initialize) { nil } }
before { allow_any_instance_of(described_class).to receive(:print_banner) { nil } }
after { subject }
it { expect(described_class.logger).to receive(:print).with(' data') }
end

describe '#puts_info' do
subject { described_class.new({}).send(:puts_info, 'data') }
before { allow_any_instance_of(described_class).to receive(:initialize) { nil } }
before { allow_any_instance_of(described_class).to receive(:print_banner) { nil } }
after { subject }
it { expect(described_class.logger).to receive(:puts).with(' data') }
end

describe '#puts_error' do
subject { described_class.new({}).send(:puts_error, 'data') }
before { allow_any_instance_of(described_class).to receive(:initialize) { nil } }
before { allow_any_instance_of(described_class).to receive(:print_banner) { nil } }
after { subject }
it { expect(described_class.logger).to receive(:puts).with(' ERROR: data') }
end

describe '#source_path' do
subject { described_class.new({}).send(:source_path, 'example.txt') }
before do
allow_any_instance_of(described_class).to receive(:initialize) { nil }
allow_any_instance_of(described_class).to receive(:print_banner) { nil }
end
it { is_expected.to include('/base/templates/example.txt') }
end

describe '#dest_path' do
subject { described_class.new({}).send(:dest_path, 'example.txt') }
before { allow_any_instance_of(described_class).to receive(:initialize) { nil } }
before { allow_any_instance_of(described_class).to receive(:print_banner) { nil } }
it { is_expected.to include('/example.txt') }
end

Expand All @@ -203,7 +202,7 @@
let(:dst) { '/path/to/d.txt' }
subject { generator.send(:copy_with_path, data) }
before do
allow_any_instance_of(described_class).to receive(:initialize) { nil }
allow_any_instance_of(described_class).to receive(:print_banner) { nil }
allow(generator).to receive(:source_path).with('s.txt') { src }
allow(generator).to receive(:dest_path).with('d.txt') { dst }
allow(FileUtils).to receive(:mkdir_p).with('/path/to') { true }
Expand Down
4 changes: 2 additions & 2 deletions spec/unit/lib/capybara_helpers_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -681,8 +681,8 @@
describe '.load_driver_gem!' do
subject { load_driver_gem!(:webkit, 'capybara-webkit', 'capybara-webkit') }
context 'when possible to require' do
before { allow(self).to receive(:require).with(:webkit) { true } }
it { expect { subject }.not_to raise_error(LoadError) }
before { allow(self).to receive(:require).with('capybara-webkit') { true } }
it { expect { subject }.not_to raise_error }
end
context 'when impossible to require' do
it do
Expand Down
6 changes: 3 additions & 3 deletions spec/unit/lib/mail_adapters/mailgun_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,10 @@
allow(Howitzer::MailgunApi::Connector.instance.client).to receive(:get).with(
'mailgun@test.domain/events',
params: { event: 'stored' }
).ordered.once { events }
) { events }
allow(Howitzer::MailgunApi::Connector.instance.client).to receive(:get_url).with(
'https://si.api.mailgun.net/v3/domains/mg.strongqa.com/messages/1234567890'
).ordered.once { mailgun_message }
) { mailgun_message }
end
it do
expect(Howitzer::Email.adapter).to receive(:new).with(message).once
Expand All @@ -80,7 +80,7 @@
allow(Howitzer::MailgunApi::Connector.instance.client).to receive(:get).with(
'mailgun@test.domain/events',
params: { event: 'stored' }
).at_least(:twice).ordered { events }
) { events }
end
it do
expect { subject }.to raise_error(
Expand Down

0 comments on commit d0c3d26

Please sign in to comment.