Skip to content

Commit

Permalink
update mspec to 8a0be99b4844a9f6dfc1eef7092901e6045e5222
Browse files Browse the repository at this point in the history
  • Loading branch information
Watson1978 committed Apr 3, 2012
1 parent 1070a0d commit ca1401b
Show file tree
Hide file tree
Showing 15 changed files with 74 additions and 38 deletions.
3 changes: 3 additions & 0 deletions mspec/Gemfile
Expand Up @@ -2,3 +2,6 @@ source 'https://rubygems.org'

# Specify your gem's dependencies in mspec.gemspec
gemspec

gem 'ruby-debug', :platform => :ruby_18
gem 'ruby-debug19', :platform => :ruby_19, :require => 'ruby-debug'
9 changes: 9 additions & 0 deletions mspec/lib/mspec/helpers/environment.rb
Expand Up @@ -37,4 +37,13 @@ def dev_null
"/dev/null"
end
end

def hostname
commands = ['hostname', 'uname -n']
commands.each do |command|
name = `#{command}`
return name.strip if $?.success?
end
raise Exception, "hostname: unable to find a working command"
end
end
4 changes: 2 additions & 2 deletions mspec/lib/mspec/helpers/ruby_exe.rb
Expand Up @@ -102,13 +102,13 @@ def ruby_exe_options(option)
def resolve_ruby_exe
[:env, :engine, :name, :install_name].each do |option|
next unless cmd = ruby_exe_options(option)
exe = cmd.split.first
exe, *rest = cmd.split(" ")

# It has been reported that File.executable is not reliable
# on Windows platforms (see commit 56bc555c). So, we check the
# platform.
if File.exists?(exe) and (PlatformGuard.windows? or File.executable?(exe))
return cmd
return [File.expand_path(exe), *rest].join(" ")
end
end
nil
Expand Down
3 changes: 2 additions & 1 deletion mspec/lib/mspec/helpers/tmp.rb
Expand Up @@ -15,7 +15,8 @@
-----------------------------------------------------
The rubyspec temp directory is not empty. Ensure that
all specs are cleaning up temporary files.
all specs are cleaning up temporary files:
#{SPEC_TEMP_DIR}
-----------------------------------------------------
EOM
Expand Down
5 changes: 3 additions & 2 deletions mspec/lib/mspec/matchers/be_computed_by.rb
Expand Up @@ -10,7 +10,8 @@ def matches?(array)
@value = line.pop
@arguments = line
@arguments += @args
return false unless @receiver.send(@method, *@arguments) == @value
@actual = @receiver.send(@method, *@arguments)
return false unless @actual == @value
end

return true
Expand All @@ -25,7 +26,7 @@ def method_call
end

def failure_message
["Expected #{@value.inspect}", "to be computed by #{method_call}"]
["Expected #{@value.inspect}", "to be computed by #{method_call} (computed #{@actual.inspect} instead)"]
end
end

Expand Down
3 changes: 2 additions & 1 deletion mspec/lib/mspec/matchers/be_valid_dns_name.rb
@@ -1,7 +1,8 @@
class BeValidDNSName
# http://stackoverflow.com/questions/106179/regular-expression-to-match-hostname-or-ip-address
# ftp://ftp.rfc-editor.org/in-notes/rfc3696.txt
VALID_DNS = /^(([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\-]*[a-zA-Z0-9])\.)*([A-Za-z]|[A-Za-z][A-Za-z0-9\-]*[A-Za-z0-9])\.?$/
# http://domainkeys.sourceforge.net/underscore.html
VALID_DNS = /^(([a-zA-Z0-9_]|[a-zA-Z0-9_][a-zA-Z0-9\-_]*[a-zA-Z0-9_])\.)*([A-Za-z_]|[A-Za-z_][A-Za-z0-9\-_]*[A-Za-z0-9_])\.?$/

def matches?(actual)
@actual = actual
Expand Down
4 changes: 2 additions & 2 deletions mspec/lib/mspec/matchers/match_yaml.rb
Expand Up @@ -10,7 +10,7 @@ def initialize(expected)

def matches?(actual)
@actual = actual
clean_yaml(@actual) == @expected
clean_yaml(@actual) == clean_yaml(@expected)
end

def failure_message
Expand All @@ -24,7 +24,7 @@ def negative_failure_message
protected

def clean_yaml(yaml)
yaml.gsub(/([^-])\s+\n/, "\\1\n")
yaml.gsub(/([^-]|^---)\s+\n/, "\\1\n")
end

def valid_yaml?(obj)
Expand Down
1 change: 0 additions & 1 deletion mspec/mspec.gemspec
Expand Up @@ -34,5 +34,4 @@ Gem::Specification.new do |gem|

gem.add_development_dependency "rake", "~> 0.9"
gem.add_development_dependency "rspec", "~> 2.8"
gem.add_development_dependency "ruby-debug", "~> 0.10"
end
4 changes: 2 additions & 2 deletions mspec/spec/helpers/datetime_spec.rb
Expand Up @@ -38,7 +38,7 @@
end

it "returns a DateTime instance with the specified offset value" do
d = new_datetime :offset => 3
d.offset.should == 3
d = new_datetime :offset => Rational(3,24)
d.offset.should == Rational(3,24)
end
end
18 changes: 18 additions & 0 deletions mspec/spec/helpers/ruby_exe_spec.rb
Expand Up @@ -105,6 +105,7 @@ class RubyExeSpecs
@script.should_receive(:ruby_exe_options).and_return(@name)
File.should_receive(:exists?).with(@name).and_return(true)
File.should_receive(:executable?).with(@name).and_return(true)
File.should_receive(:expand_path).with(@name).and_return(@name)
@script.resolve_ruby_exe.should == @name
end

Expand All @@ -113,9 +114,19 @@ class RubyExeSpecs
@script.should_receive(:ruby_exe_options).and_return(@name)
File.should_receive(:exists?).with(@name).and_return(true)
File.should_not_receive(:executable?)
File.should_receive(:expand_path).with(@name).and_return(@name)
@script.resolve_ruby_exe.should == @name
end

it "expands the path portion of the result of #ruby_exe_options" do
PlatformGuard.stub!(:windows?).and_return(false)
@script.should_receive(:ruby_exe_options).and_return("#{@name} -Xfoo")
File.should_receive(:exists?).with(@name).and_return(true)
File.should_receive(:executable?).with(@name).and_return(true)
File.should_receive(:expand_path).with(@name).and_return("/usr/bin/#{@name}")
@script.resolve_ruby_exe.should == "/usr/bin/#{@name} -Xfoo"
end

it "returns nil if no exe is found" do
File.should_receive(:exists?).at_least(:once).and_return(false)
@script.resolve_ruby_exe.should be_nil
Expand Down Expand Up @@ -177,6 +188,13 @@ class RubyExeSpecs
@script.ruby_exe nil, :options => "-c", :args => "> file.txt"
end

describe "with :dir option" do
it "executes the command in the given working directory" do
Dir.should_receive(:chdir).with("tmp")
@script.ruby_exe nil, :dir => "tmp"
end
end

describe "with :env option" do
before :each do
@script.stub!(:`)
Expand Down
2 changes: 1 addition & 1 deletion mspec/spec/matchers/be_computed_by_spec.rb
Expand Up @@ -37,6 +37,6 @@
[91, "Z" ] ]
matcher = BeComputedByMatcher.new(:chr)
matcher.matches?(array)
matcher.failure_message.should == ["Expected \"Z\"", "to be computed by 91.chr"]
matcher.failure_message.should == ["Expected \"Z\"", "to be computed by 91.chr (computed \"[\" instead)"]
end
end
7 changes: 6 additions & 1 deletion mspec/spec/matchers/raise_error_spec.rb
Expand Up @@ -34,7 +34,12 @@ class UnexpectedException < Exception; end
end

it "does not match when the proc raises the expected exception with an unexpected message" do
proc = Proc.new { raise UnexpectedException, "unexpected" }
proc = Proc.new { raise ExpectedException, "unexpected" }
RaiseErrorMatcher.new(ExpectedException, "expected").matches?(proc).should == false
end

it "does not match when the proc does not raise an exception" do
proc = Proc.new {}
RaiseErrorMatcher.new(ExpectedException, "expected").matches?(proc).should == false
end

Expand Down
46 changes: 23 additions & 23 deletions mspec/spec/runner/context_spec.rb
Expand Up @@ -9,7 +9,7 @@
describe ContextState, "#describe" do
before :each do
@state = ContextState.new "C#m"
@proc = lambda { ScratchPad.record :a }
@proc = lambda {|*| ScratchPad.record :a }
ScratchPad.clear
end

Expand Down Expand Up @@ -90,7 +90,7 @@
describe ContextState, "#it" do
before :each do
@state = ContextState.new ""
@proc = lambda { }
@proc = lambda {|*| }

@ex = ExampleState.new("", "", &@proc)
end
Expand Down Expand Up @@ -129,7 +129,7 @@
describe ContextState, "#before" do
before :each do
@state = ContextState.new ""
@proc = lambda { }
@proc = lambda {|*| }
end

it "records the block for :each" do
Expand All @@ -146,7 +146,7 @@
describe ContextState, "#after" do
before :each do
@state = ContextState.new ""
@proc = lambda { }
@proc = lambda {|*| }
end

it "records the block for :each" do
Expand All @@ -162,9 +162,9 @@

describe ContextState, "#pre" do
before :each do
@a = lambda { }
@b = lambda { }
@c = lambda { }
@a = lambda {|*| }
@b = lambda {|*| }
@c = lambda {|*| }

parent = ContextState.new ""
parent.before(:each, &@c)
Expand All @@ -189,9 +189,9 @@

describe ContextState, "#post" do
before :each do
@a = lambda { }
@b = lambda { }
@c = lambda { }
@a = lambda {|*| }
@b = lambda {|*| }
@c = lambda {|*| }

parent = ContextState.new ""
parent.after(:each, &@c)
Expand All @@ -217,9 +217,9 @@
describe ContextState, "#protect" do
before :each do
ScratchPad.record []
@a = lambda { ScratchPad << :a }
@b = lambda { ScratchPad << :b }
@c = lambda { raise Exception, "Fail!" }
@a = lambda {|*| ScratchPad << :a }
@b = lambda {|*| ScratchPad << :b }
@c = lambda {|*| raise Exception, "Fail!" }
end

it "returns true and does execute any blocks if check and MSpec.mode?(:pretend) are true" do
Expand Down Expand Up @@ -374,8 +374,8 @@
@state = ContextState.new ""
@state.describe { }

@a = lambda { ScratchPad << :a }
@b = lambda { ScratchPad << :b }
@a = lambda {|*| ScratchPad << :a }
@b = lambda {|*| ScratchPad << :b }
ScratchPad.record []
end

Expand Down Expand Up @@ -658,8 +658,8 @@ def example.example(state, spec)
@state = ContextState.new ""
@state.describe { }

@a = lambda { ScratchPad << :a }
@b = lambda { ScratchPad << :b }
@a = lambda {|*| ScratchPad << :a }
@b = lambda {|*| ScratchPad << :b }
ScratchPad.record []

@state.before(:all) { raise Exception, "Fail!" }
Expand Down Expand Up @@ -718,8 +718,8 @@ def example.example(state, spec)
@state = ContextState.new ""
@state.describe { }

@a = lambda { ScratchPad << :a }
@b = lambda { ScratchPad << :b }
@a = lambda {|*| ScratchPad << :a }
@b = lambda {|*| ScratchPad << :b }
ScratchPad.record []

@state.before(:each) { raise Exception, "Fail!" }
Expand Down Expand Up @@ -815,8 +815,8 @@ def example.example(state, spec)
@state = ContextState.new ""
@state.describe { }

@a = lambda { ScratchPad << :a }
@b = lambda { ScratchPad << :b }
@a = lambda {|*| ScratchPad << :a }
@b = lambda {|*| ScratchPad << :b }
ScratchPad.record []
end

Expand Down Expand Up @@ -921,8 +921,8 @@ def example.example(state, spec)
MSpec.stub!(:retrieve_shared).and_return(@shared)

@state = ContextState.new "Top level"
@a = lambda { }
@b = lambda { }
@a = lambda {|*| }
@b = lambda {|*| }
end

it "raises an Exception if unable to find the shared ContextState" do
Expand Down
1 change: 0 additions & 1 deletion mspec/spec/utils/name_map_spec.rb
Expand Up @@ -74,7 +74,6 @@ def n; end
DTracer
NameMap
OptionParser
YAML
]

excluded.each do |const|
Expand Down
2 changes: 1 addition & 1 deletion mspec/upstream
@@ -1 +1 @@
d664929940b1f38f6686a6c2aea041feb975418b
8a0be99b4844a9f6dfc1eef7092901e6045e5222

0 comments on commit ca1401b

Please sign in to comment.