HEX
Server: Apache
System: Linux s198.coreserver.jp 5.15.0-151-generic #161-Ubuntu SMP Tue Jul 22 14:25:40 UTC 2025 x86_64
User: nagasaki (10062)
PHP: 7.1.33
Disabled: NONE
Upload Files
File: //usr/local/rvm/src/ruby-2.5.9/spec/mspec/spec/matchers/have_class_variable_spec.rb
require 'spec_helper'
require 'mspec/expectations/expectations'
require 'mspec/matchers'

class IVarModMock
  def self.class_variables
    [:@foo]
  end
end

describe HaveClassVariableMatcher, "on RUBY_VERSION >= 1.9" do
  it "matches when mod has the class variable, given as string" do
    matcher = HaveClassVariableMatcher.new('@foo')
    matcher.matches?(IVarModMock).should be_true
  end

  it "matches when mod has the class variable, given as symbol" do
    matcher = HaveClassVariableMatcher.new(:@foo)
    matcher.matches?(IVarModMock).should be_true
  end

  it "does not match when mod hasn't got the class variable, given as string" do
    matcher = HaveClassVariableMatcher.new('@bar')
    matcher.matches?(IVarModMock).should be_false
  end

  it "does not match when mod hasn't got the class variable, given as symbol" do
    matcher = HaveClassVariableMatcher.new(:@bar)
    matcher.matches?(IVarModMock).should be_false
  end

  it "provides a failure message for #should" do
    matcher = HaveClassVariableMatcher.new(:@bar)
    matcher.matches?(IVarModMock)
    matcher.failure_message.should == [
      "Expected IVarModMock to have class variable '@bar'",
      "but it does not"
    ]
  end

  it "provides a failure messoge for #should_not" do
    matcher = HaveClassVariableMatcher.new(:@bar)
    matcher.matches?(IVarModMock)
    matcher.negative_failure_message.should == [
      "Expected IVarModMock NOT to have class variable '@bar'",
      "but it does"
    ]
  end
end