From 95e8c48dd3348503a8c7db5d0498894a1b676395 Mon Sep 17 00:00:00 2001 From: eregon Date: Sun, 7 May 2017 12:04:49 +0000 Subject: Add in-tree mspec and ruby/spec * For easier modifications of ruby/spec by MRI developers. * .gitignore: track changes under spec. * spec/mspec, spec/rubyspec: add in-tree mspec and ruby/spec. These files can therefore be updated like any other file in MRI. Instructions are provided in spec/README. [Feature #13156] [ruby-core:79246] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58595 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- .../spec/matchers/have_class_variable_spec.rb | 62 ++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 spec/mspec/spec/matchers/have_class_variable_spec.rb (limited to 'spec/mspec/spec/matchers/have_class_variable_spec.rb') diff --git a/spec/mspec/spec/matchers/have_class_variable_spec.rb b/spec/mspec/spec/matchers/have_class_variable_spec.rb new file mode 100644 index 0000000000..e440050056 --- /dev/null +++ b/spec/mspec/spec/matchers/have_class_variable_spec.rb @@ -0,0 +1,62 @@ +require 'spec_helper' +require 'mspec/expectations/expectations' +require 'mspec/matchers' + +class IVarModMock; end + +shared_examples_for "have_class_variable, on all Ruby versions" do + after :all do + Object.const_set :RUBY_VERSION, @ruby_version + end + + 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 + +describe HaveClassVariableMatcher, "on RUBY_VERSION >= 1.9" do + before :all do + @ruby_version = Object.const_get :RUBY_VERSION + Object.const_set :RUBY_VERSION, '1.9.0' + + def IVarModMock.class_variables + [:@foo] + end + end + + it_should_behave_like "have_class_variable, on all Ruby versions" +end -- cgit v1.2.3