Class: SharedContextBuilder

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/acceptance_test/shared_context_builder.rb

Instance Method Summary collapse

Instance Method Details

#build(name, acceptance_test) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/acceptance_test/shared_context_builder.rb', line 6

def build name, acceptance_test
  throw "rspec library is not available" unless defined? RSpec

  parent = self

  acceptance_test_lambda = lambda do
    parent.configure_rspec acceptance_test, self
  end

  RSpec.shared_context name do
    self.define_singleton_method(:include_context, acceptance_test_lambda)

    include_context
  end
end

#configure_rspec(acceptance_test, object = nil) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/acceptance_test/shared_context_builder.rb', line 22

def configure_rspec acceptance_test, object=nil
  # acceptance_test = self

  # if object
  #   if object.kind_of? RSpec::Core::Example
  #     rspec_conf = object.example_group.parent_groups.last
  #   else
  #     rspec_conf = object
  #   end
  # else
  #   rspec_conf = RSpec.configuration
  # end

  rspec_conf = object

  rspec_conf.around(:each) do |example|
    old_driver = Capybara.current_driver

    acceptance_test.setup(page, example.)

    new_driver = Capybara.current_driver

    if old_driver != new_driver
      example..delete(old_driver)
      example.[new_driver] = true
    end

    example.run

    acceptance_test.teardown(page, example., example.exception)
  end
end