Make it possible to define QA factory product attributes
This commit is contained in:
parent
1011ca4949
commit
d32a151714
|
@ -6,6 +6,7 @@ module QA
|
||||||
extend SingleForwardable
|
extend SingleForwardable
|
||||||
|
|
||||||
def_delegators :evaluator, :dependency, :dependencies
|
def_delegators :evaluator, :dependency, :dependencies
|
||||||
|
def_delegators :evaluator, :product, :attributes
|
||||||
|
|
||||||
def fabricate!(*_args)
|
def fabricate!(*_args)
|
||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
|
@ -28,11 +29,12 @@ module QA
|
||||||
end
|
end
|
||||||
|
|
||||||
class DSL
|
class DSL
|
||||||
attr_reader :dependencies
|
attr_reader :dependencies, :attributes
|
||||||
|
|
||||||
def initialize(base)
|
def initialize(base)
|
||||||
@base = base
|
@base = base
|
||||||
@dependencies = {}
|
@dependencies = {}
|
||||||
|
@attributes = {}
|
||||||
end
|
end
|
||||||
|
|
||||||
def dependency(factory, as:, &block)
|
def dependency(factory, as:, &block)
|
||||||
|
@ -40,10 +42,16 @@ module QA
|
||||||
@base.class_eval { attr_accessor name }
|
@base.class_eval { attr_accessor name }
|
||||||
|
|
||||||
Dependency::Signature.new(factory, block).tap do |signature|
|
Dependency::Signature.new(factory, block).tap do |signature|
|
||||||
dependencies.store(name, signature)
|
@dependencies.store(name, signature)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def product(attribute, &block)
|
||||||
|
Product::Attribute.new(attribute, block).tap do |signature|
|
||||||
|
@attributes.store(attribute, signature)
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -5,6 +5,8 @@ module QA
|
||||||
class Product
|
class Product
|
||||||
include Capybara::DSL
|
include Capybara::DSL
|
||||||
|
|
||||||
|
Attribute = Struct.new(:name, :block)
|
||||||
|
|
||||||
def initialize(factory)
|
def initialize(factory)
|
||||||
@factory = factory
|
@factory = factory
|
||||||
@location = current_url
|
@location = current_url
|
||||||
|
|
|
@ -59,30 +59,44 @@ describe QA::Factory::Base do
|
||||||
it 'defines dependency accessors' do
|
it 'defines dependency accessors' do
|
||||||
expect(subject.new).to respond_to :mydep, :mydep=
|
expect(subject.new).to respond_to :mydep, :mydep=
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe 'dependencies fabrication' do
|
||||||
|
let(:dependency) { double('dependency') }
|
||||||
|
let(:instance) { spy('instance') }
|
||||||
|
|
||||||
|
subject do
|
||||||
|
Class.new(described_class) do
|
||||||
|
dependency Some::MyDependency, as: :mydep
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
before do
|
||||||
|
stub_const('Some::MyDependency', dependency)
|
||||||
|
|
||||||
|
allow(subject).to receive(:new).and_return(instance)
|
||||||
|
allow(instance).to receive(:mydep).and_return(nil)
|
||||||
|
allow(QA::Factory::Product).to receive(:new)
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'builds all dependencies first' do
|
||||||
|
expect(dependency).to receive(:fabricate!).once
|
||||||
|
|
||||||
|
subject.fabricate!
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe 'building dependencies' do
|
describe '.product' do
|
||||||
let(:dependency) { double('dependency') }
|
|
||||||
let(:instance) { spy('instance') }
|
|
||||||
|
|
||||||
subject do
|
subject do
|
||||||
Class.new(described_class) do
|
Class.new(described_class) do
|
||||||
dependency Some::MyDependency, as: :mydep
|
product :token do |factory, page|
|
||||||
|
page.do_something!
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
before do
|
it 'appends new product attribute' do
|
||||||
stub_const('Some::MyDependency', dependency)
|
expect(subject.attributes).to be_one
|
||||||
|
|
||||||
allow(subject).to receive(:new).and_return(instance)
|
|
||||||
allow(instance).to receive(:mydep).and_return(nil)
|
|
||||||
allow(QA::Factory::Product).to receive(:new)
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'builds all dependencies first' do
|
|
||||||
expect(dependency).to receive(:fabricate!).once
|
|
||||||
|
|
||||||
subject.fabricate!
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue