Sha256: 3f2f26d18528354e154fdfc5ab3b3e80f7c24e38eb7f018a89bd627001e6f778

Contents?: true

Size: 1009 Bytes

Versions: 1

Compression:

Stored size: 1009 Bytes

Contents

require 'rspec'
require 'mocha/api'

Dir.glob("lib/**/*.rb").each do |file|
  require_relative "../#{file}"
end

RSpec::Matchers.define :have_instance_variable do |instance_variable|
  chain :with do |value|
    @value = value
  end

  match do |object|
    @error = :presence if !object.instance_variables.include?(:"@#{instance_variable}") 
    @error = :equality if (object.instance_variable_get("@#{instance_variable}") != @value) && !@value.nil?

    @error.nil?
  end

  failure_message do |object|
    if @error == :presence
      "#{object} should have @#{instance_variable} instance variable"
    else
      "Instance variable @#{instance_variable} of #{object.class} should be #{@value.inspect} not #{object.inspect}"
    end
  end

  description do
    if @value.nil?
      "have instance variable @#{instance_variable}"
    else
      "have instance variable @#{instance_variable} with #{@value.inspect}"
    end
  end
end

RSpec.configure do |config|
  config.formatter     = 'documentation'
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
memcached-manager-1.0.0 spec/spec_helper.rb