Skip to content

Commit

Permalink
Update to ruby/mspec@16b5a0a
Browse files Browse the repository at this point in the history
  • Loading branch information
eregon committed Mar 27, 2020
1 parent d214c18 commit 296f688
Show file tree
Hide file tree
Showing 20 changed files with 192 additions and 162 deletions.
19 changes: 10 additions & 9 deletions spec/mspec/lib/mspec/guards/bug.rb
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion spec/mspec/lib/mspec/guards/guard.rb
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ def record(description)

def add(example)
record example.description
MSpec.retrieve(:formatter).tally.counter.guards!
MSpec.formatter.tally.counter.guards!
end

def unregister
Expand Down
37 changes: 22 additions & 15 deletions spec/mspec/lib/mspec/guards/version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,33 +5,40 @@
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
4 changes: 4 additions & 0 deletions spec/mspec/lib/mspec/helpers/scratch.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,8 @@ def self.<<(arg)
def self.recorded
@record
end

def self.inspect
"<ScratchPad @record=#{@record.inspect}>"
end
end
11 changes: 8 additions & 3 deletions spec/mspec/lib/mspec/runner/actions/constants_leak_checker.rb
Original file line number Diff line number Diff line change
@@ -1,17 +1,22 @@
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
end

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

Expand Down
33 changes: 14 additions & 19 deletions spec/mspec/lib/mspec/runner/context.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 => [] }
Expand All @@ -32,10 +31,6 @@ def initialize(mod, options = nil)
@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.
Expand All @@ -47,7 +42,7 @@ def initialize_copy(other)
# 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
Expand Down Expand Up @@ -207,7 +202,7 @@ def process
if protect "before :all", pre(:all)
@examples.each do |state|
MSpec.repeat do
@state = state
@state = state
example = state.example
MSpec.actions :before, state

Expand All @@ -216,20 +211,20 @@ def process
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
Expand Down
12 changes: 6 additions & 6 deletions spec/mspec/lib/mspec/runner/example.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
# 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)
Expand All @@ -25,8 +25,8 @@ def description
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
Expand Down
14 changes: 7 additions & 7 deletions spec/mspec/lib/mspec/runner/formatters/method.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion spec/mspec/lib/mspec/runner/formatters/spinner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def clear_progress_line
# 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
Expand Down
Loading

0 comments on commit 296f688

Please sign in to comment.