Class: RSpec::Authorization::Adapters::ExampleGroup

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

Overview

Wrapper to generate RSpec::Core::ExampleGroup. The example group includes RSpec::Rails::ControllerExampleGroup to add behavior testing, which provides methods to test the controller, such as: get, post, patch, put and delete.

Consider the following example:

group = ExampleGroup.new(ArticlesController)
group.target # => RSpec::ExampleGroups::ArticlesController

Instantiating the class for a second time produce a different result:

group = ExampleGroup.new(ArticlesController)
group.target # => RSpec::ExampleGroups::ArticlesController_2

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(klass) ⇒ ExampleGroup

Initialize example group using controller’s class.

Parameters:

  • klass (Class)

    controller’s class for an example group



24
25
26
27
28
# File 'lib/rspec/authorization/adapters/example_group.rb', line 24

def initialize(klass)
  @target = RSpec::Core::ExampleGroup.describe(klass) do
    include RSpec::Rails::ControllerExampleGroup
  end
end

Instance Attribute Details

#targetClass (readonly)

Returns a class namespaced from RSPec::ExampleGroups.

Returns:

  • (Class)

    a class namespaced from RSPec::ExampleGroups



19
20
21
# File 'lib/rspec/authorization/adapters/example_group.rb', line 19

def target
  @target
end

Instance Method Details

#after(&block) ⇒ Array<RSpec::Core::Hooks::AfterHook>

Add instruction to be run after our example. Instructions added will be run inside the context of our example group, consider the following example:

after do
  get :index
end

The above statements behave exactly the same as RSpec after method, and this method serve as a proxy to RSpec after method call. That means everything that we can do inside after method will be available inside after to.

Returns:

  • (Array<RSpec::Core::Hooks::AfterHook>)

    an array of after hook filter



73
74
75
# File 'lib/rspec/authorization/adapters/example_group.rb', line 73

def after(&block)
  target.after(&block)
end

#before(&block) ⇒ Array<RSpec::Core::Hooks::BeforeHook>

Add instruction to be run before our example. Instructions added will be run inside the context of our example group, consider the following example:

before do
  get :index
end

The above statements behave exactly the same as RSpec before method, and this method serve as a proxy to RSpec before method call. That means everything that we can do inside before method will be available inside before to.

Returns:

  • (Array<RSpec::Core::Hooks::BeforeHook>)

    an array of before hook filter



55
56
57
# File 'lib/rspec/authorization/adapters/example_group.rb', line 55

def before(&block)
  target.before(&block)
end

#run_exampleExample

Run example for our example group. The example is actualy has no example at all, it is simply a wrapper for RSpec::Core::Example, running an actual example would produce unnecessary artifacts, while all we need is a simple wrapper on controller behavior.

Returns:

  • (Example)

    example object that has been run

See Also:



37
38
39
# File 'lib/rspec/authorization/adapters/example_group.rb', line 37

def run_example
  Example.new(target)
end