Class: RSpec::Authorization::Adapters::Example

Inherits:
Object
  • Object
show all
Defined in:
lib/rspec/authorization/adapters/example.rb

Overview

Wrapper to generate and immediately run example from RSpec::Core::Example. The purpose of this class is to abstract the running of an example without unnecessary artifacts from an RSpec example, such as: reporter, generated description, context and expectation.

The sole purpose of this class is to generate the minimum required component needed to create and run an example, for our matcher to run against. The trick to run the example without producing unnecessary artifacts is to trigger the example's before and after hook manually without running any expectations.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(group_target) ⇒ Example

Initialize example using RSpec example group. The RSpec example group can be retrieved using example group's target, consider the following example:

group   = ExampleGroup.new(ArticlesController)
example = Example.new(group.target)

26
27
28
29
30
31
32
33
# File 'lib/rspec/authorization/adapters/example.rb', line 26

def initialize(group_target)
  @group_target = group_target
  @target       = RSpec::Core::Example.new(group_target, "", {})

  set_example_group_instance
  run_before_example
  run_after_example
end

Instance Attribute Details

#group_targetClass (readonly)


14
15
16
# File 'lib/rspec/authorization/adapters/example.rb', line 14

def group_target
  @group_target
end

#targetRSpec::Core::Example (readonly)


16
17
18
# File 'lib/rspec/authorization/adapters/example.rb', line 16

def target
  @target
end