summaryrefslogtreecommitdiff
path: root/qa/qa/factory/product.rb
blob: d892359894ff7e8e2c1374d6d34edde46e561ed3 (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
require 'capybara/dsl'

module QA
  module Factory
    class Product
      include Capybara::DSL

      Attribute = Struct.new(:name, :block)

      def initialize
        @location = current_url
      end

      def visit!
        visit @location
      end

      def self.populate!(factory)
        new.tap do |product|
          factory.class.attributes.each_value do |attribute|
            product.instance_exec(factory, attribute.block) do |factory, block|
              product.define_singleton_method(attribute.name) { block.call(factory) }
            end
          end
        end
      end
    end
  end
end