Sha256: 1567ac88822cde2b831eb12ea3d2304856f533a6fb0a8f7aee9d7d9503890c53

Contents?: true

Size: 1.07 KB

Versions: 6

Compression:

Stored size: 1.07 KB

Contents

# encoding: utf-8
# copyright: 2016, Chef Software Inc.
# author: Dominik Richter
# author: Christoph Hartmann

require 'rspec/expectations'

module Inspec
  class Expect
    attr_reader :calls, :value, :block
    def initialize(value, &block)
      @value = value
      @block = block
      @calls = []
    end

    def to(*args, &block)
      @calls.push([:to, args, block, caller])
    end

    def not_to(*args, &block)
      @calls.push([:not_to, args, block, caller])
    end

    def example_group
      that = self

      opts = { 'caller' => calls[0][3] }
      if !calls[0][3].nil? && !calls[0][3].empty? &&
         (m = calls[0][3][0].match(/^([^:]*):(\d+):/))
        opts['file_path'] = m[0]
        opts['line_number'] = m[1]
      end

      RSpec::Core::ExampleGroup.describe(that.value, opts) do
        that.calls.each do |method, args, block, clr|
          it(nil, caller: clr) do
            x = expect(that.value, &that.block).method(method)
            x.call(*args, &block)
          end
        end
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
inspec-2.1.81 lib/inspec/expect.rb
inspec-2.1.21 lib/inspec/expect.rb
inspec-2.1.10 lib/inspec/expect.rb
inspec-2.0.32 lib/inspec/expect.rb
inspec-2.0.17 lib/inspec/expect.rb
inspec-1.51.15 lib/inspec/expect.rb