1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00
This commit is contained in:
Benoit Daloze 2020-03-28 00:22:48 +01:00
parent d214c188e4
commit 296f68816c
20 changed files with 192 additions and 162 deletions

View file

@ -1,28 +1,29 @@
require 'mspec/guards/version' require 'mspec/guards/version'
class BugGuard < VersionGuard class BugGuard < VersionGuard
def initialize(bug, version) def initialize(bug, requirement)
@bug = bug @bug = bug
if String === version if String === requirement
MSpec.deprecate "ruby_bug with a single version", 'an exclusive range ("2.1"..."2.3")' 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 else
super(version) super(FULL_RUBY_VERSION, requirement)
end end
@parameters = [@bug, @version]
end end
def match? def match?
return false if MSpec.mode? :no_ruby_bug return false if MSpec.mode? :no_ruby_bug
return false unless PlatformGuard.standard? return false unless PlatformGuard.standard?
if Range === @version
if Range === @requirement
super super
else else
FULL_RUBY_VERSION <= @version FULL_RUBY_VERSION <= @requirement
end end
end end
end end
def ruby_bug(bug, version, &block) def ruby_bug(bug, requirement, &block)
BugGuard.new(bug, version).run_unless(:ruby_bug, &block) BugGuard.new(bug, requirement).run_unless(:ruby_bug, &block)
end end

View file

@ -111,7 +111,7 @@ class SpecGuard
def add(example) def add(example)
record example.description record example.description
MSpec.retrieve(:formatter).tally.counter.guards! MSpec.formatter.tally.counter.guards!
end end
def unregister def unregister

View file

@ -5,33 +5,40 @@ require 'mspec/guards/guard'
class VersionGuard < SpecGuard class VersionGuard < SpecGuard
FULL_RUBY_VERSION = SpecVersion.new SpecGuard.ruby_version(:full) FULL_RUBY_VERSION = SpecVersion.new SpecGuard.ruby_version(:full)
def initialize(version) def initialize(version, requirement)
case version version = SpecVersion.new(version) unless SpecVersion === version
@version = version
case requirement
when String when String
@version = SpecVersion.new version @requirement = SpecVersion.new requirement
when Range when Range
MSpec.deprecate "an empty version range end", 'a specific version' if version.end.empty? MSpec.deprecate "an empty version range end", 'a specific version' if requirement.end.empty?
a = SpecVersion.new version.begin a = SpecVersion.new requirement.begin
b = SpecVersion.new version.end b = SpecVersion.new requirement.end
unless version.exclude_end? unless requirement.exclude_end?
MSpec.deprecate "ruby_version_is with an inclusive range", 'an exclusive range ("2.1"..."2.3")' MSpec.deprecate "ruby_version_is with an inclusive range", 'an exclusive range ("2.1"..."2.3")'
end end
@version = version.exclude_end? ? a...b : a..b @requirement = requirement.exclude_end? ? a...b : a..b
else 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 end
@parameters = [version] super(@version, @requirement)
end end
def match? def match?
if Range === @version if Range === @requirement
@version.include? FULL_RUBY_VERSION @requirement.include? @version
else else
FULL_RUBY_VERSION >= @version @version >= @requirement
end end
end end
end end
def ruby_version_is(*args, &block) def version_is(base_version, requirement, &block)
VersionGuard.new(*args).run_if(:ruby_version_is, &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 end

View file

@ -14,4 +14,8 @@ module ScratchPad
def self.recorded def self.recorded
@record @record
end end
def self.inspect
"<ScratchPad @record=#{@record.inspect}>"
end
end end

View file

@ -1,9 +1,14 @@
class ConstantsLockFile class ConstantsLockFile
LOCK_FILE_NAME = '.mspec.constants' LOCK_FILE_NAME = '.mspec.constants'
def self.lock_file
@prefix ||= File.expand_path(MSpecScript.get(:prefix) || '.')
"#{@prefix}/#{LOCK_FILE_NAME}"
end
def self.load def self.load
if File.exist?(LOCK_FILE_NAME) if File.exist?(lock_file)
File.readlines(LOCK_FILE_NAME).map(&:chomp) File.readlines(lock_file).map(&:chomp)
else else
[] []
end end
@ -11,7 +16,7 @@ class ConstantsLockFile
def self.dump(ary) def self.dump(ary)
contents = ary.map(&:to_s).uniq.sort.join("\n") + "\n" contents = ary.map(&:to_s).uniq.sort.join("\n") + "\n"
File.write(LOCK_FILE_NAME, contents) File.write(lock_file, contents)
end end
end end

View file

@ -12,15 +12,14 @@
class ContextState class ContextState
attr_reader :state, :parent, :parents, :children, :examples, :to_s attr_reader :state, :parent, :parents, :children, :examples, :to_s
def initialize(mod, options = nil) MOCK_VERIFY = -> { Mock.verify_count }
@to_s = mod.to_s MOCK_CLEANUP = -> { Mock.cleanup }
if options.is_a? Hash EXPECTATION_MISSING = -> { raise SpecExpectationNotFoundError }
@options = options
else def initialize(description, options = nil)
@to_s += "#{".:#".include?(options[0,1]) ? "" : " "}#{options}" if options raise "#describe options should be a Hash or nil" unless Hash === options or options.nil?
@options = { } @to_s = description.to_s
end @shared = options && options[:shared]
@options[:shared] ||= false
@parsed = false @parsed = false
@before = { :all => [], :each => [] } @before = { :all => [], :each => [] }
@ -32,10 +31,6 @@ class ContextState
@parent = nil @parent = nil
@parents = [self] @parents = [self]
@children = [] @children = []
@mock_verify = Proc.new { Mock.verify_count }
@mock_cleanup = Proc.new { Mock.cleanup }
@expectation_missing = Proc.new { raise SpecExpectationNotFoundError }
end end
# Remove caching when a ContextState is dup'd for shared specs. # 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 # Returns true if this is a shared +ContextState+. Essentially, when
# created with: describe "Something", :shared => true { ... } # created with: describe "Something", :shared => true { ... }
def shared? def shared?
return @options[:shared] @shared
end end
# Set the parent (enclosing) +ContextState+ for this state. Creates # Set the parent (enclosing) +ContextState+ for this state. Creates
@ -207,7 +202,7 @@ class ContextState
if protect "before :all", pre(:all) if protect "before :all", pre(:all)
@examples.each do |state| @examples.each do |state|
MSpec.repeat do MSpec.repeat do
@state = state @state = state
example = state.example example = state.example
MSpec.actions :before, state MSpec.actions :before, state
@ -216,20 +211,20 @@ class ContextState
if example if example
passed = protect nil, example passed = protect nil, example
MSpec.actions :example, state, 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
end end
protect "after :each", post(:each) 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 MSpec.actions :after, state
@state = nil @state = nil
end end
end end
protect "after :all", post(:all) protect "after :all", post(:all)
else else
protect "Mock.cleanup", @mock_cleanup protect "Mock.cleanup", MOCK_CLEANUP
end end
MSpec.actions :leave MSpec.actions :leave

View file

@ -3,12 +3,12 @@ require 'mspec/runner/mspec'
# Holds some of the state of the example (i.e. +it+ block) that is # Holds some of the state of the example (i.e. +it+ block) that is
# being evaluated. See also +ContextState+. # being evaluated. See also +ContextState+.
class ExampleState class ExampleState
attr_reader :context, :it, :example attr_reader :context, :it, :example
def initialize(context, it, example = nil) def initialize(context, it, example = nil)
@context = context @context = context
@it = it @it = it
@example = example @example = example
end end
def context=(context) def context=(context)
@ -25,8 +25,8 @@ class ExampleState
end end
def filtered? def filtered?
incl = MSpec.retrieve(:include) || [] incl = MSpec.include
excl = MSpec.retrieve(:exclude) || [] excl = MSpec.exclude
included = incl.empty? || incl.any? { |f| f === description } included = incl.empty? || incl.any? { |f| f === description }
included &&= excl.empty? || !excl.any? { |f| f === description } included &&= excl.empty? || !excl.any? { |f| f === description }
!included !included

View file

@ -6,13 +6,13 @@ class MethodFormatter < BaseFormatter
def initialize(out = nil) def initialize(out = nil)
super(out) super(out)
@methods = Hash.new do |h, k| @methods = Hash.new do |h, k|
hash = {} h[k] = {
hash[:examples] = 0 examples: 0,
hash[:expectations] = 0 expectations: 0,
hash[:failures] = 0 failures: 0,
hash[:errors] = 0 errors: 0,
hash[:exceptions] = [] exceptions: []
h[k] = hash }
end end
end end

View file

@ -78,7 +78,7 @@ class SpinnerFormatter < BaseFormatter
# Callback for the MSpec :start event. Stores the total # Callback for the MSpec :start event. Stores the total
# number of files that will be processed. # number of files that will be processed.
def start def start
@total = MSpec.retrieve(:files).size @total = MSpec.files_array.size
compute_progress compute_progress
print progress_line print progress_line
end end

View file

@ -10,7 +10,6 @@ class MSpecEnv
end end
module MSpec module MSpec
@exit = nil @exit = nil
@abort = nil @abort = nil
@start = nil @start = nil
@ -20,8 +19,8 @@ module MSpec
@after = nil @after = nil
@leave = nil @leave = nil
@finish = nil @finish = nil
@exclude = nil @exclude = []
@include = nil @include = []
@leave = nil @leave = nil
@load = nil @load = nil
@unload = nil @unload = nil
@ -33,13 +32,19 @@ module MSpec
@guarded = [] @guarded = []
@features = {} @features = {}
@exception = nil @exception = nil
@randomize = nil @randomize = false
@repeat = nil @repeat = 1
@expectation = nil @expectation = nil
@expectations = false @expectations = false
def self.describe(mod, options = nil, &block) class << self
state = ContextState.new mod, options 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 state.parent = current
MSpec.register_current state MSpec.register_current state
@ -57,6 +62,10 @@ module MSpec
actions :finish actions :finish
end end
def self.files_array
@files
end
def self.each_file(&block) def self.each_file(&block)
if ENV["MSPEC_MULTI"] if ENV["MSPEC_MULTI"]
while file = STDIN.gets while file = STDIN.gets
@ -74,7 +83,7 @@ module MSpec
# The parent closed the connection without QUIT # The parent closed the connection without QUIT
abort "the parent did not send QUIT" abort "the parent did not send QUIT"
else else
return unless files = retrieve(:files) return unless files = @files
shuffle files if randomize? shuffle files if randomize?
files.each(&block) files.each(&block)
end end
@ -83,10 +92,11 @@ module MSpec
def self.files def self.files
each_file do |file| each_file do |file|
setup_env setup_env
store :file, file @file = file
actions :load actions :load
protect("loading #{file}") { Kernel.load file } protect("loading #{file}") { Kernel.load file }
actions :unload actions :unload
raise "#{file} was executed but did not reset the current example: #{@current}" if @current
end end
end end
@ -101,7 +111,7 @@ module MSpec
def self.protect(location, &block) def self.protect(location, &block)
begin begin
@env.instance_eval(&block) @env.instance_exec(&block)
return true return true
rescue SystemExit => e rescue SystemExit => e
raise e raise e
@ -130,17 +140,17 @@ module MSpec
# Sets the toplevel ContextState to +state+. # Sets the toplevel ContextState to +state+.
def self.register_current(state) def self.register_current(state)
store :current, state @current = state
end end
# Sets the toplevel ContextState to +nil+. # Sets the toplevel ContextState to +nil+.
def self.clear_current def self.clear_current
store :current, nil @current = nil
end end
# Returns the toplevel ContextState. # Returns the toplevel ContextState.
def self.current def self.current
retrieve :current @current
end end
# Stores the shared ContextState keyed by description. # Stores the shared ContextState keyed by description.
@ -155,17 +165,17 @@ module MSpec
# Stores the exit code used by the runner scripts. # Stores the exit code used by the runner scripts.
def self.register_exit(code) def self.register_exit(code)
store :exit, code @exit = code
end end
# Retrieves the stored exit code. # Retrieves the stored exit code.
def self.exit_code def self.exit_code
retrieve(:exit).to_i @exit.to_i
end end
# Stores the list of files to be evaluated. # Stores the list of files to be evaluated.
def self.register_files(files) def self.register_files(files)
store :files, files @files = files
end end
# Stores one or more substitution patterns for transforming # Stores one or more substitution patterns for transforming
@ -176,7 +186,7 @@ module MSpec
# #
# See also +tags_file+. # See also +tags_file+.
def self.register_tags_patterns(patterns) def self.register_tags_patterns(patterns)
store :tags_patterns, patterns @tags_patterns = patterns
end end
# Registers an operating mode. Modes recognized by MSpec: # Registers an operating mode. Modes recognized by MSpec:
@ -187,30 +197,30 @@ module MSpec
# :report - specs that are guarded are reported # :report - specs that are guarded are reported
# :unguarded - all guards are forced off # :unguarded - all guards are forced off
def self.register_mode(mode) def self.register_mode(mode)
modes = retrieve :modes modes = @modes
modes << mode unless modes.include? mode modes << mode unless modes.include? mode
end end
# Clears all registered modes. # Clears all registered modes.
def self.clear_modes def self.clear_modes
store :modes, [] @modes = []
end end
# Returns +true+ if +mode+ is registered. # Returns +true+ if +mode+ is registered.
def self.mode?(mode) def self.mode?(mode)
retrieve(:modes).include? mode @modes.include? mode
end end
def self.enable_feature(feature) def self.enable_feature(feature)
retrieve(:features)[feature] = true @features[feature] = true
end end
def self.disable_feature(feature) def self.disable_feature(feature)
retrieve(:features)[feature] = false @features[feature] = false
end end
def self.feature_enabled?(feature) def self.feature_enabled?(feature)
retrieve(:features)[feature] || false @features[feature] || false
end end
def self.retrieve(symbol) def self.retrieve(symbol)
@ -259,21 +269,17 @@ module MSpec
end end
end end
def self.randomize(flag = true)
@randomize = flag
end
def self.randomize? def self.randomize?
@randomize == true @randomize
end
def self.repeat=(times)
@repeat = times
end end
def self.repeat def self.repeat
(@repeat || 1).times do if @repeat == 1
yield yield
else
@repeat.times do
yield
end
end end
end end
@ -289,17 +295,17 @@ module MSpec
# Records that an expectation has been encountered in an example. # Records that an expectation has been encountered in an example.
def self.expectation def self.expectation
store :expectations, true @expectations = true
end end
# Returns true if an expectation has been encountered # Returns true if an expectation has been encountered
def self.expectation? def self.expectation?
retrieve :expectations @expectations
end end
# Resets the flag that an expectation has been encountered in an example. # Resets the flag that an expectation has been encountered in an example.
def self.clear_expectations def self.clear_expectations
store :expectations, false @expectations = false
end end
# Transforms a spec filename into a tags filename by applying each # Transforms a spec filename into a tags filename by applying each
@ -313,9 +319,9 @@ module MSpec
# #
# See also +register_tags_patterns+. # See also +register_tags_patterns+.
def self.tags_file def self.tags_file
patterns = retrieve(:tags_patterns) || patterns = @tags_patterns ||
[[%r(spec/), 'spec/tags/'], [/_spec.rb$/, '_tags.txt']] [[%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) file.gsub(*pattern)
end end
end end

View file

@ -7,8 +7,8 @@ class Object
MSpec.current.after at, &block MSpec.current.after at, &block
end end
private def describe(mod, msg = nil, options = nil, &block) private def describe(description, options = nil, &block)
MSpec.describe mod, msg, &block MSpec.describe description, options, &block
end end
private def it(desc, &block) private def it(desc, &block)

View file

@ -281,7 +281,7 @@ class MSpecOptions
when 'j', 'junit' when 'j', 'junit'
config[:formatter] = JUnitFormatter config[:formatter] = JUnitFormatter
else else
abort "Unknown format: #{o}\n#{@parser}" unless File.exist?(o) abort "Unknown format: #{o}" unless File.exist?(o)
require File.expand_path(o) require File.expand_path(o)
if Object.const_defined?(:CUSTOM_MSPEC_FORMATTER) if Object.const_defined?(:CUSTOM_MSPEC_FORMATTER)
config[:formatter] = CUSTOM_MSPEC_FORMATTER config[:formatter] = CUSTOM_MSPEC_FORMATTER
@ -377,7 +377,7 @@ class MSpecOptions
def randomize def randomize
on("-H", "--random", on("-H", "--random",
"Randomize the list of spec files") do "Randomize the list of spec files") do
MSpec.randomize MSpec.randomize = true
end end
end end
@ -392,10 +392,10 @@ class MSpecOptions
on("-V", "--verbose", "Output the name of each file processed") do on("-V", "--verbose", "Output the name of each file processed") do
obj = Object.new obj = Object.new
def obj.start 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 end
def obj.load def obj.load
file = MSpec.retrieve :file file = MSpec.file
STDERR.print "\n#{file.ljust(@width)}" STDERR.print "\n#{file.ljust(@width)}"
end end
MSpec.register :start, obj MSpec.register :start, obj

View file

@ -127,7 +127,7 @@ class MSpecScript
if formatter = config_formatter if formatter = config_formatter
formatter.register formatter.register
MSpec.store :formatter, formatter MSpec.formatter = formatter
end end
MatchFilter.new(:include, *config[:includes]).register unless config[:includes].empty? MatchFilter.new(:include, *config[:includes]).register unless config[:includes].empty?

View file

@ -254,7 +254,7 @@ describe Object, "#guard" do
end end
it "allows to combine guards" do 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) VersionGuard.stub(:new).and_return(guard1)
guard2 = PlatformGuard.new :dummy guard2 = PlatformGuard.new :dummy
PlatformGuard.stub(:new).and_return(guard2) PlatformGuard.stub(:new).and_return(guard2)
@ -360,7 +360,7 @@ describe Object, "#guard_not" do
end end
it "allows to combine guards" do 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) VersionGuard.stub(:new).and_return(guard1)
guard2 = PlatformGuard.new :dummy guard2 = PlatformGuard.new :dummy
PlatformGuard.stub(:new).and_return(guard2) PlatformGuard.stub(:new).and_return(guard2)

View file

@ -14,44 +14,44 @@ require 'mspec/guards'
describe VersionGuard, "#match?" do describe VersionGuard, "#match?" do
before :each do before :each do
hide_deprecation_warnings hide_deprecation_warnings
stub_const "VersionGuard::FULL_RUBY_VERSION", SpecVersion.new('1.8.6') @current = '1.8.6'
end end
it "returns true when the argument is equal to RUBY_VERSION" do 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 end
it "returns true when the argument is less than RUBY_VERSION" do it "returns true when the argument is less than RUBY_VERSION" do
VersionGuard.new('1.8').match?.should == true VersionGuard.new(@current, '1.8').match?.should == true
VersionGuard.new('1.8.5').match?.should == true VersionGuard.new(@current, '1.8.5').match?.should == true
end end
it "returns false when the argument is greater than RUBY_VERSION" do it "returns false when the argument is greater than RUBY_VERSION" do
VersionGuard.new('1.8.7').match?.should == false VersionGuard.new(@current, '1.8.7').match?.should == false
VersionGuard.new('1.9.2').match?.should == false VersionGuard.new(@current, '1.9.2').match?.should == false
end end
it "returns true when the argument range includes RUBY_VERSION" do it "returns true when the argument range includes RUBY_VERSION" do
VersionGuard.new('1.8.5'..'1.8.7').match?.should == true VersionGuard.new(@current, '1.8.5'..'1.8.7').match?.should == true
VersionGuard.new('1.8'..'1.9').match?.should == true VersionGuard.new(@current, '1.8'..'1.9').match?.should == true
VersionGuard.new('1.8'...'1.9').match?.should == true VersionGuard.new(@current, '1.8'...'1.9').match?.should == true
VersionGuard.new('1.8'..'1.8.6').match?.should == true VersionGuard.new(@current, '1.8'..'1.8.6').match?.should == true
VersionGuard.new('1.8.5'..'1.8.6').match?.should == true VersionGuard.new(@current, '1.8.5'..'1.8.6').match?.should == true
VersionGuard.new(''...'1.8.7').match?.should == true VersionGuard.new(@current, ''...'1.8.7').match?.should == true
end end
it "returns false when the argument range does not include RUBY_VERSION" do 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(@current, '1.8.7'..'1.8.9').match?.should == false
VersionGuard.new('1.8.4'..'1.8.5').match?.should == false VersionGuard.new(@current, '1.8.4'..'1.8.5').match?.should == false
VersionGuard.new('1.8.4'...'1.8.6').match?.should == false VersionGuard.new(@current, '1.8.4'...'1.8.6').match?.should == false
VersionGuard.new('1.8.5'...'1.8.6').match?.should == false VersionGuard.new(@current, '1.8.5'...'1.8.6').match?.should == false
VersionGuard.new(''...'1.8.6').match?.should == false VersionGuard.new(@current, ''...'1.8.6').match?.should == false
end end
end end
describe Object, "#ruby_version_is" do describe Object, "#ruby_version_is" do
before :each 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) VersionGuard.stub(:new).and_return(@guard)
ScratchPad.clear ScratchPad.clear
end end
@ -88,3 +88,25 @@ describe Object, "#ruby_version_is" do
end.should raise_error(Exception) end.should raise_error(Exception)
end end
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

View file

@ -55,22 +55,6 @@ describe ContextState, "#to_s" do
it "returns a description string for self when passed a String" do it "returns a description string for self when passed a String" do
ContextState.new("SomeClass").to_s.should == "SomeClass" ContextState.new("SomeClass").to_s.should == "SomeClass"
end 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 end
describe ContextState, "#description" do describe ContextState, "#description" do
@ -464,11 +448,14 @@ describe ContextState, "#process" do
end end
it "shuffles the spec list if MSpec.randomize? is true" do it "shuffles the spec list if MSpec.randomize? is true" do
MSpec.randomize MSpec.randomize = true
MSpec.should_receive(:shuffle) begin
@state.it("") { } MSpec.should_receive(:shuffle)
@state.process @state.it("") { }
MSpec.randomize false @state.process
ensure
MSpec.randomize = false
end
end end
it "sets the current MSpec ContextState" do it "sets the current MSpec ContextState" do

View file

@ -14,7 +14,7 @@ end
describe ExampleState, "#describe" do describe ExampleState, "#describe" do
before :each do before :each do
@context = ContextState.new Object, "#to_s" @context = ContextState.new "Object#to_s"
@state = ExampleState.new @context, "it" @state = ExampleState.new @context, "it"
end end
@ -64,16 +64,16 @@ end
describe ExampleState, "#filtered?" do describe ExampleState, "#filtered?" do
before :each do before :each do
MSpec.store :include, nil MSpec.store :include, []
MSpec.store :exclude, nil MSpec.store :exclude, []
@state = ExampleState.new ContextState.new("describe"), "it" @state = ExampleState.new ContextState.new("describe"), "it"
@filter = double("filter") @filter = double("filter")
end end
after :each do after :each do
MSpec.store :include, nil MSpec.store :include, []
MSpec.store :exclude, nil MSpec.store :exclude, []
end end
it "returns false if MSpec include filters list is empty" do it "returns false if MSpec include filters list is empty" do

View file

@ -1,4 +1,5 @@
require 'spec_helper' require 'spec_helper'
require 'mspec/expectations/expectations'
require 'mspec/helpers/tmp' require 'mspec/helpers/tmp'
require 'mspec/helpers/fs' require 'mspec/helpers/fs'
require 'mspec/matchers/base' require 'mspec/matchers/base'
@ -8,7 +9,7 @@ require 'mspec/runner/example'
describe MSpec, ".register_files" do describe MSpec, ".register_files" do
it "records which spec files to run" do it "records which spec files to run" do
MSpec.register_files [:one, :two, :three] MSpec.register_files [:one, :two, :three]
MSpec.retrieve(:files).should == [:one, :two, :three] MSpec.files_array.should == [:one, :two, :three]
end end
end end
@ -66,9 +67,9 @@ end
describe MSpec, ".randomize" do describe MSpec, ".randomize" do
it "sets the flag to randomize spec execution order" do it "sets the flag to randomize spec execution order" do
MSpec.randomize?.should == false MSpec.randomize?.should == false
MSpec.randomize MSpec.randomize = true
MSpec.randomize?.should == true MSpec.randomize?.should == true
MSpec.randomize false MSpec.randomize = false
MSpec.randomize?.should == false MSpec.randomize?.should == false
end end
end end
@ -342,17 +343,19 @@ describe MSpec, ".files" do
end end
it "shuffles the file list if .randomize? is true" do it "shuffles the file list if .randomize? is true" do
MSpec.randomize MSpec.randomize = true
MSpec.should_receive(:shuffle) MSpec.should_receive(:shuffle)
MSpec.files MSpec.files
MSpec.randomize false MSpec.randomize = false
end end
it "registers the current file" do it "registers the current file" do
MSpec.should_receive(:store).with(:file, :one) load = double("load")
MSpec.should_receive(:store).with(:file, :two) files = []
MSpec.should_receive(:store).with(:file, :three) load.stub(:load).and_return { files << MSpec.file }
MSpec.register :load, load
MSpec.files MSpec.files
files.should == [:one, :two, :three]
end end
end end

View file

@ -1044,7 +1044,7 @@ describe "The -H, --random option" do
end end
it "registers the MSpec randomize mode" do it "registers the MSpec randomize mode" do
MSpec.should_receive(:randomize).twice MSpec.should_receive(:randomize=).twice
["-H", "--random"].each do |opt| ["-H", "--random"].each do |opt|
@options.parse opt @options.parse opt
end end

View file

@ -250,8 +250,8 @@ describe MSpecScript, "#register" do
it "registers :formatter with the formatter instance" do it "registers :formatter with the formatter instance" do
@formatter.stub(:new).and_return(@formatter) @formatter.stub(:new).and_return(@formatter)
MSpec.should_receive(:store).with(:formatter, @formatter)
@script.register @script.register
MSpec.formatter.should be(@formatter)
end end
it "does not register :formatter if config[:formatter] is false" do it "does not register :formatter if config[:formatter] is false" do