summaryrefslogtreecommitdiff
path: root/spec/mspec
diff options
context:
space:
mode:
Diffstat (limited to 'spec/mspec')
-rw-r--r--spec/mspec/lib/mspec/guards/bug.rb19
-rw-r--r--spec/mspec/lib/mspec/guards/guard.rb2
-rw-r--r--spec/mspec/lib/mspec/guards/version.rb37
-rw-r--r--spec/mspec/lib/mspec/helpers/scratch.rb4
-rw-r--r--spec/mspec/lib/mspec/runner/actions/constants_leak_checker.rb11
-rw-r--r--spec/mspec/lib/mspec/runner/context.rb33
-rw-r--r--spec/mspec/lib/mspec/runner/example.rb12
-rw-r--r--spec/mspec/lib/mspec/runner/formatters/method.rb14
-rw-r--r--spec/mspec/lib/mspec/runner/formatters/spinner.rb2
-rw-r--r--spec/mspec/lib/mspec/runner/mspec.rb82
-rw-r--r--spec/mspec/lib/mspec/runner/object.rb4
-rw-r--r--spec/mspec/lib/mspec/utils/options.rb8
-rw-r--r--spec/mspec/lib/mspec/utils/script.rb2
-rw-r--r--spec/mspec/spec/guards/guard_spec.rb4
-rw-r--r--spec/mspec/spec/guards/version_spec.rb58
-rw-r--r--spec/mspec/spec/runner/context_spec.rb29
-rw-r--r--spec/mspec/spec/runner/example_spec.rb10
-rw-r--r--spec/mspec/spec/runner/mspec_spec.rb19
-rw-r--r--spec/mspec/spec/utils/options_spec.rb2
-rw-r--r--spec/mspec/spec/utils/script_spec.rb2
20 files changed, 192 insertions, 162 deletions
diff --git a/spec/mspec/lib/mspec/guards/bug.rb b/spec/mspec/lib/mspec/guards/bug.rb
index b1bfc6413e..b9ba75fd97 100644
--- a/spec/mspec/lib/mspec/guards/bug.rb
+++ b/spec/mspec/lib/mspec/guards/bug.rb
@@ -1,28 +1,29 @@
require 'mspec/guards/version'
class BugGuard < VersionGuard
- def initialize(bug, version)
+ def initialize(bug, requirement)
@bug = bug
- if String === version
+ if String === requirement
MSpec.deprecate "ruby_bug with a single version", 'an exclusive range ("2.1"..."2.3")'
- @version = SpecVersion.new version, true
+ @requirement = SpecVersion.new requirement, true
+ super(FULL_RUBY_VERSION, requirement)
else
- super(version)
+ super(FULL_RUBY_VERSION, requirement)
end
- @parameters = [@bug, @version]
end
def match?
return false if MSpec.mode? :no_ruby_bug
return false unless PlatformGuard.standard?
- if Range === @version
+
+ if Range === @requirement
super
else
- FULL_RUBY_VERSION <= @version
+ FULL_RUBY_VERSION <= @requirement
end
end
end
-def ruby_bug(bug, version, &block)
- BugGuard.new(bug, version).run_unless(:ruby_bug, &block)
+def ruby_bug(bug, requirement, &block)
+ BugGuard.new(bug, requirement).run_unless(:ruby_bug, &block)
end
diff --git a/spec/mspec/lib/mspec/guards/guard.rb b/spec/mspec/lib/mspec/guards/guard.rb
index 322a08145d..3a6372a660 100644
--- a/spec/mspec/lib/mspec/guards/guard.rb
+++ b/spec/mspec/lib/mspec/guards/guard.rb
@@ -111,7 +111,7 @@ class SpecGuard
def add(example)
record example.description
- MSpec.retrieve(:formatter).tally.counter.guards!
+ MSpec.formatter.tally.counter.guards!
end
def unregister
diff --git a/spec/mspec/lib/mspec/guards/version.rb b/spec/mspec/lib/mspec/guards/version.rb
index cb08fdac73..20f8c06d38 100644
--- a/spec/mspec/lib/mspec/guards/version.rb
+++ b/spec/mspec/lib/mspec/guards/version.rb
@@ -5,33 +5,40 @@ require 'mspec/guards/guard'
class VersionGuard < SpecGuard
FULL_RUBY_VERSION = SpecVersion.new SpecGuard.ruby_version(:full)
- def initialize(version)
- case version
+ def initialize(version, requirement)
+ version = SpecVersion.new(version) unless SpecVersion === version
+ @version = version
+
+ case requirement
when String
- @version = SpecVersion.new version
+ @requirement = SpecVersion.new requirement
when Range
- MSpec.deprecate "an empty version range end", 'a specific version' if version.end.empty?
- a = SpecVersion.new version.begin
- b = SpecVersion.new version.end
- unless version.exclude_end?
+ MSpec.deprecate "an empty version range end", 'a specific version' if requirement.end.empty?
+ a = SpecVersion.new requirement.begin
+ b = SpecVersion.new requirement.end
+ unless requirement.exclude_end?
MSpec.deprecate "ruby_version_is with an inclusive range", 'an exclusive range ("2.1"..."2.3")'
end
- @version = version.exclude_end? ? a...b : a..b
+ @requirement = requirement.exclude_end? ? a...b : a..b
else
- raise "version must be a String or Range but was a #{version.class}"
+ raise "version must be a String or Range but was a #{requirement.class}"
end
- @parameters = [version]
+ super(@version, @requirement)
end
def match?
- if Range === @version
- @version.include? FULL_RUBY_VERSION
+ if Range === @requirement
+ @requirement.include? @version
else
- FULL_RUBY_VERSION >= @version
+ @version >= @requirement
end
end
end
-def ruby_version_is(*args, &block)
- VersionGuard.new(*args).run_if(:ruby_version_is, &block)
+def version_is(base_version, requirement, &block)
+ VersionGuard.new(base_version, requirement).run_if(:version_is, &block)
+end
+
+def ruby_version_is(requirement, &block)
+ VersionGuard.new(VersionGuard::FULL_RUBY_VERSION, requirement).run_if(:ruby_version_is, &block)
end
diff --git a/spec/mspec/lib/mspec/helpers/scratch.rb b/spec/mspec/lib/mspec/helpers/scratch.rb
index a6b0c02748..0da3315cd8 100644
--- a/spec/mspec/lib/mspec/helpers/scratch.rb
+++ b/spec/mspec/lib/mspec/helpers/scratch.rb
@@ -14,4 +14,8 @@ module ScratchPad
def self.recorded
@record
end
+
+ def self.inspect
+ "<ScratchPad @record=#{@record.inspect}>"
+ end
end
diff --git a/spec/mspec/lib/mspec/runner/actions/constants_leak_checker.rb b/spec/mspec/lib/mspec/runner/actions/constants_leak_checker.rb
index fd0a3efe14..abfb6dd0ee 100644
--- a/spec/mspec/lib/mspec/runner/actions/constants_leak_checker.rb
+++ b/spec/mspec/lib/mspec/runner/actions/constants_leak_checker.rb
@@ -1,9 +1,14 @@
class ConstantsLockFile
LOCK_FILE_NAME = '.mspec.constants'
+ def self.lock_file
+ @prefix ||= File.expand_path(MSpecScript.get(:prefix) || '.')
+ "#{@prefix}/#{LOCK_FILE_NAME}"
+ end
+
def self.load
- if File.exist?(LOCK_FILE_NAME)
- File.readlines(LOCK_FILE_NAME).map(&:chomp)
+ if File.exist?(lock_file)
+ File.readlines(lock_file).map(&:chomp)
else
[]
end
@@ -11,7 +16,7 @@ class ConstantsLockFile
def self.dump(ary)
contents = ary.map(&:to_s).uniq.sort.join("\n") + "\n"
- File.write(LOCK_FILE_NAME, contents)
+ File.write(lock_file, contents)
end
end
diff --git a/spec/mspec/lib/mspec/runner/context.rb b/spec/mspec/lib/mspec/runner/context.rb
index d55b0dcd9e..62483590bb 100644
--- a/spec/mspec/lib/mspec/runner/context.rb
+++ b/spec/mspec/lib/mspec/runner/context.rb
@@ -12,15 +12,14 @@
class ContextState
attr_reader :state, :parent, :parents, :children, :examples, :to_s
- def initialize(mod, options = nil)
- @to_s = mod.to_s
- if options.is_a? Hash
- @options = options
- else
- @to_s += "#{".:#".include?(options[0,1]) ? "" : " "}#{options}" if options
- @options = { }
- end
- @options[:shared] ||= false
+ MOCK_VERIFY = -> { Mock.verify_count }
+ MOCK_CLEANUP = -> { Mock.cleanup }
+ EXPECTATION_MISSING = -> { raise SpecExpectationNotFoundError }
+
+ def initialize(description, options = nil)
+ raise "#describe options should be a Hash or nil" unless Hash === options or options.nil?
+ @to_s = description.to_s
+ @shared = options && options[:shared]
@parsed = false
@before = { :all => [], :each => [] }
@@ -32,10 +31,6 @@ class ContextState
@parent = nil
@parents = [self]
@children = []
-
- @mock_verify = Proc.new { Mock.verify_count }
- @mock_cleanup = Proc.new { Mock.cleanup }
- @expectation_missing = Proc.new { raise SpecExpectationNotFoundError }
end
# Remove caching when a ContextState is dup'd for shared specs.
@@ -47,7 +42,7 @@ class ContextState
# Returns true if this is a shared +ContextState+. Essentially, when
# created with: describe "Something", :shared => true { ... }
def shared?
- return @options[:shared]
+ @shared
end
# Set the parent (enclosing) +ContextState+ for this state. Creates
@@ -207,7 +202,7 @@ class ContextState
if protect "before :all", pre(:all)
@examples.each do |state|
MSpec.repeat do
- @state = state
+ @state = state
example = state.example
MSpec.actions :before, state
@@ -216,20 +211,20 @@ class ContextState
if example
passed = protect nil, example
MSpec.actions :example, state, example
- protect nil, @expectation_missing if !MSpec.expectation? and passed
+ protect nil, EXPECTATION_MISSING if !MSpec.expectation? and passed
end
end
protect "after :each", post(:each)
- protect "Mock.verify_count", @mock_verify
+ protect "Mock.verify_count", MOCK_VERIFY
- protect "Mock.cleanup", @mock_cleanup
+ protect "Mock.cleanup", MOCK_CLEANUP
MSpec.actions :after, state
@state = nil
end
end
protect "after :all", post(:all)
else
- protect "Mock.cleanup", @mock_cleanup
+ protect "Mock.cleanup", MOCK_CLEANUP
end
MSpec.actions :leave
diff --git a/spec/mspec/lib/mspec/runner/example.rb b/spec/mspec/lib/mspec/runner/example.rb
index 82feba0b03..0d9f0d618c 100644
--- a/spec/mspec/lib/mspec/runner/example.rb
+++ b/spec/mspec/lib/mspec/runner/example.rb
@@ -3,12 +3,12 @@ require 'mspec/runner/mspec'
# Holds some of the state of the example (i.e. +it+ block) that is
# being evaluated. See also +ContextState+.
class ExampleState
- attr_reader :context, :it, :example
+ attr_reader :context, :it, :example
def initialize(context, it, example = nil)
- @context = context
- @it = it
- @example = example
+ @context = context
+ @it = it
+ @example = example
end
def context=(context)
@@ -25,8 +25,8 @@ class ExampleState
end
def filtered?
- incl = MSpec.retrieve(:include) || []
- excl = MSpec.retrieve(:exclude) || []
+ incl = MSpec.include
+ excl = MSpec.exclude
included = incl.empty? || incl.any? { |f| f === description }
included &&= excl.empty? || !excl.any? { |f| f === description }
!included
diff --git a/spec/mspec/lib/mspec/runner/formatters/method.rb b/spec/mspec/lib/mspec/runner/formatters/method.rb
index 8fe02575c4..925858c845 100644
--- a/spec/mspec/lib/mspec/runner/formatters/method.rb
+++ b/spec/mspec/lib/mspec/runner/formatters/method.rb
@@ -6,13 +6,13 @@ class MethodFormatter < BaseFormatter
def initialize(out = nil)
super(out)
@methods = Hash.new do |h, k|
- hash = {}
- hash[:examples] = 0
- hash[:expectations] = 0
- hash[:failures] = 0
- hash[:errors] = 0
- hash[:exceptions] = []
- h[k] = hash
+ h[k] = {
+ examples: 0,
+ expectations: 0,
+ failures: 0,
+ errors: 0,
+ exceptions: []
+ }
end
end
diff --git a/spec/mspec/lib/mspec/runner/formatters/spinner.rb b/spec/mspec/lib/mspec/runner/formatters/spinner.rb
index 8815e1a48a..817d8c02be 100644
--- a/spec/mspec/lib/mspec/runner/formatters/spinner.rb
+++ b/spec/mspec/lib/mspec/runner/formatters/spinner.rb
@@ -78,7 +78,7 @@ class SpinnerFormatter < BaseFormatter
# Callback for the MSpec :start event. Stores the total
# number of files that will be processed.
def start
- @total = MSpec.retrieve(:files).size
+ @total = MSpec.files_array.size
compute_progress
print progress_line
end
diff --git a/spec/mspec/lib/mspec/runner/mspec.rb b/spec/mspec/lib/mspec/runner/mspec.rb
index 5528f27cf8..0e2496d3d7 100644
--- a/spec/mspec/lib/mspec/runner/mspec.rb
+++ b/spec/mspec/lib/mspec/runner/mspec.rb
@@ -10,7 +10,6 @@ class MSpecEnv
end
module MSpec
-
@exit = nil
@abort = nil
@start = nil
@@ -20,8 +19,8 @@ module MSpec
@after = nil
@leave = nil
@finish = nil
- @exclude = nil
- @include = nil
+ @exclude = []
+ @include = []
@leave = nil
@load = nil
@unload = nil
@@ -33,13 +32,19 @@ module MSpec
@guarded = []
@features = {}
@exception = nil
- @randomize = nil
- @repeat = nil
+ @randomize = false
+ @repeat = 1
@expectation = nil
@expectations = false
- def self.describe(mod, options = nil, &block)
- state = ContextState.new mod, options
+ class << self
+ attr_reader :file, :include, :exclude
+ attr_writer :repeat, :randomize
+ attr_accessor :formatter
+ end
+
+ def self.describe(description, options = nil, &block)
+ state = ContextState.new description, options
state.parent = current
MSpec.register_current state
@@ -57,6 +62,10 @@ module MSpec
actions :finish
end
+ def self.files_array
+ @files
+ end
+
def self.each_file(&block)
if ENV["MSPEC_MULTI"]
while file = STDIN.gets
@@ -74,7 +83,7 @@ module MSpec
# The parent closed the connection without QUIT
abort "the parent did not send QUIT"
else
- return unless files = retrieve(:files)
+ return unless files = @files
shuffle files if randomize?
files.each(&block)
end
@@ -83,10 +92,11 @@ module MSpec
def self.files
each_file do |file|
setup_env
- store :file, file
+ @file = file
actions :load
protect("loading #{file}") { Kernel.load file }
actions :unload
+ raise "#{file} was executed but did not reset the current example: #{@current}" if @current
end
end
@@ -101,7 +111,7 @@ module MSpec
def self.protect(location, &block)
begin
- @env.instance_eval(&block)
+ @env.instance_exec(&block)
return true
rescue SystemExit => e
raise e
@@ -130,17 +140,17 @@ module MSpec
# Sets the toplevel ContextState to +state+.
def self.register_current(state)
- store :current, state
+ @current = state
end
# Sets the toplevel ContextState to +nil+.
def self.clear_current
- store :current, nil
+ @current = nil
end
# Returns the toplevel ContextState.
def self.current
- retrieve :current
+ @current
end
# Stores the shared ContextState keyed by description.
@@ -155,17 +165,17 @@ module MSpec
# Stores the exit code used by the runner scripts.
def self.register_exit(code)
- store :exit, code
+ @exit = code
end
# Retrieves the stored exit code.
def self.exit_code
- retrieve(:exit).to_i
+ @exit.to_i
end
# Stores the list of files to be evaluated.
def self.register_files(files)
- store :files, files
+ @files = files
end
# Stores one or more substitution patterns for transforming
@@ -176,7 +186,7 @@ module MSpec
#
# See also +tags_file+.
def self.register_tags_patterns(patterns)
- store :tags_patterns, patterns
+ @tags_patterns = patterns
end
# Registers an operating mode. Modes recognized by MSpec:
@@ -187,30 +197,30 @@ module MSpec
# :report - specs that are guarded are reported
# :unguarded - all guards are forced off
def self.register_mode(mode)
- modes = retrieve :modes
+ modes = @modes
modes << mode unless modes.include? mode
end
# Clears all registered modes.
def self.clear_modes
- store :modes, []
+ @modes = []
end
# Returns +true+ if +mode+ is registered.
def self.mode?(mode)
- retrieve(:modes).include? mode
+ @modes.include? mode
end
def self.enable_feature(feature)
- retrieve(:features)[feature] = true
+ @features[feature] = true
end
def self.disable_feature(feature)
- retrieve(:features)[feature] = false
+ @features[feature] = false
end
def self.feature_enabled?(feature)
- retrieve(:features)[feature] || false
+ @features[feature] || false
end
def self.retrieve(symbol)
@@ -259,21 +269,17 @@ module MSpec
end
end
- def self.randomize(flag = true)
- @randomize = flag
- end
-
def self.randomize?
- @randomize == true
- end
-
- def self.repeat=(times)
- @repeat = times
+ @randomize
end
def self.repeat
- (@repeat || 1).times do
+ if @repeat == 1
yield
+ else
+ @repeat.times do
+ yield
+ end
end
end
@@ -289,17 +295,17 @@ module MSpec
# Records that an expectation has been encountered in an example.
def self.expectation
- store :expectations, true
+ @expectations = true
end
# Returns true if an expectation has been encountered
def self.expectation?
- retrieve :expectations
+ @expectations
end
# Resets the flag that an expectation has been encountered in an example.
def self.clear_expectations
- store :expectations, false
+ @expectations = false
end
# Transforms a spec filename into a tags filename by applying each
@@ -313,9 +319,9 @@ module MSpec
#
# See also +register_tags_patterns+.
def self.tags_file
- patterns = retrieve(:tags_patterns) ||
+ patterns = @tags_patterns ||
[[%r(spec/), 'spec/tags/'], [/_spec.rb$/, '_tags.txt']]
- patterns.inject(retrieve(:file).dup) do |file, pattern|
+ patterns.inject(@file.dup) do |file, pattern|
file.gsub(*pattern)
end
end
diff --git a/spec/mspec/lib/mspec/runner/object.rb b/spec/mspec/lib/mspec/runner/object.rb
index d5d9650795..58d98cc4df 100644
--- a/spec/mspec/lib/mspec/runner/object.rb
+++ b/spec/mspec/lib/mspec/runner/object.rb
@@ -7,8 +7,8 @@ class Object
MSpec.current.after at, &block
end
- private def describe(mod, msg = nil, options = nil, &block)
- MSpec.describe mod, msg, &block
+ private def describe(description, options = nil, &block)
+ MSpec.describe description, options, &block
end
private def it(desc, &block)
diff --git a/spec/mspec/lib/mspec/utils/options.rb b/spec/mspec/lib/mspec/utils/options.rb
index 3e3f708a2f..886707e0c4 100644
--- a/spec/mspec/lib/mspec/utils/options.rb
+++ b/spec/mspec/lib/mspec/utils/options.rb
@@ -281,7 +281,7 @@ class MSpecOptions
when 'j', 'junit'
config[:formatter] = JUnitFormatter
else
- abort "Unknown format: #{o}\n#{@parser}" unless File.exist?(o)
+ abort "Unknown format: #{o}" unless File.exist?(o)
require File.expand_path(o)
if Object.const_defined?(:CUSTOM_MSPEC_FORMATTER)
config[:formatter] = CUSTOM_MSPEC_FORMATTER
@@ -377,7 +377,7 @@ class MSpecOptions
def randomize
on("-H", "--random",
"Randomize the list of spec files") do
- MSpec.randomize
+ MSpec.randomize = true
end
end
@@ -392,10 +392,10 @@ class MSpecOptions
on("-V", "--verbose", "Output the name of each file processed") do
obj = Object.new
def obj.start
- @width = MSpec.retrieve(:files).inject(0) { |max, f| f.size > max ? f.size : max }
+ @width = MSpec.files_array.inject(0) { |max, f| f.size > max ? f.size : max }
end
def obj.load
- file = MSpec.retrieve :file
+ file = MSpec.file
STDERR.print "\n#{file.ljust(@width)}"
end
MSpec.register :start, obj
diff --git a/spec/mspec/lib/mspec/utils/script.rb b/spec/mspec/lib/mspec/utils/script.rb
index 2545a16bae..ec841db2e7 100644
--- a/spec/mspec/lib/mspec/utils/script.rb
+++ b/spec/mspec/lib/mspec/utils/script.rb
@@ -127,7 +127,7 @@ class MSpecScript
if formatter = config_formatter
formatter.register
- MSpec.store :formatter, formatter
+ MSpec.formatter = formatter
end
MatchFilter.new(:include, *config[:includes]).register unless config[:includes].empty?
diff --git a/spec/mspec/spec/guards/guard_spec.rb b/spec/mspec/spec/guards/guard_spec.rb
index 5c3dae4b3f..2c3317afe6 100644
--- a/spec/mspec/spec/guards/guard_spec.rb
+++ b/spec/mspec/spec/guards/guard_spec.rb
@@ -254,7 +254,7 @@ describe Object, "#guard" do
end
it "allows to combine guards" do
- guard1 = VersionGuard.new 'x.x.x'
+ guard1 = VersionGuard.new '1.2.3', 'x.x.x'
VersionGuard.stub(:new).and_return(guard1)
guard2 = PlatformGuard.new :dummy
PlatformGuard.stub(:new).and_return(guard2)
@@ -360,7 +360,7 @@ describe Object, "#guard_not" do
end
it "allows to combine guards" do
- guard1 = VersionGuard.new 'x.x.x'
+ guard1 = VersionGuard.new '1.2.3', 'x.x.x'
VersionGuard.stub(:new).and_return(guard1)
guard2 = PlatformGuard.new :dummy
PlatformGuard.stub(:new).and_return(guard2)
diff --git a/spec/mspec/spec/guards/version_spec.rb b/spec/mspec/spec/guards/version_spec.rb
index 07eb451ec9..b0025efcfb 100644
--- a/spec/mspec/spec/guards/version_spec.rb
+++ b/spec/mspec/spec/guards/version_spec.rb
@@ -14,44 +14,44 @@ require 'mspec/guards'
describe VersionGuard, "#match?" do
before :each do
hide_deprecation_warnings
- stub_const "VersionGuard::FULL_RUBY_VERSION", SpecVersion.new('1.8.6')
+ @current = '1.8.6'
end
it "returns true when the argument is equal to RUBY_VERSION" do
- VersionGuard.new('1.8.6').match?.should == true
+ VersionGuard.new(@current, '1.8.6').match?.should == true
end
it "returns true when the argument is less than RUBY_VERSION" do
- VersionGuard.new('1.8').match?.should == true
- VersionGuard.new('1.8.5').match?.should == true
+ VersionGuard.new(@current, '1.8').match?.should == true
+ VersionGuard.new(@current, '1.8.5').match?.should == true
end
it "returns false when the argument is greater than RUBY_VERSION" do
- VersionGuard.new('1.8.7').match?.should == false
- VersionGuard.new('1.9.2').match?.should == false
+ VersionGuard.new(@current, '1.8.7').match?.should == false
+ VersionGuard.new(@current, '1.9.2').match?.should == false
end
it "returns true when the argument range includes RUBY_VERSION" do
- VersionGuard.new('1.8.5'..'1.8.7').match?.should == true
- VersionGuard.new('1.8'..'1.9').match?.should == true
- VersionGuard.new('1.8'...'1.9').match?.should == true
- VersionGuard.new('1.8'..'1.8.6').match?.should == true
- VersionGuard.new('1.8.5'..'1.8.6').match?.should == true
- VersionGuard.new(''...'1.8.7').match?.should == true
+ VersionGuard.new(@current, '1.8.5'..'1.8.7').match?.should == true
+ VersionGuard.new(@current, '1.8'..'1.9').match?.should == true
+ VersionGuard.new(@current, '1.8'...'1.9').match?.should == true
+ VersionGuard.new(@current, '1.8'..'1.8.6').match?.should == true
+ VersionGuard.new(@current, '1.8.5'..'1.8.6').match?.should == true
+ VersionGuard.new(@current, ''...'1.8.7').match?.should == true
end
it "returns false when the argument range does not include RUBY_VERSION" do
- VersionGuard.new('1.8.7'..'1.8.9').match?.should == false
- VersionGuard.new('1.8.4'..'1.8.5').match?.should == false
- VersionGuard.new('1.8.4'...'1.8.6').match?.should == false
- VersionGuard.new('1.8.5'...'1.8.6').match?.should == false
- VersionGuard.new(''...'1.8.6').match?.should == false
+ VersionGuard.new(@current, '1.8.7'..'1.8.9').match?.should == false
+ VersionGuard.new(@current, '1.8.4'..'1.8.5').match?.should == false
+ VersionGuard.new(@current, '1.8.4'...'1.8.6').match?.should == false
+ VersionGuard.new(@current, '1.8.5'...'1.8.6').match?.should == false
+ VersionGuard.new(@current, ''...'1.8.6').match?.should == false
end
end
describe Object, "#ruby_version_is" do
before :each do
- @guard = VersionGuard.new 'x.x.x'
+ @guard = VersionGuard.new '1.2.3', 'x.x.x'
VersionGuard.stub(:new).and_return(@guard)
ScratchPad.clear
end
@@ -88,3 +88,25 @@ describe Object, "#ruby_version_is" do
end.should raise_error(Exception)
end
end
+
+describe Object, "#version_is" do
+ before :each do
+ hide_deprecation_warnings
+ end
+
+ it "returns the expected values" do
+ version_is('1.2.3', '1.2.2').should == true
+ version_is('1.2.3', '1.2.3').should == true
+ version_is('1.2.3', '1.2.4').should == false
+
+ version_is('1.2.3', '1').should == true
+ version_is('1.2.3', '1.0').should == true
+ version_is('1.2.3', '2').should == false
+ version_is('1.2.3', '2.0').should == false
+
+ version_is('1.2.3', '1.2.2'..'1.2.4').should == true
+ version_is('1.2.3', '1.2.2'..'1.2.3').should == true
+ version_is('1.2.3', '1.2.2'...'1.2.3').should == false
+ version_is('1.2.3', '1.2.3'..'1.2.4').should == true
+ end
+end
diff --git a/spec/mspec/spec/runner/context_spec.rb b/spec/mspec/spec/runner/context_spec.rb
index d9c20aa0cf..c5aa691323 100644
--- a/spec/mspec/spec/runner/context_spec.rb
+++ b/spec/mspec/spec/runner/context_spec.rb
@@ -55,22 +55,6 @@ describe ContextState, "#to_s" do
it "returns a description string for self when passed a String" do
ContextState.new("SomeClass").to_s.should == "SomeClass"
end
-
- it "returns a description string for self when passed a Module, String" do
- ContextState.new(Object, "when empty").to_s.should == "Object when empty"
- end
-
- it "returns a description string for self when passed a Module and String beginning with '#'" do
- ContextState.new(Object, "#to_s").to_s.should == "Object#to_s"
- end
-
- it "returns a description string for self when passed a Module and String beginning with '.'" do
- ContextState.new(Object, ".to_s").to_s.should == "Object.to_s"
- end
-
- it "returns a description string for self when passed a Module and String beginning with '::'" do
- ContextState.new(Object, "::to_s").to_s.should == "Object::to_s"
- end
end
describe ContextState, "#description" do
@@ -464,11 +448,14 @@ describe ContextState, "#process" do
end
it "shuffles the spec list if MSpec.randomize? is true" do
- MSpec.randomize
- MSpec.should_receive(:shuffle)
- @state.it("") { }
- @state.process
- MSpec.randomize false
+ MSpec.randomize = true
+ begin
+ MSpec.should_receive(:shuffle)
+ @state.it("") { }
+ @state.process
+ ensure
+ MSpec.randomize = false
+ end
end
it "sets the current MSpec ContextState" do
diff --git a/spec/mspec/spec/runner/example_spec.rb b/spec/mspec/spec/runner/example_spec.rb
index b4391f802d..7d3ad6be30 100644
--- a/spec/mspec/spec/runner/example_spec.rb
+++ b/spec/mspec/spec/runner/example_spec.rb
@@ -14,7 +14,7 @@ end
describe ExampleState, "#describe" do
before :each do
- @context = ContextState.new Object, "#to_s"
+ @context = ContextState.new "Object#to_s"
@state = ExampleState.new @context, "it"
end
@@ -64,16 +64,16 @@ end
describe ExampleState, "#filtered?" do
before :each do
- MSpec.store :include, nil
- MSpec.store :exclude, nil
+ MSpec.store :include, []
+ MSpec.store :exclude, []
@state = ExampleState.new ContextState.new("describe"), "it"
@filter = double("filter")
end
after :each do
- MSpec.store :include, nil
- MSpec.store :exclude, nil
+ MSpec.store :include, []
+ MSpec.store :exclude, []
end
it "returns false if MSpec include filters list is empty" do
diff --git a/spec/mspec/spec/runner/mspec_spec.rb b/spec/mspec/spec/runner/mspec_spec.rb
index 91338c6ddb..7dad4458d3 100644
--- a/spec/mspec/spec/runner/mspec_spec.rb
+++ b/spec/mspec/spec/runner/mspec_spec.rb
@@ -1,4 +1,5 @@
require 'spec_helper'
+require 'mspec/expectations/expectations'
require 'mspec/helpers/tmp'
require 'mspec/helpers/fs'
require 'mspec/matchers/base'
@@ -8,7 +9,7 @@ require 'mspec/runner/example'
describe MSpec, ".register_files" do
it "records which spec files to run" do
MSpec.register_files [:one, :two, :three]
- MSpec.retrieve(:files).should == [:one, :two, :three]
+ MSpec.files_array.should == [:one, :two, :three]
end
end
@@ -66,9 +67,9 @@ end
describe MSpec, ".randomize" do
it "sets the flag to randomize spec execution order" do
MSpec.randomize?.should == false
- MSpec.randomize
+ MSpec.randomize = true
MSpec.randomize?.should == true
- MSpec.randomize false
+ MSpec.randomize = false
MSpec.randomize?.should == false
end
end
@@ -342,17 +343,19 @@ describe MSpec, ".files" do
end
it "shuffles the file list if .randomize? is true" do
- MSpec.randomize
+ MSpec.randomize = true
MSpec.should_receive(:shuffle)
MSpec.files
- MSpec.randomize false
+ MSpec.randomize = false
end
it "registers the current file" do
- MSpec.should_receive(:store).with(:file, :one)
- MSpec.should_receive(:store).with(:file, :two)
- MSpec.should_receive(:store).with(:file, :three)
+ load = double("load")
+ files = []
+ load.stub(:load).and_return { files << MSpec.file }
+ MSpec.register :load, load
MSpec.files
+ files.should == [:one, :two, :three]
end
end
diff --git a/spec/mspec/spec/utils/options_spec.rb b/spec/mspec/spec/utils/options_spec.rb
index face909286..ef85c41246 100644
--- a/spec/mspec/spec/utils/options_spec.rb
+++ b/spec/mspec/spec/utils/options_spec.rb
@@ -1044,7 +1044,7 @@ describe "The -H, --random option" do
end
it "registers the MSpec randomize mode" do
- MSpec.should_receive(:randomize).twice
+ MSpec.should_receive(:randomize=).twice
["-H", "--random"].each do |opt|
@options.parse opt
end
diff --git a/spec/mspec/spec/utils/script_spec.rb b/spec/mspec/spec/utils/script_spec.rb
index 3cc85fa1e2..c7fa3eb354 100644
--- a/spec/mspec/spec/utils/script_spec.rb
+++ b/spec/mspec/spec/utils/script_spec.rb
@@ -250,8 +250,8 @@ describe MSpecScript, "#register" do
it "registers :formatter with the formatter instance" do
@formatter.stub(:new).and_return(@formatter)
- MSpec.should_receive(:store).with(:formatter, @formatter)
@script.register
+ MSpec.formatter.should be(@formatter)
end
it "does not register :formatter if config[:formatter] is false" do