summaryrefslogtreecommitdiff
path: root/spec/mspec/spec
diff options
context:
space:
mode:
Diffstat (limited to 'spec/mspec/spec')
-rw-r--r--spec/mspec/spec/commands/mspec_spec.rb6
-rw-r--r--spec/mspec/spec/expectations/should.rb1
-rw-r--r--spec/mspec/spec/fixtures/object_methods_spec.rb8
-rw-r--r--spec/mspec/spec/helpers/ruby_exe_spec.rb59
-rw-r--r--spec/mspec/spec/integration/object_methods_spec.rb18
-rw-r--r--spec/mspec/spec/matchers/output_to_fd_spec.rb24
-rw-r--r--spec/mspec/spec/mocks/mock_spec.rb6
-rw-r--r--spec/mspec/spec/runner/shared_spec.rb2
8 files changed, 63 insertions, 61 deletions
diff --git a/spec/mspec/spec/commands/mspec_spec.rb b/spec/mspec/spec/commands/mspec_spec.rb
index 5d2134a054..b01af6b41b 100644
--- a/spec/mspec/spec/commands/mspec_spec.rb
+++ b/spec/mspec/spec/commands/mspec_spec.rb
@@ -60,13 +60,13 @@ describe MSpecMain, "#run" do
end
it "uses exec to invoke the runner script" do
- @script.should_receive(:exec).with("ruby", "#{MSPEC_HOME}/bin/mspec-run")
+ @script.should_receive(:exec).with("ruby", "#{MSPEC_HOME}/bin/mspec-run", close_others: false)
@script.options []
@script.run
end
it "shows the command line on stderr" do
- @script.should_receive(:exec).with("ruby", "#{MSPEC_HOME}/bin/mspec-run")
+ @script.should_receive(:exec).with("ruby", "#{MSPEC_HOME}/bin/mspec-run", close_others: false)
@script.options []
@script.run
$stderr.to_s.should == "$ ruby #{Dir.pwd}/bin/mspec-run\n"
@@ -74,7 +74,7 @@ describe MSpecMain, "#run" do
it "adds config[:launch] to the exec options" do
@script.should_receive(:exec).with("ruby",
- "-Xlaunch.option", "#{MSPEC_HOME}/bin/mspec-run")
+ "-Xlaunch.option", "#{MSPEC_HOME}/bin/mspec-run", close_others: false)
@config[:launch] << "-Xlaunch.option"
@script.options []
@script.run
diff --git a/spec/mspec/spec/expectations/should.rb b/spec/mspec/spec/expectations/should.rb
index 8404ff044e..24b1cf2bf8 100644
--- a/spec/mspec/spec/expectations/should.rb
+++ b/spec/mspec/spec/expectations/should.rb
@@ -33,6 +33,7 @@ MSpec.register :finish, monitor
at_exit { MSpec.actions :finish }
MSpec.actions :start
+MSpec.setup_env
# Specs
describe "MSpec expectation method #should" do
diff --git a/spec/mspec/spec/fixtures/object_methods_spec.rb b/spec/mspec/spec/fixtures/object_methods_spec.rb
new file mode 100644
index 0000000000..9b7c1523e5
--- /dev/null
+++ b/spec/mspec/spec/fixtures/object_methods_spec.rb
@@ -0,0 +1,8 @@
+unless defined?(RSpec)
+ describe "Object" do
+ it ".public_instance_methods(false) is empty" do
+ Object.public_instance_methods(false).sort.should ==
+ [:should, :should_not, :should_not_receive, :should_receive, :stub!]
+ end
+ end
+end
diff --git a/spec/mspec/spec/helpers/ruby_exe_spec.rb b/spec/mspec/spec/helpers/ruby_exe_spec.rb
index 474ad7b51a..8036043578 100644
--- a/spec/mspec/spec/helpers/ruby_exe_spec.rb
+++ b/spec/mspec/spec/helpers/ruby_exe_spec.rb
@@ -11,24 +11,13 @@ class RubyExeSpecs
end
describe "#ruby_exe_options" do
- before :all do
- @verbose = $VERBOSE
- $VERBOSE = nil
-
- @ruby_engine = Object.const_get :RUBY_ENGINE
+ before :each do
@ruby_exe_env = ENV['RUBY_EXE']
-
@script = RubyExeSpecs.new
end
- after :all do
- Object.const_set :RUBY_ENGINE, @ruby_engine
+ after :each do
ENV['RUBY_EXE'] = @ruby_exe_env
- $VERBOSE = @verbose
- end
-
- before :each do
- @script = RubyExeSpecs.new
end
it "returns ENV['RUBY_EXE'] when passed :env" do
@@ -37,27 +26,27 @@ describe "#ruby_exe_options" do
end
it "returns 'bin/jruby' when passed :engine and RUBY_ENGINE is 'jruby'" do
- Object.const_set :RUBY_ENGINE, 'jruby'
+ stub_const "RUBY_ENGINE", 'jruby'
@script.ruby_exe_options(:engine).should == 'bin/jruby'
end
it "returns 'bin/rbx' when passed :engine, RUBY_ENGINE is 'rbx'" do
- Object.const_set :RUBY_ENGINE, 'rbx'
+ stub_const "RUBY_ENGINE", 'rbx'
@script.ruby_exe_options(:engine).should == 'bin/rbx'
end
it "returns 'ir' when passed :engine and RUBY_ENGINE is 'ironruby'" do
- Object.const_set :RUBY_ENGINE, 'ironruby'
+ stub_const "RUBY_ENGINE", 'ironruby'
@script.ruby_exe_options(:engine).should == 'ir'
end
it "returns 'maglev-ruby' when passed :engine and RUBY_ENGINE is 'maglev'" do
- Object.const_set :RUBY_ENGINE, 'maglev'
+ stub_const "RUBY_ENGINE", 'maglev'
@script.ruby_exe_options(:engine).should == 'maglev-ruby'
end
it "returns 'topaz' when passed :engine and RUBY_ENGINE is 'topaz'" do
- Object.const_set :RUBY_ENGINE, 'topaz'
+ stub_const "RUBY_ENGINE", 'topaz'
@script.ruby_exe_options(:engine).should == 'topaz'
end
@@ -75,21 +64,11 @@ describe "#ruby_exe_options" do
end
describe "#resolve_ruby_exe" do
- before :all do
- @verbose = $VERBOSE
- $VERBOSE = nil
-
- @name = "ruby_spec_exe"
- end
-
before :each do
+ @name = "ruby_spec_exe"
@script = RubyExeSpecs.new
end
- after :all do
- $VERBOSE = @verbose
- end
-
it "returns the value returned by #ruby_exe_options if it exists and is executable" do
@script.should_receive(:ruby_exe_options).and_return(@name)
File.should_receive(:file?).with(@name).and_return(true)
@@ -126,12 +105,8 @@ describe "#resolve_ruby_exe" do
end
describe Object, "#ruby_cmd" do
- before :all do
- @verbose = $VERBOSE
- $VERBOSE = nil
-
- @ruby_exe = Object.const_get :RUBY_EXE
- Object.const_set :RUBY_EXE, 'ruby_spec_exe -w -Q'
+ before :each do
+ stub_const 'RUBY_EXE', 'ruby_spec_exe -w -Q'
@file = "some/ruby/file.rb"
@code = %(some "real" 'ruby' code)
@@ -139,11 +114,6 @@ describe Object, "#ruby_cmd" do
@script = RubyExeSpecs.new
end
- after :all do
- Object.const_set :RUBY_EXE, @ruby_exe
- $VERBOSE = @verbose
- end
-
it "returns a command that runs the given file if it is a file that exists" do
File.should_receive(:exist?).with(@file).and_return(true)
@script.ruby_cmd(@file).should == "ruby_spec_exe -w -Q some/ruby/file.rb"
@@ -168,12 +138,15 @@ describe Object, "#ruby_cmd" do
end
describe Object, "#ruby_exe" do
- before :all do
+ before :each do
+ stub_const 'RUBY_EXE', 'ruby_spec_exe -w -Q'
+
@script = RubyExeSpecs.new
+ @script.stub(:`)
end
- before :each do
- @script.stub(:`)
+ it "returns an Array containing the interpreter executable and flags when given no arguments" do
+ @script.ruby_exe.should == ['ruby_spec_exe', '-w', '-Q']
end
it "executes (using `) the result of calling #ruby_cmd with the given arguments" do
diff --git a/spec/mspec/spec/integration/object_methods_spec.rb b/spec/mspec/spec/integration/object_methods_spec.rb
new file mode 100644
index 0000000000..3be704beb6
--- /dev/null
+++ b/spec/mspec/spec/integration/object_methods_spec.rb
@@ -0,0 +1,18 @@
+require 'spec_helper'
+
+expected_output = <<EOS
+RUBY_DESCRIPTION
+.
+
+Finished in D.DDDDDD seconds
+
+1 file, 1 example, 1 expectation, 0 failures, 0 errors, 0 tagged
+EOS
+
+describe "MSpec" do
+ it "does not define public methods on Object" do
+ out, ret = run_mspec("run", "spec/fixtures/object_methods_spec.rb")
+ out.should == expected_output
+ ret.success?.should == true
+ end
+end
diff --git a/spec/mspec/spec/matchers/output_to_fd_spec.rb b/spec/mspec/spec/matchers/output_to_fd_spec.rb
index d35da58829..e584c4e003 100644
--- a/spec/mspec/spec/matchers/output_to_fd_spec.rb
+++ b/spec/mspec/spec/matchers/output_to_fd_spec.rb
@@ -5,38 +5,40 @@ require 'mspec/matchers'
describe OutputToFDMatcher do
# Figure out how in the hell to achieve this
it "matches when running the block produces the expected output to the given FD" do
- output_to_fd("Hi\n", STDERR).matches?(lambda { $stderr.print "Hi\n" }).should == true
+ OutputToFDMatcher.new("Hi\n", STDERR).matches?(lambda { $stderr.print "Hi\n" }).should == true
end
it "does not match if running the block does not produce the expected output to the FD" do
- output_to_fd("Hi\n", STDERR).matches?(lambda { $stderr.puts("Hello\n") }).should == false
+ OutputToFDMatcher.new("Hi\n", STDERR).matches?(lambda { $stderr.puts("Hello\n") }).should == false
end
it "propagate the exception if one is thrown while matching" do
exc = RuntimeError.new("propagates")
lambda {
- output_to_fd("Hi\n", STDERR).matches?(lambda {
+ OutputToFDMatcher.new("Hi\n", STDERR).matches?(lambda {
raise exc
}).should == false
}.should raise_error(exc)
end
it "defaults to matching against STDOUT" do
- output_to_fd("Hi\n").matches?(lambda { $stdout.print "Hi\n" }).should == true
+ object = Object.new
+ object.extend MSpecMatchers
+ object.send(:output_to_fd, "Hi\n").matches?(lambda { $stdout.print "Hi\n" }).should == true
end
it "accepts any IO instance" do
io = IO.new STDOUT.fileno
- output_to_fd("Hi\n", io).matches?(lambda { io.print "Hi\n" }).should == true
+ OutputToFDMatcher.new("Hi\n", io).matches?(lambda { io.print "Hi\n" }).should == true
end
it "allows matching with a Regexp" do
s = "Hi there\n"
- output_to_fd(/Hi/, STDERR).matches?(lambda { $stderr.print s }).should == true
- output_to_fd(/Hi?/, STDERR).matches?(lambda { $stderr.print s }).should == true
- output_to_fd(/[hH]i?/, STDERR).matches?(lambda { $stderr.print s }).should == true
- output_to_fd(/.*/, STDERR).matches?(lambda { $stderr.print s }).should == true
- output_to_fd(/H.*?here/, STDERR).matches?(lambda { $stderr.print s }).should == true
- output_to_fd(/Ahoy/, STDERR).matches?(lambda { $stderr.print s }).should == false
+ OutputToFDMatcher.new(/Hi/, STDERR).matches?(lambda { $stderr.print s }).should == true
+ OutputToFDMatcher.new(/Hi?/, STDERR).matches?(lambda { $stderr.print s }).should == true
+ OutputToFDMatcher.new(/[hH]i?/, STDERR).matches?(lambda { $stderr.print s }).should == true
+ OutputToFDMatcher.new(/.*/, STDERR).matches?(lambda { $stderr.print s }).should == true
+ OutputToFDMatcher.new(/H.*?here/, STDERR).matches?(lambda { $stderr.print s }).should == true
+ OutputToFDMatcher.new(/Ahoy/, STDERR).matches?(lambda { $stderr.print s }).should == false
end
end
diff --git a/spec/mspec/spec/mocks/mock_spec.rb b/spec/mspec/spec/mocks/mock_spec.rb
index 1a7fb2d567..d996b5285c 100644
--- a/spec/mspec/spec/mocks/mock_spec.rb
+++ b/spec/mspec/spec/mocks/mock_spec.rb
@@ -22,16 +22,14 @@ end
describe Mock, ".replaced_name" do
it "returns the name for a method that is being replaced by a mock method" do
m = double('a fake id')
- m.stub(:__mspec_object_id__).and_return(42)
- Mock.replaced_name(m, :method_call).should == :__mspec_42_method_call__
+ Mock.replaced_name(m, :method_call).should == :"__mspec_#{m.object_id}_method_call__"
end
end
describe Mock, ".replaced_key" do
it "returns a key used internally by Mock" do
m = double('a fake id')
- m.stub(:__mspec_object_id__).and_return(42)
- Mock.replaced_key(m, :method_call).should == [:__mspec_42_method_call__, :method_call]
+ Mock.replaced_key(m, :method_call).should == [:"__mspec_#{m.object_id}_method_call__", :method_call]
end
end
diff --git a/spec/mspec/spec/runner/shared_spec.rb b/spec/mspec/spec/runner/shared_spec.rb
index 791588fdca..b91800b7db 100644
--- a/spec/mspec/spec/runner/shared_spec.rb
+++ b/spec/mspec/spec/runner/shared_spec.rb
@@ -11,6 +11,7 @@ describe Object, "#it_behaves_like" do
@state = ContextState.new "Top level"
@state.instance_variable_set :@parsed, true
+ @state.singleton_class.send(:public, :it_behaves_like)
@shared = ContextState.new :shared_spec, :shared => true
MSpec.stub(:retrieve_shared).and_return(@shared)
@@ -51,6 +52,7 @@ describe Object, "#it_behaves_like" do
@state2 = ContextState.new "Second top level"
@state2.instance_variable_set :@parsed, true
+ @state2.singleton_class.send(:public, :it_behaves_like)
end
it "ensures the shared spec state is distinct" do