Sha256: 46d628331983efc5825ee54b20e720754eade6d0a10a82524e57eb3dd06516fb

Contents?: true

Size: 1022 Bytes

Versions: 109

Compression:

Stored size: 1022 Bytes

Contents

# copyright: 2016, Chef Software Inc.

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] } # TODO: this needs overhaul. no magic #s
      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

109 entries across 109 versions & 2 rubygems

Version Path
inspec-core-4.29.3 lib/inspec/expect.rb
inspec-core-4.28.0 lib/inspec/expect.rb
inspec-core-4.26.13 lib/inspec/expect.rb
inspec-core-4.26.4 lib/inspec/expect.rb
inspec-core-4.25.1 lib/inspec/expect.rb
inspec-core-4.24.32 lib/inspec/expect.rb
inspec-core-4.24.28 lib/inspec/expect.rb
inspec-core-4.24.26 lib/inspec/expect.rb
inspec-core-4.24.8 lib/inspec/expect.rb
inspec-core-4.23.15 lib/inspec/expect.rb
inspec-core-4.23.11 lib/inspec/expect.rb
inspec-core-4.23.10 lib/inspec/expect.rb
inspec-core-4.23.4 lib/inspec/expect.rb
inspec-core-4.22.22 lib/inspec/expect.rb
inspec-core-4.22.8 lib/inspec/expect.rb
inspec-core-4.22.1 lib/inspec/expect.rb
inspec-core-4.22.0 lib/inspec/expect.rb
inspec-core-4.21.3 lib/inspec/expect.rb
inspec-core-4.21.1 lib/inspec/expect.rb
inspec-core-4.20.10 lib/inspec/expect.rb