product.rb 594 Bytes
Newer Older
1 2 3 4 5 6 7
require 'capybara/dsl'

module QA
  module Factory
    class Product
      include Capybara::DSL

8
      attr_reader :factory
9

10
      def initialize(factory)
11 12
        @factory = factory

13
        define_attributes
14 15 16
      end

      def visit!
17 18 19
        visit(web_url)
      end

20 21
      def populate(*attributes)
        attributes.each(&method(:public_send))
22 23
      end

24 25
      private

26 27 28 29
      def define_attributes
        factory.class.attributes_names.each do |name|
          define_singleton_method(name) do
            factory.public_send(name)
30 31
          end
        end
32 33 34 35
      end
    end
  end
end