summaryrefslogtreecommitdiff
path: root/qa/spec/factory/product_spec.rb
blob: f245aabbf43b6210f99bf7566386ff5fd8920f30 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
describe QA::Factory::Product do
  let(:factory) do
    QA::Factory::Base.new
  end

  let(:attributes) do
    { test: QA::Factory::Product::Attribute.new(:test, proc { 'returned' }) }
  end

  let(:product) { spy('product') }

  before do
    allow(QA::Factory::Base).to receive(:attributes).and_return(attributes)
  end

  describe '.populate!' do
    it 'returns a fabrication product and define factory attributes as its methods' do
      expect(described_class).to receive(:new).and_return(product)

      result = described_class.populate!(factory) do |instance|
        instance.something = 'string'
      end

      expect(result).to be product
      expect(result.test).to eq('returned')
    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')

      expect(subject.visit!).to eq 'visited some url'
    end
  end
end