2017-12-21 04:38:06 -05:00
|
|
|
describe QA::Factory::Product do
|
2018-01-26 14:25:01 -05:00
|
|
|
let(:factory) do
|
|
|
|
QA::Factory::Base.new
|
|
|
|
end
|
|
|
|
|
|
|
|
let(:attributes) do
|
|
|
|
{ test: QA::Factory::Product::Attribute.new(:test, proc { 'returned' }) }
|
|
|
|
end
|
|
|
|
|
2017-12-21 04:38:06 -05:00
|
|
|
let(:product) { spy('product') }
|
|
|
|
|
2018-01-26 14:25:01 -05:00
|
|
|
before do
|
|
|
|
allow(QA::Factory::Base).to receive(:attributes).and_return(attributes)
|
|
|
|
end
|
|
|
|
|
2017-12-21 04:38:06 -05:00
|
|
|
describe '.populate!' do
|
2018-01-26 14:25:01 -05:00
|
|
|
it 'returns a fabrication product and define factory attributes as its methods' do
|
2018-01-11 06:00:22 -05:00
|
|
|
expect(described_class).to receive(:new).and_return(product)
|
2017-12-21 04:38:06 -05:00
|
|
|
|
|
|
|
result = described_class.populate!(factory) do |instance|
|
|
|
|
instance.something = 'string'
|
|
|
|
end
|
|
|
|
|
|
|
|
expect(result).to be product
|
2018-01-26 14:25:01 -05:00
|
|
|
expect(result.test).to eq('returned')
|
2017-12-21 04:38:06 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '.visit!' do
|
|
|
|
it 'makes it possible to visit fabrication product' do
|
|
|
|
allow_any_instance_of(described_class)
|
|
|
|
.to receive(:current_url).and_return('some url')
|
|
|
|
allow_any_instance_of(described_class)
|
|
|
|
.to receive(:visit).and_return('visited some url')
|
|
|
|
|
2018-01-11 06:00:22 -05:00
|
|
|
expect(subject.visit!).to eq 'visited some url'
|
2017-12-21 04:38:06 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|