Class: Inspec::RunnerRspec

Inherits:
Object
  • Object
show all
Defined in:
lib/inspec/runner_rspec.rb

Instance Method Summary collapse

Constructor Details

#initialize(conf) ⇒ RunnerRspec

Returns a new instance of RunnerRspec.



15
16
17
18
19
# File 'lib/inspec/runner_rspec.rb', line 15

def initialize(conf)
  @conf = conf
  @formatter = nil
  reset
end

Instance Method Details

#add_profile(profile) ⇒ nil

Add a full profile to the runner. Only pulls in metadata

Parameters:

Returns:

  • (nil)


34
35
36
37
38
39
40
# File 'lib/inspec/runner_rspec.rb', line 34

def add_profile(profile)
  RSpec.configuration.formatters
       .find_all { |c| c.is_a? InspecRspecJson }
       .each do |fmt|
    fmt.add_profile(profile)
  end
end

#add_test(example, rule) ⇒ nil

Add an example group to the list of registered tests.

Parameters:

  • example (RSpecExampleGroup)

    test

  • rule_id (String)

    the ID associated with this check

Returns:

  • (nil)


59
60
61
62
# File 'lib/inspec/runner_rspec.rb', line 59

def add_test(example, rule)
  set_rspec_ids(example, rule)
  @tests.example_groups.push(example)
end

#backend=(backend) ⇒ nil

Configure the backend of the runner.

Parameters:

Returns:

  • (nil)


46
47
48
49
50
51
52
# File 'lib/inspec/runner_rspec.rb', line 46

def backend=(backend)
  RSpec.configuration.formatters
       .find_all { |c| c.is_a? InspecRspecJson }
       .each do |fmt|
    fmt.backend = backend
  end
end

#example_group(*args, &block) ⇒ RSpecExampleGroup

Create a new RSpec example group from arguments and block.

Parameters:

  • *args (Type)

    list of arguments for this example

  • &block (Type)

    the block associated with this example group

Returns:

  • (RSpecExampleGroup)


26
27
28
# File 'lib/inspec/runner_rspec.rb', line 26

def example_group(*args, &block)
  RSpec::Core::ExampleGroup.describe(*args, &block)
end

#reportHash

Provide an output hash of the run’s report

Returns:

  • (Hash)

    a run’s output hash



83
84
85
86
87
# File 'lib/inspec/runner_rspec.rb', line 83

def report
  reporter = @formatter || RSpec.configuration.formatters[0]
  return nil if reporter.nil? || !reporter.respond_to?(:output_hash)
  reporter.output_hash
end

#resetnil

Empty the list of registered tests.

Returns:

  • (nil)


92
93
94
95
96
97
# File 'lib/inspec/runner_rspec.rb', line 92

def reset
  @tests = RSpec::Core::World.new
  # resets "pending examples" in reporter
  RSpec.configuration.reset
  configure_output
end

#run(with = nil) ⇒ int

Run all registered tests with an optional test runner.

Parameters:

  • with (RSpecRunner) (defaults to: nil)

    is an optional RSpecRunner

Returns:

  • (int)

    0 if all went well; otherwise nonzero



75
76
77
78
# File 'lib/inspec/runner_rspec.rb', line 75

def run(with = nil)
  with ||= RSpec::Core::Runner.new(nil)
  with.run_specs(tests)
end

#testsArray

Retrieve the list of tests that have been added.

Returns:

  • (Array)

    full list of tests



67
68
69
# File 'lib/inspec/runner_rspec.rb', line 67

def tests
  @tests.ordered_example_groups
end