зеркало из https://github.com/github/ruby.git
Update to ruby/mspec@d1adf59
This commit is contained in:
Родитель
31ae931e16
Коммит
44736a6b7a
|
@ -1,4 +1,4 @@
|
|||
source 'https://rubygems.org'
|
||||
|
||||
gem "rake", "~> 12.3"
|
||||
gem "rspec", "~> 2.14.1"
|
||||
gem "rspec", "~> 3.0"
|
||||
|
|
|
@ -1,16 +1,21 @@
|
|||
GEM
|
||||
remote: https://rubygems.org/
|
||||
specs:
|
||||
diff-lcs (1.3)
|
||||
diff-lcs (1.4.4)
|
||||
rake (12.3.3)
|
||||
rspec (2.14.1)
|
||||
rspec-core (~> 2.14.0)
|
||||
rspec-expectations (~> 2.14.0)
|
||||
rspec-mocks (~> 2.14.0)
|
||||
rspec-core (2.14.8)
|
||||
rspec-expectations (2.14.5)
|
||||
diff-lcs (>= 1.1.3, < 2.0)
|
||||
rspec-mocks (2.14.6)
|
||||
rspec (3.10.0)
|
||||
rspec-core (~> 3.10.0)
|
||||
rspec-expectations (~> 3.10.0)
|
||||
rspec-mocks (~> 3.10.0)
|
||||
rspec-core (3.10.1)
|
||||
rspec-support (~> 3.10.0)
|
||||
rspec-expectations (3.10.1)
|
||||
diff-lcs (>= 1.2.0, < 2.0)
|
||||
rspec-support (~> 3.10.0)
|
||||
rspec-mocks (3.10.2)
|
||||
diff-lcs (>= 1.2.0, < 2.0)
|
||||
rspec-support (~> 3.10.0)
|
||||
rspec-support (3.10.2)
|
||||
|
||||
PLATFORMS
|
||||
java
|
||||
|
@ -18,4 +23,4 @@ PLATFORMS
|
|||
|
||||
DEPENDENCIES
|
||||
rake (~> 12.3)
|
||||
rspec (~> 2.14.1)
|
||||
rspec (~> 3.0)
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
class Object
|
||||
NO_MATCHER_GIVEN = Object.new
|
||||
|
||||
def should(matcher = NO_MATCHER_GIVEN)
|
||||
def should(matcher = NO_MATCHER_GIVEN, &block)
|
||||
MSpec.expectation
|
||||
state = MSpec.current.state
|
||||
raise "should outside example" unless state
|
||||
|
@ -10,6 +10,9 @@ class Object
|
|||
if NO_MATCHER_GIVEN.equal?(matcher)
|
||||
SpecPositiveOperatorMatcher.new(self)
|
||||
else
|
||||
# The block was given to #should syntactically, but it was intended for a matcher like #raise_error
|
||||
matcher.block = block if block
|
||||
|
||||
unless matcher.matches? self
|
||||
expected, actual = matcher.failure_message
|
||||
SpecExpectation.fail_with(expected, actual)
|
||||
|
@ -17,7 +20,7 @@ class Object
|
|||
end
|
||||
end
|
||||
|
||||
def should_not(matcher = NO_MATCHER_GIVEN)
|
||||
def should_not(matcher = NO_MATCHER_GIVEN, &block)
|
||||
MSpec.expectation
|
||||
state = MSpec.current.state
|
||||
raise "should_not outside example" unless state
|
||||
|
@ -26,6 +29,9 @@ class Object
|
|||
if NO_MATCHER_GIVEN.equal?(matcher)
|
||||
SpecNegativeOperatorMatcher.new(self)
|
||||
else
|
||||
# The block was given to #should_not syntactically, but it was intended for the matcher
|
||||
matcher.block = block if block
|
||||
|
||||
if matcher.matches? self
|
||||
expected, actual = matcher.negative_failure_message
|
||||
SpecExpectation.fail_with(expected, actual)
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
require 'mspec/guards/version'
|
||||
|
||||
# You might be looking for #silence_warnings, use #suppress_warning instead.
|
||||
# MSpec calls it #suppress_warning for consistency with EnvUtil.suppress_warning in CRuby test/.
|
||||
def suppress_warning
|
||||
verbose = $VERBOSE
|
||||
$VERBOSE = nil
|
||||
|
|
|
@ -1,4 +1,6 @@
|
|||
class RaiseErrorMatcher
|
||||
attr_writer :block
|
||||
|
||||
def initialize(exception, message, &block)
|
||||
@exception = exception
|
||||
@message = message
|
||||
|
|
|
@ -24,7 +24,7 @@ class JUnitFormatter < YamlFormatter
|
|||
errors = @tally.counter.errors
|
||||
failures = @tally.counter.failures
|
||||
|
||||
printf <<-XML
|
||||
print <<-XML
|
||||
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<testsuites
|
||||
|
@ -42,8 +42,8 @@ class JUnitFormatter < YamlFormatter
|
|||
@tests.each do |h|
|
||||
description = encode_for_xml h[:test].description
|
||||
|
||||
printf <<-XML, "Spec", description, 0.0
|
||||
<testcase classname="%s" name="%s" time="%f">
|
||||
print <<-XML
|
||||
<testcase classname="Spec" name="#{description}" time="0.0">
|
||||
XML
|
||||
if h[:exception]
|
||||
outcome = h[:test].failure? ? "failure" : "error"
|
||||
|
|
|
@ -1,18 +1,18 @@
|
|||
require 'spec_helper'
|
||||
require 'mspec/commands/mkspec'
|
||||
require 'fileutils'
|
||||
|
||||
|
||||
describe "The -c, --constant CONSTANT option" do
|
||||
RSpec.describe "The -c, --constant CONSTANT option" do
|
||||
before :each do
|
||||
@options = MSpecOptions.new
|
||||
MSpecOptions.stub(:new).and_return(@options)
|
||||
allow(MSpecOptions).to receive(:new).and_return(@options)
|
||||
@script = MkSpec.new
|
||||
@config = @script.config
|
||||
end
|
||||
|
||||
it "is enabled by #options" do
|
||||
@options.stub(:on)
|
||||
@options.should_receive(:on).with("-c", "--constant", "CONSTANT",
|
||||
allow(@options).to receive(:on)
|
||||
expect(@options).to receive(:on).with("-c", "--constant", "CONSTANT",
|
||||
an_instance_of(String))
|
||||
@script.options []
|
||||
end
|
||||
|
@ -21,22 +21,22 @@ describe "The -c, --constant CONSTANT option" do
|
|||
["-c", "--constant"].each do |opt|
|
||||
@config[:constants] = []
|
||||
@script.options [opt, "Object"]
|
||||
@config[:constants].should include("Object")
|
||||
expect(@config[:constants]).to include("Object")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "The -b, --base DIR option" do
|
||||
RSpec.describe "The -b, --base DIR option" do
|
||||
before :each do
|
||||
@options = MSpecOptions.new
|
||||
MSpecOptions.stub(:new).and_return(@options)
|
||||
allow(MSpecOptions).to receive(:new).and_return(@options)
|
||||
@script = MkSpec.new
|
||||
@config = @script.config
|
||||
end
|
||||
|
||||
it "is enabled by #options" do
|
||||
@options.stub(:on)
|
||||
@options.should_receive(:on).with("-b", "--base", "DIR",
|
||||
allow(@options).to receive(:on)
|
||||
expect(@options).to receive(:on).with("-b", "--base", "DIR",
|
||||
an_instance_of(String))
|
||||
@script.options []
|
||||
end
|
||||
|
@ -45,22 +45,22 @@ describe "The -b, --base DIR option" do
|
|||
["-b", "--base"].each do |opt|
|
||||
@config[:base] = nil
|
||||
@script.options [opt, "superspec"]
|
||||
@config[:base].should == File.expand_path("superspec")
|
||||
expect(@config[:base]).to eq(File.expand_path("superspec"))
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "The -r, --require LIBRARY option" do
|
||||
RSpec.describe "The -r, --require LIBRARY option" do
|
||||
before :each do
|
||||
@options = MSpecOptions.new
|
||||
MSpecOptions.stub(:new).and_return(@options)
|
||||
allow(MSpecOptions).to receive(:new).and_return(@options)
|
||||
@script = MkSpec.new
|
||||
@config = @script.config
|
||||
end
|
||||
|
||||
it "is enabled by #options" do
|
||||
@options.stub(:on)
|
||||
@options.should_receive(:on).with("-r", "--require", "LIBRARY",
|
||||
allow(@options).to receive(:on)
|
||||
expect(@options).to receive(:on).with("-r", "--require", "LIBRARY",
|
||||
an_instance_of(String))
|
||||
@script.options []
|
||||
end
|
||||
|
@ -69,22 +69,22 @@ describe "The -r, --require LIBRARY option" do
|
|||
["-r", "--require"].each do |opt|
|
||||
@config[:requires] = []
|
||||
@script.options [opt, "libspec"]
|
||||
@config[:requires].should include("libspec")
|
||||
expect(@config[:requires]).to include("libspec")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "The -V, --version-guard VERSION option" do
|
||||
RSpec.describe "The -V, --version-guard VERSION option" do
|
||||
before :each do
|
||||
@options = MSpecOptions.new
|
||||
MSpecOptions.stub(:new).and_return(@options)
|
||||
allow(MSpecOptions).to receive(:new).and_return(@options)
|
||||
@script = MkSpec.new
|
||||
@config = @script.config
|
||||
end
|
||||
|
||||
it "is enabled by #options" do
|
||||
@options.stub(:on)
|
||||
@options.should_receive(:on).with("-V", "--version-guard", "VERSION",
|
||||
allow(@options).to receive(:on)
|
||||
expect(@options).to receive(:on).with("-V", "--version-guard", "VERSION",
|
||||
an_instance_of(String))
|
||||
@script.options []
|
||||
end
|
||||
|
@ -93,150 +93,150 @@ describe "The -V, --version-guard VERSION option" do
|
|||
["-r", "--require"].each do |opt|
|
||||
@config[:requires] = []
|
||||
@script.options [opt, "libspec"]
|
||||
@config[:requires].should include("libspec")
|
||||
expect(@config[:requires]).to include("libspec")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe MkSpec, "#options" do
|
||||
RSpec.describe MkSpec, "#options" do
|
||||
before :each do
|
||||
@options = MSpecOptions.new
|
||||
MSpecOptions.stub(:new).and_return(@options)
|
||||
allow(MSpecOptions).to receive(:new).and_return(@options)
|
||||
@script = MkSpec.new
|
||||
end
|
||||
|
||||
it "parses the command line options" do
|
||||
@options.should_receive(:parse).with(["--this", "and", "--that"])
|
||||
expect(@options).to receive(:parse).with(["--this", "and", "--that"])
|
||||
@script.options ["--this", "and", "--that"]
|
||||
end
|
||||
|
||||
it "parses ARGV unless passed other options" do
|
||||
@options.should_receive(:parse).with(ARGV)
|
||||
expect(@options).to receive(:parse).with(ARGV)
|
||||
@script.options
|
||||
end
|
||||
|
||||
it "prints help and exits if passed an unrecognized option" do
|
||||
@options.should_receive(:raise).with(MSpecOptions::ParseError, an_instance_of(String))
|
||||
@options.stub(:puts)
|
||||
@options.stub(:exit)
|
||||
expect(@options).to receive(:raise).with(MSpecOptions::ParseError, an_instance_of(String))
|
||||
allow(@options).to receive(:puts)
|
||||
allow(@options).to receive(:exit)
|
||||
@script.options ["--iunknown"]
|
||||
end
|
||||
end
|
||||
|
||||
describe MkSpec, "#create_directory" do
|
||||
RSpec.describe MkSpec, "#create_directory" do
|
||||
before :each do
|
||||
@script = MkSpec.new
|
||||
@script.config[:base] = "spec"
|
||||
end
|
||||
|
||||
it "prints a warning if a file with the directory name exists" do
|
||||
File.should_receive(:exist?).and_return(true)
|
||||
File.should_receive(:directory?).and_return(false)
|
||||
FileUtils.should_not_receive(:mkdir_p)
|
||||
@script.should_receive(:puts).with("spec/class already exists and is not a directory.")
|
||||
@script.create_directory("Class").should == nil
|
||||
expect(File).to receive(:exist?).and_return(true)
|
||||
expect(File).to receive(:directory?).and_return(false)
|
||||
expect(FileUtils).not_to receive(:mkdir_p)
|
||||
expect(@script).to receive(:puts).with("spec/class already exists and is not a directory.")
|
||||
expect(@script.create_directory("Class")).to eq(nil)
|
||||
end
|
||||
|
||||
it "does nothing if the directory already exists" do
|
||||
File.should_receive(:exist?).and_return(true)
|
||||
File.should_receive(:directory?).and_return(true)
|
||||
FileUtils.should_not_receive(:mkdir_p)
|
||||
@script.create_directory("Class").should == "spec/class"
|
||||
expect(File).to receive(:exist?).and_return(true)
|
||||
expect(File).to receive(:directory?).and_return(true)
|
||||
expect(FileUtils).not_to receive(:mkdir_p)
|
||||
expect(@script.create_directory("Class")).to eq("spec/class")
|
||||
end
|
||||
|
||||
it "creates the directory if it does not exist" do
|
||||
File.should_receive(:exist?).and_return(false)
|
||||
@script.should_receive(:mkdir_p).with("spec/class")
|
||||
@script.create_directory("Class").should == "spec/class"
|
||||
expect(File).to receive(:exist?).and_return(false)
|
||||
expect(@script).to receive(:mkdir_p).with("spec/class")
|
||||
expect(@script.create_directory("Class")).to eq("spec/class")
|
||||
end
|
||||
|
||||
it "creates the directory for a namespaced module if it does not exist" do
|
||||
File.should_receive(:exist?).and_return(false)
|
||||
@script.should_receive(:mkdir_p).with("spec/struct/tms")
|
||||
@script.create_directory("Struct::Tms").should == "spec/struct/tms"
|
||||
expect(File).to receive(:exist?).and_return(false)
|
||||
expect(@script).to receive(:mkdir_p).with("spec/struct/tms")
|
||||
expect(@script.create_directory("Struct::Tms")).to eq("spec/struct/tms")
|
||||
end
|
||||
end
|
||||
|
||||
describe MkSpec, "#write_requires" do
|
||||
RSpec.describe MkSpec, "#write_requires" do
|
||||
before :each do
|
||||
@script = MkSpec.new
|
||||
@script.config[:base] = "spec"
|
||||
|
||||
@file = double("file")
|
||||
File.stub(:open).and_yield(@file)
|
||||
allow(File).to receive(:open).and_yield(@file)
|
||||
end
|
||||
|
||||
it "writes the spec_helper require line" do
|
||||
@file.should_receive(:puts).with("require_relative '../../../spec_helper'")
|
||||
expect(@file).to receive(:puts).with("require_relative '../../../spec_helper'")
|
||||
@script.write_requires("spec/core/tcejbo", "spec/core/tcejbo/inspect_spec.rb")
|
||||
end
|
||||
|
||||
it "writes require lines for each library specified on the command line" do
|
||||
@file.stub(:puts)
|
||||
@file.should_receive(:puts).with("require_relative '../../../spec_helper'")
|
||||
@file.should_receive(:puts).with("require 'complex'")
|
||||
allow(@file).to receive(:puts)
|
||||
expect(@file).to receive(:puts).with("require_relative '../../../spec_helper'")
|
||||
expect(@file).to receive(:puts).with("require 'complex'")
|
||||
@script.config[:requires] << 'complex'
|
||||
@script.write_requires("spec/core/tcejbo", "spec/core/tcejbo/inspect_spec.rb")
|
||||
end
|
||||
end
|
||||
|
||||
describe MkSpec, "#write_spec" do
|
||||
RSpec.describe MkSpec, "#write_spec" do
|
||||
before :each do
|
||||
@file = IOStub.new
|
||||
File.stub(:open).and_yield(@file)
|
||||
allow(File).to receive(:open).and_yield(@file)
|
||||
|
||||
@script = MkSpec.new
|
||||
@script.stub(:puts)
|
||||
allow(@script).to receive(:puts)
|
||||
|
||||
@response = double("system command response")
|
||||
@response.stub(:include?).and_return(false)
|
||||
@script.stub(:`).and_return(@response)
|
||||
allow(@response).to receive(:include?).and_return(false)
|
||||
allow(@script).to receive(:`).and_return(@response)
|
||||
end
|
||||
|
||||
it "checks if specs exist for the method if the spec file exists" do
|
||||
name = Regexp.escape(@script.ruby)
|
||||
@script.should_receive(:`).with(
|
||||
expect(@script).to receive(:`).with(
|
||||
%r"#{name} #{MSPEC_HOME}/bin/mspec-run --dry-run --unguarded -fs -e 'Object#inspect' spec/core/tcejbo/inspect_spec.rb")
|
||||
@script.write_spec("spec/core/tcejbo/inspect_spec.rb", "Object#inspect", true)
|
||||
end
|
||||
|
||||
it "checks for the method name in the spec file output" do
|
||||
@response.should_receive(:include?).with("Array#[]=")
|
||||
expect(@response).to receive(:include?).with("Array#[]=")
|
||||
@script.write_spec("spec/core/yarra/element_set_spec.rb", "Array#[]=", true)
|
||||
end
|
||||
|
||||
it "returns nil if the spec file exists and contains a spec for the method" do
|
||||
@response.stub(:include?).and_return(true)
|
||||
@script.write_spec("spec/core/tcejbo/inspect_spec.rb", "Object#inspect", true).should == nil
|
||||
allow(@response).to receive(:include?).and_return(true)
|
||||
expect(@script.write_spec("spec/core/tcejbo/inspect_spec.rb", "Object#inspect", true)).to eq(nil)
|
||||
end
|
||||
|
||||
it "does not print the spec file name if it exists and contains a spec for the method" do
|
||||
@response.stub(:include?).and_return(true)
|
||||
@script.should_not_receive(:puts)
|
||||
allow(@response).to receive(:include?).and_return(true)
|
||||
expect(@script).not_to receive(:puts)
|
||||
@script.write_spec("spec/core/tcejbo/inspect_spec.rb", "Object#inspect", true)
|
||||
end
|
||||
|
||||
it "prints the spec file name if a template spec is written" do
|
||||
@script.should_receive(:puts).with("spec/core/tcejbo/inspect_spec.rb")
|
||||
expect(@script).to receive(:puts).with("spec/core/tcejbo/inspect_spec.rb")
|
||||
@script.write_spec("spec/core/tcejbo/inspect_spec.rb", "Object#inspect", true)
|
||||
end
|
||||
|
||||
it "writes a template spec to the file if the spec file does not exist" do
|
||||
@file.should_receive(:puts).twice
|
||||
@script.should_receive(:puts).with("spec/core/tcejbo/inspect_spec.rb")
|
||||
expect(@file).to receive(:puts).twice
|
||||
expect(@script).to receive(:puts).with("spec/core/tcejbo/inspect_spec.rb")
|
||||
@script.write_spec("spec/core/tcejbo/inspect_spec.rb", "Object#inspect", false)
|
||||
end
|
||||
|
||||
it "writes a template spec to the file if it exists but contains no spec for the method" do
|
||||
@response.should_receive(:include?).and_return(false)
|
||||
@file.should_receive(:puts).twice
|
||||
@script.should_receive(:puts).with("spec/core/tcejbo/inspect_spec.rb")
|
||||
expect(@response).to receive(:include?).and_return(false)
|
||||
expect(@file).to receive(:puts).twice
|
||||
expect(@script).to receive(:puts).with("spec/core/tcejbo/inspect_spec.rb")
|
||||
@script.write_spec("spec/core/tcejbo/inspect_spec.rb", "Object#inspect", true)
|
||||
end
|
||||
|
||||
it "writes a template spec" do
|
||||
@script.write_spec("spec/core/tcejbo/inspect_spec.rb", "Object#inspect", true)
|
||||
@file.should == <<EOS
|
||||
expect(@file).to eq <<EOS
|
||||
|
||||
describe "Object#inspect" do
|
||||
it "needs to be reviewed for spec completeness"
|
||||
|
@ -247,7 +247,7 @@ EOS
|
|||
it "writes a template spec with version guard" do
|
||||
@script.config[:version] = '""..."1.9"'
|
||||
@script.write_spec("spec/core/tcejbo/inspect_spec.rb", "Object#inspect", true)
|
||||
@file.should == <<EOS
|
||||
expect(@file).to eq <<EOS
|
||||
|
||||
ruby_version_is ""..."1.9" do
|
||||
describe "Object#inspect" do
|
||||
|
@ -259,105 +259,105 @@ EOS
|
|||
end
|
||||
end
|
||||
|
||||
describe MkSpec, "#create_file" do
|
||||
RSpec.describe MkSpec, "#create_file" do
|
||||
before :each do
|
||||
@script = MkSpec.new
|
||||
@script.stub(:write_requires)
|
||||
@script.stub(:write_spec)
|
||||
allow(@script).to receive(:write_requires)
|
||||
allow(@script).to receive(:write_spec)
|
||||
|
||||
File.stub(:exist?).and_return(false)
|
||||
allow(File).to receive(:exist?).and_return(false)
|
||||
end
|
||||
|
||||
it "generates a file name based on the directory, class/module, and method" do
|
||||
File.should_receive(:join).with("spec/tcejbo", "inspect_spec.rb"
|
||||
expect(File).to receive(:join).with("spec/tcejbo", "inspect_spec.rb"
|
||||
).and_return("spec/tcejbo/inspect_spec.rb")
|
||||
@script.create_file("spec/tcejbo", "Object", "inspect", "Object#inspect")
|
||||
end
|
||||
|
||||
it "does not call #write_requires if the spec file already exists" do
|
||||
File.should_receive(:exist?).and_return(true)
|
||||
@script.should_not_receive(:write_requires)
|
||||
expect(File).to receive(:exist?).and_return(true)
|
||||
expect(@script).not_to receive(:write_requires)
|
||||
@script.create_file("spec/tcejbo", "Object", "inspect", "Object#inspect")
|
||||
end
|
||||
|
||||
it "calls #write_requires if the spec file does not exist" do
|
||||
File.should_receive(:exist?).and_return(false)
|
||||
@script.should_receive(:write_requires).with(
|
||||
expect(File).to receive(:exist?).and_return(false)
|
||||
expect(@script).to receive(:write_requires).with(
|
||||
"spec/tcejbo", "spec/tcejbo/inspect_spec.rb")
|
||||
@script.create_file("spec/tcejbo", "Object", "inspect", "Object#inspect")
|
||||
end
|
||||
|
||||
it "calls #write_spec with the file, method name" do
|
||||
@script.should_receive(:write_spec).with(
|
||||
expect(@script).to receive(:write_spec).with(
|
||||
"spec/tcejbo/inspect_spec.rb", "Object#inspect", false)
|
||||
@script.create_file("spec/tcejbo", "Object", "inspect", "Object#inspect")
|
||||
end
|
||||
end
|
||||
|
||||
describe MkSpec, "#run" do
|
||||
RSpec.describe MkSpec, "#run" do
|
||||
before :each do
|
||||
@options = MSpecOptions.new
|
||||
MSpecOptions.stub(:new).and_return(@options)
|
||||
allow(MSpecOptions).to receive(:new).and_return(@options)
|
||||
|
||||
@map = NameMap.new
|
||||
NameMap.stub(:new).and_return(@map)
|
||||
allow(NameMap).to receive(:new).and_return(@map)
|
||||
|
||||
@script = MkSpec.new
|
||||
@script.stub(:create_directory).and_return("spec/mkspec")
|
||||
@script.stub(:create_file)
|
||||
allow(@script).to receive(:create_directory).and_return("spec/mkspec")
|
||||
allow(@script).to receive(:create_file)
|
||||
@script.config[:constants] = [MkSpec]
|
||||
end
|
||||
|
||||
it "loads files in the requires list" do
|
||||
@script.stub(:require)
|
||||
@script.should_receive(:require).with("alib")
|
||||
@script.should_receive(:require).with("blib")
|
||||
allow(@script).to receive(:require)
|
||||
expect(@script).to receive(:require).with("alib")
|
||||
expect(@script).to receive(:require).with("blib")
|
||||
@script.config[:requires] = ["alib", "blib"]
|
||||
@script.run
|
||||
end
|
||||
|
||||
it "creates a map of constants to methods" do
|
||||
@map.should_receive(:map).with({}, @script.config[:constants]).and_return({})
|
||||
expect(@map).to receive(:map).with({}, @script.config[:constants]).and_return({})
|
||||
@script.run
|
||||
end
|
||||
|
||||
it "calls #create_directory for each class/module in the map" do
|
||||
@script.should_receive(:create_directory).with("MkSpec").twice
|
||||
expect(@script).to receive(:create_directory).with("MkSpec").twice
|
||||
@script.run
|
||||
end
|
||||
|
||||
it "calls #create_file for each method on each class/module in the map" do
|
||||
@map.should_receive(:map).with({}, @script.config[:constants]
|
||||
expect(@map).to receive(:map).with({}, @script.config[:constants]
|
||||
).and_return({"MkSpec#" => ["run"]})
|
||||
@script.should_receive(:create_file).with("spec/mkspec", "MkSpec", "run", "MkSpec#run")
|
||||
expect(@script).to receive(:create_file).with("spec/mkspec", "MkSpec", "run", "MkSpec#run")
|
||||
@script.run
|
||||
end
|
||||
end
|
||||
|
||||
describe MkSpec, ".main" do
|
||||
RSpec.describe MkSpec, ".main" do
|
||||
before :each do
|
||||
@script = double("MkSpec").as_null_object
|
||||
MkSpec.stub(:new).and_return(@script)
|
||||
allow(MkSpec).to receive(:new).and_return(@script)
|
||||
end
|
||||
|
||||
it "sets MSPEC_RUNNER = '1' in the environment" do
|
||||
ENV["MSPEC_RUNNER"] = "0"
|
||||
MkSpec.main
|
||||
ENV["MSPEC_RUNNER"].should == "1"
|
||||
expect(ENV["MSPEC_RUNNER"]).to eq("1")
|
||||
end
|
||||
|
||||
it "creates an instance of MSpecScript" do
|
||||
MkSpec.should_receive(:new).and_return(@script)
|
||||
expect(MkSpec).to receive(:new).and_return(@script)
|
||||
MkSpec.main
|
||||
end
|
||||
|
||||
it "calls the #options method on the script" do
|
||||
@script.should_receive(:options)
|
||||
expect(@script).to receive(:options)
|
||||
MkSpec.main
|
||||
end
|
||||
|
||||
it "calls the #run method on the script" do
|
||||
@script.should_receive(:run)
|
||||
expect(@script).to receive(:run)
|
||||
MkSpec.main
|
||||
end
|
||||
end
|
||||
|
|
|
@ -3,148 +3,148 @@ require 'mspec/runner/mspec'
|
|||
require 'mspec/runner/filters/tag'
|
||||
require 'mspec/commands/mspec-ci'
|
||||
|
||||
describe MSpecCI, "#options" do
|
||||
RSpec.describe MSpecCI, "#options" do
|
||||
before :each do
|
||||
@options, @config = new_option
|
||||
MSpecOptions.stub(:new).and_return(@options)
|
||||
allow(MSpecOptions).to receive(:new).and_return(@options)
|
||||
|
||||
@script = MSpecCI.new
|
||||
@script.stub(:config).and_return(@config)
|
||||
@script.stub(:files).and_return([])
|
||||
allow(@script).to receive(:config).and_return(@config)
|
||||
allow(@script).to receive(:files).and_return([])
|
||||
end
|
||||
|
||||
it "enables the chdir option" do
|
||||
@options.should_receive(:chdir)
|
||||
expect(@options).to receive(:chdir)
|
||||
@script.options []
|
||||
end
|
||||
|
||||
it "enables the prefix option" do
|
||||
@options.should_receive(:prefix)
|
||||
expect(@options).to receive(:prefix)
|
||||
@script.options []
|
||||
end
|
||||
|
||||
it "enables the config option" do
|
||||
@options.should_receive(:configure)
|
||||
expect(@options).to receive(:configure)
|
||||
@script.options []
|
||||
end
|
||||
|
||||
it "provides a custom action (block) to the config option" do
|
||||
@script.should_receive(:load).with("cfg.mspec")
|
||||
expect(@script).to receive(:load).with("cfg.mspec")
|
||||
@script.options ["-B", "cfg.mspec"]
|
||||
end
|
||||
|
||||
it "enables the dry run option" do
|
||||
@options.should_receive(:pretend)
|
||||
expect(@options).to receive(:pretend)
|
||||
@script.options []
|
||||
end
|
||||
|
||||
it "enables the unguarded option" do
|
||||
@options.should_receive(:unguarded)
|
||||
expect(@options).to receive(:unguarded)
|
||||
@script.options []
|
||||
end
|
||||
|
||||
it "enables the interrupt single specs option" do
|
||||
@options.should_receive(:interrupt)
|
||||
expect(@options).to receive(:interrupt)
|
||||
@script.options []
|
||||
end
|
||||
|
||||
it "enables the formatter options" do
|
||||
@options.should_receive(:formatters)
|
||||
expect(@options).to receive(:formatters)
|
||||
@script.options []
|
||||
end
|
||||
|
||||
it "enables the verbose option" do
|
||||
@options.should_receive(:verbose)
|
||||
expect(@options).to receive(:verbose)
|
||||
@script.options []
|
||||
end
|
||||
|
||||
it "enables the action options" do
|
||||
@options.should_receive(:actions)
|
||||
expect(@options).to receive(:actions)
|
||||
@script.options []
|
||||
end
|
||||
|
||||
it "enables the action filter options" do
|
||||
@options.should_receive(:action_filters)
|
||||
expect(@options).to receive(:action_filters)
|
||||
@script.options []
|
||||
end
|
||||
|
||||
it "enables the version option" do
|
||||
@options.should_receive(:version)
|
||||
expect(@options).to receive(:version)
|
||||
@script.options []
|
||||
end
|
||||
|
||||
it "enables the help option" do
|
||||
@options.should_receive(:help)
|
||||
expect(@options).to receive(:help)
|
||||
@script.options []
|
||||
end
|
||||
|
||||
it "calls #custom_options" do
|
||||
@script.should_receive(:custom_options).with(@options)
|
||||
expect(@script).to receive(:custom_options).with(@options)
|
||||
@script.options []
|
||||
end
|
||||
end
|
||||
|
||||
describe MSpecCI, "#run" do
|
||||
RSpec.describe MSpecCI, "#run" do
|
||||
before :each do
|
||||
MSpec.stub(:process)
|
||||
allow(MSpec).to receive(:process)
|
||||
|
||||
@filter = double("TagFilter")
|
||||
TagFilter.stub(:new).and_return(@filter)
|
||||
@filter.stub(:register)
|
||||
allow(TagFilter).to receive(:new).and_return(@filter)
|
||||
allow(@filter).to receive(:register)
|
||||
|
||||
@tags = ["fails", "critical", "unstable", "incomplete", "unsupported"]
|
||||
|
||||
@config = { :ci_files => ["one", "two"] }
|
||||
@script = MSpecCI.new
|
||||
@script.stub(:exit)
|
||||
@script.stub(:config).and_return(@config)
|
||||
@script.stub(:files).and_return(["one", "two"])
|
||||
allow(@script).to receive(:exit)
|
||||
allow(@script).to receive(:config).and_return(@config)
|
||||
allow(@script).to receive(:files).and_return(["one", "two"])
|
||||
@script.options []
|
||||
end
|
||||
|
||||
it "registers the tags patterns" do
|
||||
@config[:tags_patterns] = [/spec/, "tags"]
|
||||
MSpec.should_receive(:register_tags_patterns).with([/spec/, "tags"])
|
||||
expect(MSpec).to receive(:register_tags_patterns).with([/spec/, "tags"])
|
||||
@script.run
|
||||
end
|
||||
|
||||
it "registers the files to process" do
|
||||
MSpec.should_receive(:register_files).with(["one", "two"])
|
||||
expect(MSpec).to receive(:register_files).with(["one", "two"])
|
||||
@script.run
|
||||
end
|
||||
|
||||
it "registers a tag filter for 'fails', 'unstable', 'incomplete', 'critical', 'unsupported'" do
|
||||
filter = double("fails filter")
|
||||
TagFilter.should_receive(:new).with(:exclude, *@tags).and_return(filter)
|
||||
filter.should_receive(:register)
|
||||
expect(TagFilter).to receive(:new).with(:exclude, *@tags).and_return(filter)
|
||||
expect(filter).to receive(:register)
|
||||
@script.run
|
||||
end
|
||||
|
||||
it "registers an additional exclude tag specified by :ci_xtags" do
|
||||
@config[:ci_xtags] = "windows"
|
||||
filter = double("fails filter")
|
||||
TagFilter.should_receive(:new).with(:exclude, *(@tags + ["windows"])).and_return(filter)
|
||||
filter.should_receive(:register)
|
||||
expect(TagFilter).to receive(:new).with(:exclude, *(@tags + ["windows"])).and_return(filter)
|
||||
expect(filter).to receive(:register)
|
||||
@script.run
|
||||
end
|
||||
|
||||
it "registers additional exclude tags specified by a :ci_xtags array" do
|
||||
@config[:ci_xtags] = ["windows", "windoze"]
|
||||
filter = double("fails filter")
|
||||
TagFilter.should_receive(:new).with(:exclude,
|
||||
expect(TagFilter).to receive(:new).with(:exclude,
|
||||
*(@tags + ["windows", "windoze"])).and_return(filter)
|
||||
filter.should_receive(:register)
|
||||
expect(filter).to receive(:register)
|
||||
@script.run
|
||||
end
|
||||
|
||||
it "processes the files" do
|
||||
MSpec.should_receive(:process)
|
||||
expect(MSpec).to receive(:process)
|
||||
@script.run
|
||||
end
|
||||
|
||||
it "exits with the exit code registered with MSpec" do
|
||||
MSpec.stub(:exit_code).and_return(7)
|
||||
@script.should_receive(:exit).with(7)
|
||||
allow(MSpec).to receive(:exit_code).and_return(7)
|
||||
expect(@script).to receive(:exit).with(7)
|
||||
@script.run
|
||||
end
|
||||
end
|
||||
|
|
|
@ -5,130 +5,130 @@ require 'mspec/commands/mspec-run'
|
|||
one_spec = File.expand_path(File.dirname(__FILE__)) + '/fixtures/one_spec.rb'
|
||||
two_spec = File.expand_path(File.dirname(__FILE__)) + '/fixtures/two_spec.rb'
|
||||
|
||||
describe MSpecRun, ".new" do
|
||||
RSpec.describe MSpecRun, ".new" do
|
||||
before :each do
|
||||
@script = MSpecRun.new
|
||||
end
|
||||
|
||||
it "sets config[:files] to an empty list" do
|
||||
@script.config[:files].should == []
|
||||
expect(@script.config[:files]).to eq([])
|
||||
end
|
||||
end
|
||||
|
||||
describe MSpecRun, "#options" do
|
||||
RSpec.describe MSpecRun, "#options" do
|
||||
before :each do
|
||||
@argv = [one_spec, two_spec]
|
||||
@options, @config = new_option
|
||||
MSpecOptions.stub(:new).and_return(@options)
|
||||
allow(MSpecOptions).to receive(:new).and_return(@options)
|
||||
|
||||
@script = MSpecRun.new
|
||||
@script.stub(:config).and_return(@config)
|
||||
allow(@script).to receive(:config).and_return(@config)
|
||||
end
|
||||
|
||||
it "enables the filter options" do
|
||||
@options.should_receive(:filters)
|
||||
expect(@options).to receive(:filters)
|
||||
@script.options @argv
|
||||
end
|
||||
|
||||
it "enables the chdir option" do
|
||||
@options.should_receive(:chdir)
|
||||
expect(@options).to receive(:chdir)
|
||||
@script.options @argv
|
||||
end
|
||||
|
||||
it "enables the prefix option" do
|
||||
@options.should_receive(:prefix)
|
||||
expect(@options).to receive(:prefix)
|
||||
@script.options @argv
|
||||
end
|
||||
|
||||
it "enables the configure option" do
|
||||
@options.should_receive(:configure)
|
||||
expect(@options).to receive(:configure)
|
||||
@script.options @argv
|
||||
end
|
||||
|
||||
it "provides a custom action (block) to the config option" do
|
||||
@script.should_receive(:load).with("cfg.mspec")
|
||||
expect(@script).to receive(:load).with("cfg.mspec")
|
||||
@script.options ["-B", "cfg.mspec", one_spec]
|
||||
end
|
||||
|
||||
it "enables the randomize option to runs specs in random order" do
|
||||
@options.should_receive(:randomize)
|
||||
expect(@options).to receive(:randomize)
|
||||
@script.options @argv
|
||||
end
|
||||
|
||||
it "enables the dry run option" do
|
||||
@options.should_receive(:pretend)
|
||||
expect(@options).to receive(:pretend)
|
||||
@script.options @argv
|
||||
end
|
||||
|
||||
it "enables the unguarded option" do
|
||||
@options.should_receive(:unguarded)
|
||||
expect(@options).to receive(:unguarded)
|
||||
@script.options @argv
|
||||
end
|
||||
|
||||
it "enables the interrupt single specs option" do
|
||||
@options.should_receive(:interrupt)
|
||||
expect(@options).to receive(:interrupt)
|
||||
@script.options @argv
|
||||
end
|
||||
|
||||
it "enables the formatter options" do
|
||||
@options.should_receive(:formatters)
|
||||
expect(@options).to receive(:formatters)
|
||||
@script.options @argv
|
||||
end
|
||||
|
||||
it "enables the verbose option" do
|
||||
@options.should_receive(:verbose)
|
||||
expect(@options).to receive(:verbose)
|
||||
@script.options @argv
|
||||
end
|
||||
|
||||
it "enables the verify options" do
|
||||
@options.should_receive(:verify)
|
||||
expect(@options).to receive(:verify)
|
||||
@script.options @argv
|
||||
end
|
||||
|
||||
it "enables the action options" do
|
||||
@options.should_receive(:actions)
|
||||
expect(@options).to receive(:actions)
|
||||
@script.options @argv
|
||||
end
|
||||
|
||||
it "enables the action filter options" do
|
||||
@options.should_receive(:action_filters)
|
||||
expect(@options).to receive(:action_filters)
|
||||
@script.options @argv
|
||||
end
|
||||
|
||||
it "enables the version option" do
|
||||
@options.should_receive(:version)
|
||||
expect(@options).to receive(:version)
|
||||
@script.options @argv
|
||||
end
|
||||
|
||||
it "enables the help option" do
|
||||
@options.should_receive(:help)
|
||||
expect(@options).to receive(:help)
|
||||
@script.options @argv
|
||||
end
|
||||
|
||||
it "exits if there are no files to process and './spec' is not a directory" do
|
||||
File.should_receive(:directory?).with("./spec").and_return(false)
|
||||
@options.should_receive(:parse).and_return([])
|
||||
@script.should_receive(:abort).with("No files specified.")
|
||||
expect(File).to receive(:directory?).with("./spec").and_return(false)
|
||||
expect(@options).to receive(:parse).and_return([])
|
||||
expect(@script).to receive(:abort).with("No files specified.")
|
||||
@script.options
|
||||
end
|
||||
|
||||
it "process 'spec/' if it is a directory and no files were specified" do
|
||||
File.should_receive(:directory?).with("./spec").and_return(true)
|
||||
@options.should_receive(:parse).and_return([])
|
||||
@script.should_receive(:files).with(["spec/"]).and_return(["spec/a_spec.rb"])
|
||||
expect(File).to receive(:directory?).with("./spec").and_return(true)
|
||||
expect(@options).to receive(:parse).and_return([])
|
||||
expect(@script).to receive(:files).with(["spec/"]).and_return(["spec/a_spec.rb"])
|
||||
@script.options
|
||||
end
|
||||
|
||||
it "calls #custom_options" do
|
||||
@script.should_receive(:custom_options).with(@options)
|
||||
expect(@script).to receive(:custom_options).with(@options)
|
||||
@script.options @argv
|
||||
end
|
||||
end
|
||||
|
||||
describe MSpecRun, "#run" do
|
||||
RSpec.describe MSpecRun, "#run" do
|
||||
before :each do
|
||||
@script = MSpecRun.new
|
||||
@script.stub(:exit)
|
||||
allow(@script).to receive(:exit)
|
||||
@spec_dir = File.expand_path(File.dirname(__FILE__)+"/fixtures")
|
||||
@file_patterns = [
|
||||
@spec_dir+"/level2",
|
||||
|
@ -139,35 +139,35 @@ describe MSpecRun, "#run" do
|
|||
@spec_dir+"/one_spec.rb",
|
||||
@spec_dir+"/two_spec.rb"]
|
||||
@script.options @file_patterns
|
||||
MSpec.stub :process
|
||||
allow(MSpec).to receive :process
|
||||
end
|
||||
|
||||
it "registers the tags patterns" do
|
||||
@script.config[:tags_patterns] = [/spec/, "tags"]
|
||||
MSpec.should_receive(:register_tags_patterns).with([/spec/, "tags"])
|
||||
expect(MSpec).to receive(:register_tags_patterns).with([/spec/, "tags"])
|
||||
@script.run
|
||||
end
|
||||
|
||||
it "registers the files to process" do
|
||||
MSpec.should_receive(:register_files).with(@files)
|
||||
expect(MSpec).to receive(:register_files).with(@files)
|
||||
@script.run
|
||||
end
|
||||
|
||||
it "uses config[:files] if no files are given on the command line" do
|
||||
@script.config[:files] = @file_patterns
|
||||
MSpec.should_receive(:register_files).with(@files)
|
||||
expect(MSpec).to receive(:register_files).with(@files)
|
||||
@script.options []
|
||||
@script.run
|
||||
end
|
||||
|
||||
it "processes the files" do
|
||||
MSpec.should_receive(:process)
|
||||
expect(MSpec).to receive(:process)
|
||||
@script.run
|
||||
end
|
||||
|
||||
it "exits with the exit code registered with MSpec" do
|
||||
MSpec.stub(:exit_code).and_return(7)
|
||||
@script.should_receive(:exit).with(7)
|
||||
allow(MSpec).to receive(:exit_code).and_return(7)
|
||||
expect(@script).to receive(:exit).with(7)
|
||||
@script.run
|
||||
end
|
||||
end
|
||||
|
|
|
@ -2,55 +2,55 @@ require 'spec_helper'
|
|||
require 'yaml'
|
||||
require 'mspec/commands/mspec'
|
||||
|
||||
describe MSpecMain, "#options" do
|
||||
RSpec.describe MSpecMain, "#options" do
|
||||
before :each do
|
||||
@options, @config = new_option
|
||||
MSpecOptions.stub(:new).and_return(@options)
|
||||
allow(MSpecOptions).to receive(:new).and_return(@options)
|
||||
|
||||
@script = MSpecMain.new
|
||||
@script.stub(:config).and_return(@config)
|
||||
@script.stub(:load)
|
||||
allow(@script).to receive(:config).and_return(@config)
|
||||
allow(@script).to receive(:load)
|
||||
end
|
||||
|
||||
it "enables the configure option" do
|
||||
@options.should_receive(:configure)
|
||||
expect(@options).to receive(:configure)
|
||||
@script.options
|
||||
end
|
||||
|
||||
it "provides a custom action (block) to the config option" do
|
||||
@script.options ["-B", "config"]
|
||||
@config[:options].should include("-B", "config")
|
||||
expect(@config[:options]).to include("-B", "config")
|
||||
end
|
||||
|
||||
it "loads the file specified by the config option" do
|
||||
@script.should_receive(:load).with("config")
|
||||
expect(@script).to receive(:load).with("config")
|
||||
@script.options ["-B", "config"]
|
||||
end
|
||||
|
||||
it "enables the target options" do
|
||||
@options.should_receive(:targets)
|
||||
expect(@options).to receive(:targets)
|
||||
@script.options
|
||||
end
|
||||
|
||||
it "sets config[:options] to all argv entries that are not registered options" do
|
||||
@options.on "-X", "--exclude", "ARG", "description"
|
||||
@script.options [".", "-G", "fail", "-X", "ARG", "--list", "unstable", "some/file.rb"]
|
||||
@config[:options].should == [".", "-G", "fail", "--list", "unstable", "some/file.rb"]
|
||||
expect(@config[:options]).to eq([".", "-G", "fail", "--list", "unstable", "some/file.rb"])
|
||||
end
|
||||
|
||||
it "calls #custom_options" do
|
||||
@script.should_receive(:custom_options).with(@options)
|
||||
expect(@script).to receive(:custom_options).with(@options)
|
||||
@script.options
|
||||
end
|
||||
end
|
||||
|
||||
describe MSpecMain, "#run" do
|
||||
RSpec.describe MSpecMain, "#run" do
|
||||
before :each do
|
||||
@options, @config = new_option
|
||||
MSpecOptions.stub(:new).and_return(@options)
|
||||
allow(MSpecOptions).to receive(:new).and_return(@options)
|
||||
@script = MSpecMain.new
|
||||
@script.stub(:config).and_return(@config)
|
||||
@script.stub(:exec)
|
||||
allow(@script).to receive(:config).and_return(@config)
|
||||
allow(@script).to receive(:exec)
|
||||
@err = $stderr
|
||||
$stderr = IOStub.new
|
||||
end
|
||||
|
@ -60,76 +60,76 @@ 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", close_others: false)
|
||||
expect(@script).to 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", close_others: false)
|
||||
expect(@script).to 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"
|
||||
expect($stderr.to_s).to eq("$ ruby #{Dir.pwd}/bin/mspec-run\n")
|
||||
end
|
||||
|
||||
it "adds config[:launch] to the exec options" do
|
||||
@script.should_receive(:exec).with("ruby",
|
||||
expect(@script).to receive(:exec).with("ruby",
|
||||
"-Xlaunch.option", "#{MSPEC_HOME}/bin/mspec-run", close_others: false)
|
||||
@config[:launch] << "-Xlaunch.option"
|
||||
@script.options []
|
||||
@script.run
|
||||
$stderr.to_s.should == "$ ruby -Xlaunch.option #{Dir.pwd}/bin/mspec-run\n"
|
||||
expect($stderr.to_s).to eq("$ ruby -Xlaunch.option #{Dir.pwd}/bin/mspec-run\n")
|
||||
end
|
||||
|
||||
it "calls #multi_exec if the command is 'ci' and the multi option is passed" do
|
||||
@script.should_receive(:multi_exec).and_return do |argv|
|
||||
argv.should == ["ruby", "#{MSPEC_HOME}/bin/mspec-ci"]
|
||||
expect(@script).to receive(:multi_exec) do |argv|
|
||||
expect(argv).to eq(["ruby", "#{MSPEC_HOME}/bin/mspec-ci"])
|
||||
end
|
||||
@script.options ["ci", "-j"]
|
||||
lambda do
|
||||
expect do
|
||||
@script.run
|
||||
end.should raise_error(SystemExit)
|
||||
end.to raise_error(SystemExit)
|
||||
end
|
||||
end
|
||||
|
||||
describe "The --warnings option" do
|
||||
RSpec.describe "The --warnings option" do
|
||||
before :each do
|
||||
@options, @config = new_option
|
||||
MSpecOptions.stub(:new).and_return(@options)
|
||||
allow(MSpecOptions).to receive(:new).and_return(@options)
|
||||
@script = MSpecMain.new
|
||||
@script.stub(:config).and_return(@config)
|
||||
allow(@script).to receive(:config).and_return(@config)
|
||||
end
|
||||
|
||||
it "is enabled by #options" do
|
||||
@options.stub(:on)
|
||||
@options.should_receive(:on).with("--warnings", an_instance_of(String))
|
||||
allow(@options).to receive(:on)
|
||||
expect(@options).to receive(:on).with("--warnings", an_instance_of(String))
|
||||
@script.options
|
||||
end
|
||||
|
||||
it "sets flags to -w" do
|
||||
@config[:flags] = []
|
||||
@script.options ["--warnings"]
|
||||
@config[:flags].should include("-w")
|
||||
expect(@config[:flags]).to include("-w")
|
||||
end
|
||||
|
||||
it "set OUTPUT_WARNINGS = '1' in the environment" do
|
||||
ENV['OUTPUT_WARNINGS'] = '0'
|
||||
@script.options ["--warnings"]
|
||||
ENV['OUTPUT_WARNINGS'].should == '1'
|
||||
expect(ENV['OUTPUT_WARNINGS']).to eq('1')
|
||||
end
|
||||
end
|
||||
|
||||
describe "The -j, --multi option" do
|
||||
RSpec.describe "The -j, --multi option" do
|
||||
before :each do
|
||||
@options, @config = new_option
|
||||
MSpecOptions.stub(:new).and_return(@options)
|
||||
allow(MSpecOptions).to receive(:new).and_return(@options)
|
||||
@script = MSpecMain.new
|
||||
@script.stub(:config).and_return(@config)
|
||||
allow(@script).to receive(:config).and_return(@config)
|
||||
end
|
||||
|
||||
it "is enabled by #options" do
|
||||
@options.stub(:on)
|
||||
@options.should_receive(:on).with("-j", "--multi", an_instance_of(String))
|
||||
allow(@options).to receive(:on)
|
||||
expect(@options).to receive(:on).with("-j", "--multi", an_instance_of(String))
|
||||
@script.options
|
||||
end
|
||||
|
||||
|
@ -137,22 +137,22 @@ describe "The -j, --multi option" do
|
|||
["-j", "--multi"].each do |opt|
|
||||
@config[:multi] = nil
|
||||
@script.options [opt]
|
||||
@config[:multi].should == true
|
||||
expect(@config[:multi]).to eq(true)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "The -h, --help option" do
|
||||
RSpec.describe "The -h, --help option" do
|
||||
before :each do
|
||||
@options, @config = new_option
|
||||
MSpecOptions.stub(:new).and_return(@options)
|
||||
allow(MSpecOptions).to receive(:new).and_return(@options)
|
||||
@script = MSpecMain.new
|
||||
@script.stub(:config).and_return(@config)
|
||||
allow(@script).to receive(:config).and_return(@config)
|
||||
end
|
||||
|
||||
it "is enabled by #options" do
|
||||
@options.stub(:on)
|
||||
@options.should_receive(:on).with("-h", "--help", an_instance_of(String))
|
||||
allow(@options).to receive(:on)
|
||||
expect(@options).to receive(:on).with("-h", "--help", an_instance_of(String))
|
||||
@script.options
|
||||
end
|
||||
|
||||
|
@ -160,30 +160,30 @@ describe "The -h, --help option" do
|
|||
["-h", "--help"].each do |opt|
|
||||
@config[:options] = []
|
||||
@script.options ["ci", opt]
|
||||
@config[:options].sort.should == ["-h"]
|
||||
expect(@config[:options].sort).to eq(["-h"])
|
||||
end
|
||||
end
|
||||
|
||||
it "prints help and exits" do
|
||||
@script.should_receive(:puts).twice
|
||||
@script.should_receive(:exit).twice
|
||||
expect(@script).to receive(:puts).twice
|
||||
expect(@script).to receive(:exit).twice
|
||||
["-h", "--help"].each do |opt|
|
||||
@script.options [opt]
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "The -v, --version option" do
|
||||
RSpec.describe "The -v, --version option" do
|
||||
before :each do
|
||||
@options, @config = new_option
|
||||
MSpecOptions.stub(:new).and_return(@options)
|
||||
allow(MSpecOptions).to receive(:new).and_return(@options)
|
||||
@script = MSpecMain.new
|
||||
@script.stub(:config).and_return(@config)
|
||||
allow(@script).to receive(:config).and_return(@config)
|
||||
end
|
||||
|
||||
it "is enabled by #options" do
|
||||
@options.stub(:on)
|
||||
@options.should_receive(:on).with("-v", "--version", an_instance_of(String))
|
||||
allow(@options).to receive(:on)
|
||||
expect(@options).to receive(:on).with("-v", "--version", an_instance_of(String))
|
||||
@script.options
|
||||
end
|
||||
|
||||
|
@ -191,15 +191,15 @@ describe "The -v, --version option" do
|
|||
["-v", "--version"].each do |opt|
|
||||
@config[:options] = []
|
||||
@script.options ["ci", opt]
|
||||
@config[:options].sort.should == ["-v"]
|
||||
expect(@config[:options].sort).to eq(["-v"])
|
||||
end
|
||||
end
|
||||
|
||||
it "prints the version and exits if no subscript is invoked" do
|
||||
@config[:command] = nil
|
||||
File.stub(:basename).and_return("mspec")
|
||||
@script.should_receive(:puts).twice.with("mspec #{MSpec::VERSION}")
|
||||
@script.should_receive(:exit).twice
|
||||
allow(File).to receive(:basename).and_return("mspec")
|
||||
expect(@script).to receive(:puts).twice.with("mspec #{MSpec::VERSION}")
|
||||
expect(@script).to receive(:exit).twice
|
||||
["-v", "--version"].each do |opt|
|
||||
@script.options [opt]
|
||||
end
|
||||
|
|
|
@ -8,13 +8,13 @@ require 'mspec/runner/actions/tagpurge'
|
|||
one_spec = File.expand_path(File.dirname(__FILE__)) + '/fixtures/one_spec.rb'
|
||||
two_spec = File.expand_path(File.dirname(__FILE__)) + '/fixtures/two_spec.rb'
|
||||
|
||||
describe MSpecTag, ".new" do
|
||||
RSpec.describe MSpecTag, ".new" do
|
||||
before :each do
|
||||
@script = MSpecTag.new
|
||||
end
|
||||
|
||||
it "sets config[:ltags] to an empty list" do
|
||||
@script.config[:ltags].should == []
|
||||
expect(@script.config[:ltags]).to eq([])
|
||||
end
|
||||
|
||||
it "sets config[:tagger] to :add" do
|
||||
|
@ -30,16 +30,16 @@ describe MSpecTag, ".new" do
|
|||
end
|
||||
end
|
||||
|
||||
describe MSpecTag, "#options" do
|
||||
RSpec.describe MSpecTag, "#options" do
|
||||
before :each do
|
||||
@stdout, $stdout = $stdout, IOStub.new
|
||||
|
||||
@argv = [one_spec, two_spec]
|
||||
@options, @config = new_option
|
||||
MSpecOptions.stub(:new).and_return(@options)
|
||||
allow(MSpecOptions).to receive(:new).and_return(@options)
|
||||
|
||||
@script = MSpecTag.new
|
||||
@script.stub(:config).and_return(@config)
|
||||
allow(@script).to receive(:config).and_return(@config)
|
||||
end
|
||||
|
||||
after :each do
|
||||
|
@ -47,80 +47,80 @@ describe MSpecTag, "#options" do
|
|||
end
|
||||
|
||||
it "enables the filter options" do
|
||||
@options.should_receive(:filters)
|
||||
expect(@options).to receive(:filters)
|
||||
@script.options @argv
|
||||
end
|
||||
|
||||
it "enables the configure option" do
|
||||
@options.should_receive(:configure)
|
||||
expect(@options).to receive(:configure)
|
||||
@script.options @argv
|
||||
end
|
||||
|
||||
it "provides a custom action (block) to the config option" do
|
||||
@script.should_receive(:load).with("cfg.mspec")
|
||||
expect(@script).to receive(:load).with("cfg.mspec")
|
||||
@script.options ["-B", "cfg.mspec", one_spec]
|
||||
end
|
||||
|
||||
it "enables the dry run option" do
|
||||
@options.should_receive(:pretend)
|
||||
expect(@options).to receive(:pretend)
|
||||
@script.options @argv
|
||||
end
|
||||
|
||||
it "enables the unguarded option" do
|
||||
@options.should_receive(:unguarded)
|
||||
expect(@options).to receive(:unguarded)
|
||||
@script.options @argv
|
||||
end
|
||||
|
||||
it "enables the interrupt single specs option" do
|
||||
@options.should_receive(:interrupt)
|
||||
expect(@options).to receive(:interrupt)
|
||||
@script.options @argv
|
||||
end
|
||||
|
||||
it "enables the formatter options" do
|
||||
@options.should_receive(:formatters)
|
||||
expect(@options).to receive(:formatters)
|
||||
@script.options @argv
|
||||
end
|
||||
|
||||
it "enables the verbose option" do
|
||||
@options.should_receive(:verbose)
|
||||
expect(@options).to receive(:verbose)
|
||||
@script.options @argv
|
||||
end
|
||||
|
||||
it "enables the version option" do
|
||||
@options.should_receive(:version)
|
||||
expect(@options).to receive(:version)
|
||||
@script.options @argv
|
||||
end
|
||||
|
||||
it "enables the help option" do
|
||||
@options.should_receive(:help)
|
||||
expect(@options).to receive(:help)
|
||||
@script.options @argv
|
||||
end
|
||||
|
||||
it "calls #custom_options" do
|
||||
@script.should_receive(:custom_options).with(@options)
|
||||
expect(@script).to receive(:custom_options).with(@options)
|
||||
@script.options @argv
|
||||
end
|
||||
|
||||
it "exits if there are no files to process" do
|
||||
@options.should_receive(:parse).and_return([])
|
||||
@script.should_receive(:exit)
|
||||
expect(@options).to receive(:parse).and_return([])
|
||||
expect(@script).to receive(:exit)
|
||||
@script.options
|
||||
$stdout.should include "No files specified"
|
||||
expect($stdout.to_s).to include "No files specified"
|
||||
end
|
||||
end
|
||||
|
||||
describe MSpecTag, "options" do
|
||||
RSpec.describe MSpecTag, "options" do
|
||||
before :each do
|
||||
@options, @config = new_option
|
||||
MSpecOptions.stub(:new).and_return(@options)
|
||||
allow(MSpecOptions).to receive(:new).and_return(@options)
|
||||
@script = MSpecTag.new
|
||||
@script.stub(:config).and_return(@config)
|
||||
allow(@script).to receive(:config).and_return(@config)
|
||||
end
|
||||
|
||||
describe "-N, --add TAG" do
|
||||
it "is enabled with #options" do
|
||||
@options.stub(:on)
|
||||
@options.should_receive(:on).with("-N", "--add", "TAG", an_instance_of(String))
|
||||
allow(@options).to receive(:on)
|
||||
expect(@options).to receive(:on).with("-N", "--add", "TAG", an_instance_of(String))
|
||||
@script.options [one_spec]
|
||||
end
|
||||
|
||||
|
@ -129,16 +129,16 @@ describe MSpecTag, "options" do
|
|||
@config[:tagger] = nil
|
||||
@config[:tag] = nil
|
||||
@script.options [opt, "taggit", one_spec]
|
||||
@config[:tagger].should == :add
|
||||
@config[:tag].should == "taggit:"
|
||||
expect(@config[:tagger]).to eq(:add)
|
||||
expect(@config[:tag]).to eq("taggit:")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "-R, --del TAG" do
|
||||
it "is enabled with #options" do
|
||||
@options.stub(:on)
|
||||
@options.should_receive(:on).with("-R", "--del", "TAG",
|
||||
allow(@options).to receive(:on)
|
||||
expect(@options).to receive(:on).with("-R", "--del", "TAG",
|
||||
an_instance_of(String))
|
||||
@script.options [one_spec]
|
||||
end
|
||||
|
@ -149,17 +149,17 @@ describe MSpecTag, "options" do
|
|||
@config[:tag] = nil
|
||||
@config[:outcome] = nil
|
||||
@script.options [opt, "taggit", one_spec]
|
||||
@config[:tagger].should == :del
|
||||
@config[:tag].should == "taggit:"
|
||||
@config[:outcome].should == :pass
|
||||
expect(@config[:tagger]).to eq(:del)
|
||||
expect(@config[:tag]).to eq("taggit:")
|
||||
expect(@config[:outcome]).to eq(:pass)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "-Q, --pass" do
|
||||
it "is enabled with #options" do
|
||||
@options.stub(:on)
|
||||
@options.should_receive(:on).with("-Q", "--pass", an_instance_of(String))
|
||||
allow(@options).to receive(:on)
|
||||
expect(@options).to receive(:on).with("-Q", "--pass", an_instance_of(String))
|
||||
@script.options [one_spec]
|
||||
end
|
||||
|
||||
|
@ -167,15 +167,15 @@ describe MSpecTag, "options" do
|
|||
["-Q", "--pass"].each do |opt|
|
||||
@config[:outcome] = nil
|
||||
@script.options [opt, one_spec]
|
||||
@config[:outcome].should == :pass
|
||||
expect(@config[:outcome]).to eq(:pass)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "-F, --fail" do
|
||||
it "is enabled with #options" do
|
||||
@options.stub(:on)
|
||||
@options.should_receive(:on).with("-F", "--fail", an_instance_of(String))
|
||||
allow(@options).to receive(:on)
|
||||
expect(@options).to receive(:on).with("-F", "--fail", an_instance_of(String))
|
||||
@script.options [one_spec]
|
||||
end
|
||||
|
||||
|
@ -183,15 +183,15 @@ describe MSpecTag, "options" do
|
|||
["-F", "--fail"].each do |opt|
|
||||
@config[:outcome] = nil
|
||||
@script.options [opt, one_spec]
|
||||
@config[:outcome].should == :fail
|
||||
expect(@config[:outcome]).to eq(:fail)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "-L, --all" do
|
||||
it "is enabled with #options" do
|
||||
@options.stub(:on)
|
||||
@options.should_receive(:on).with("-L", "--all", an_instance_of(String))
|
||||
allow(@options).to receive(:on)
|
||||
expect(@options).to receive(:on).with("-L", "--all", an_instance_of(String))
|
||||
@script.options [one_spec]
|
||||
end
|
||||
|
||||
|
@ -199,100 +199,100 @@ describe MSpecTag, "options" do
|
|||
["-L", "--all"].each do |opt|
|
||||
@config[:outcome] = nil
|
||||
@script.options [opt, one_spec]
|
||||
@config[:outcome].should == :all
|
||||
expect(@config[:outcome]).to eq(:all)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "--list TAG" do
|
||||
it "is enabled with #options" do
|
||||
@options.stub(:on)
|
||||
@options.should_receive(:on).with("--list", "TAG", an_instance_of(String))
|
||||
allow(@options).to receive(:on)
|
||||
expect(@options).to receive(:on).with("--list", "TAG", an_instance_of(String))
|
||||
@script.options [one_spec]
|
||||
end
|
||||
|
||||
it "sets the mode to :list" do
|
||||
@config[:tagger] = nil
|
||||
@script.options ["--list", "TAG", one_spec]
|
||||
@config[:tagger].should == :list
|
||||
expect(@config[:tagger]).to eq(:list)
|
||||
end
|
||||
|
||||
it "sets ltags to include TAG" do
|
||||
@config[:tag] = nil
|
||||
@script.options ["--list", "TAG", one_spec]
|
||||
@config[:ltags].should == ["TAG"]
|
||||
expect(@config[:ltags]).to eq(["TAG"])
|
||||
end
|
||||
end
|
||||
|
||||
describe "--list-all" do
|
||||
it "is enabled with #options" do
|
||||
@options.stub(:on)
|
||||
@options.should_receive(:on).with("--list-all", an_instance_of(String))
|
||||
allow(@options).to receive(:on)
|
||||
expect(@options).to receive(:on).with("--list-all", an_instance_of(String))
|
||||
@script.options [one_spec]
|
||||
end
|
||||
|
||||
it "sets the mode to :list_all" do
|
||||
@config[:tagger] = nil
|
||||
@script.options ["--list-all", one_spec]
|
||||
@config[:tagger].should == :list_all
|
||||
expect(@config[:tagger]).to eq(:list_all)
|
||||
end
|
||||
end
|
||||
|
||||
describe "--purge" do
|
||||
it "is enabled with #options" do
|
||||
@options.stub(:on)
|
||||
@options.should_receive(:on).with("--purge", an_instance_of(String))
|
||||
allow(@options).to receive(:on)
|
||||
expect(@options).to receive(:on).with("--purge", an_instance_of(String))
|
||||
@script.options [one_spec]
|
||||
end
|
||||
|
||||
it "sets the mode to :purge" do
|
||||
@config[:tagger] = nil
|
||||
@script.options ["--purge", one_spec]
|
||||
@config[:tagger].should == :purge
|
||||
expect(@config[:tagger]).to eq(:purge)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe MSpecTag, "#run" do
|
||||
RSpec.describe MSpecTag, "#run" do
|
||||
before :each do
|
||||
MSpec.stub(:process)
|
||||
allow(MSpec).to receive(:process)
|
||||
|
||||
options = double("MSpecOptions").as_null_object
|
||||
options.stub(:parse).and_return(["one", "two"])
|
||||
MSpecOptions.stub(:new).and_return(options)
|
||||
allow(options).to receive(:parse).and_return(["one", "two"])
|
||||
allow(MSpecOptions).to receive(:new).and_return(options)
|
||||
|
||||
@config = { }
|
||||
@script = MSpecTag.new
|
||||
@script.stub(:exit)
|
||||
@script.stub(:config).and_return(@config)
|
||||
@script.stub(:files).and_return(["one", "two"])
|
||||
allow(@script).to receive(:exit)
|
||||
allow(@script).to receive(:config).and_return(@config)
|
||||
allow(@script).to receive(:files).and_return(["one", "two"])
|
||||
@script.options
|
||||
end
|
||||
|
||||
it "registers the tags patterns" do
|
||||
@config[:tags_patterns] = [/spec/, "tags"]
|
||||
MSpec.should_receive(:register_tags_patterns).with([/spec/, "tags"])
|
||||
expect(MSpec).to receive(:register_tags_patterns).with([/spec/, "tags"])
|
||||
@script.run
|
||||
end
|
||||
|
||||
it "registers the files to process" do
|
||||
MSpec.should_receive(:register_files).with(["one", "two"])
|
||||
expect(MSpec).to receive(:register_files).with(["one", "two"])
|
||||
@script.run
|
||||
end
|
||||
|
||||
it "processes the files" do
|
||||
MSpec.should_receive(:process)
|
||||
expect(MSpec).to receive(:process)
|
||||
@script.run
|
||||
end
|
||||
|
||||
it "exits with the exit code registered with MSpec" do
|
||||
MSpec.stub(:exit_code).and_return(7)
|
||||
@script.should_receive(:exit).with(7)
|
||||
allow(MSpec).to receive(:exit_code).and_return(7)
|
||||
expect(@script).to receive(:exit).with(7)
|
||||
@script.run
|
||||
end
|
||||
end
|
||||
|
||||
describe MSpecTag, "#register" do
|
||||
RSpec.describe MSpecTag, "#register" do
|
||||
before :each do
|
||||
@script = MSpecTag.new
|
||||
@config = @script.config
|
||||
|
@ -301,19 +301,19 @@ describe MSpecTag, "#register" do
|
|||
@config[:astrings] = []
|
||||
@config[:ltags] = ["fails", "unstable"]
|
||||
|
||||
@script.stub(:files).and_return([])
|
||||
allow(@script).to receive(:files).and_return([])
|
||||
@script.options "fake"
|
||||
|
||||
@t = double("TagAction")
|
||||
@t.stub(:register)
|
||||
allow(@t).to receive(:register)
|
||||
|
||||
@tl = double("TagListAction")
|
||||
@tl.stub(:register)
|
||||
allow(@tl).to receive(:register)
|
||||
end
|
||||
|
||||
it "raises an ArgumentError if no recognized action is given" do
|
||||
@config[:tagger] = :totally_whack
|
||||
lambda { @script.register }.should raise_error(ArgumentError)
|
||||
expect { @script.register }.to raise_error(ArgumentError)
|
||||
end
|
||||
|
||||
describe "when config[:tagger] is the default (:add)" do
|
||||
|
@ -322,93 +322,93 @@ describe MSpecTag, "#register" do
|
|||
end
|
||||
|
||||
it "creates a TagAction" do
|
||||
TagAction.should_receive(:new).and_return(@t)
|
||||
expect(TagAction).to receive(:new).and_return(@t)
|
||||
@script.register
|
||||
end
|
||||
|
||||
it "creates a TagAction if config[:tagger] is :del" do
|
||||
@config[:tagger] = :del
|
||||
@config[:outcome] = :pass
|
||||
TagAction.should_receive(:new).with(:del, :pass, "fake", nil, [], []).and_return(@t)
|
||||
expect(TagAction).to receive(:new).with(:del, :pass, "fake", nil, [], []).and_return(@t)
|
||||
@script.register
|
||||
end
|
||||
|
||||
it "calls #register on the TagAction instance" do
|
||||
TagAction.should_receive(:new).and_return(@t)
|
||||
@t.should_receive(:register)
|
||||
expect(TagAction).to receive(:new).and_return(@t)
|
||||
expect(@t).to receive(:register)
|
||||
@script.register
|
||||
end
|
||||
end
|
||||
|
||||
describe "when config[:tagger] is :list" do
|
||||
before :each do
|
||||
TagListAction.should_receive(:new).with(@config[:ltags]).and_return(@tl)
|
||||
expect(TagListAction).to receive(:new).with(@config[:ltags]).and_return(@tl)
|
||||
@config[:tagger] = :list
|
||||
end
|
||||
|
||||
it "creates a TagListAction" do
|
||||
@tl.should_receive(:register)
|
||||
expect(@tl).to receive(:register)
|
||||
@script.register
|
||||
end
|
||||
|
||||
it "registers MSpec pretend mode" do
|
||||
MSpec.should_receive(:register_mode).with(:pretend)
|
||||
expect(MSpec).to receive(:register_mode).with(:pretend)
|
||||
@script.register
|
||||
end
|
||||
|
||||
it "sets config[:formatter] to false" do
|
||||
@script.register
|
||||
@config[:formatter].should be_false
|
||||
expect(@config[:formatter]).to be_falsey
|
||||
end
|
||||
end
|
||||
|
||||
describe "when config[:tagger] is :list_all" do
|
||||
before :each do
|
||||
TagListAction.should_receive(:new).with(nil).and_return(@tl)
|
||||
expect(TagListAction).to receive(:new).with(nil).and_return(@tl)
|
||||
@config[:tagger] = :list_all
|
||||
end
|
||||
|
||||
it "creates a TagListAction" do
|
||||
@tl.should_receive(:register)
|
||||
expect(@tl).to receive(:register)
|
||||
@script.register
|
||||
end
|
||||
|
||||
it "registers MSpec pretend mode" do
|
||||
MSpec.should_receive(:register_mode).with(:pretend)
|
||||
expect(MSpec).to receive(:register_mode).with(:pretend)
|
||||
@script.register
|
||||
end
|
||||
|
||||
it "sets config[:formatter] to false" do
|
||||
@script.register
|
||||
@config[:formatter].should be_false
|
||||
expect(@config[:formatter]).to be_falsey
|
||||
end
|
||||
end
|
||||
|
||||
describe "when config[:tagger] is :purge" do
|
||||
before :each do
|
||||
TagPurgeAction.should_receive(:new).and_return(@tl)
|
||||
MSpec.stub(:register_mode)
|
||||
expect(TagPurgeAction).to receive(:new).and_return(@tl)
|
||||
allow(MSpec).to receive(:register_mode)
|
||||
@config[:tagger] = :purge
|
||||
end
|
||||
|
||||
it "creates a TagPurgeAction" do
|
||||
@tl.should_receive(:register)
|
||||
expect(@tl).to receive(:register)
|
||||
@script.register
|
||||
end
|
||||
|
||||
it "registers MSpec in pretend mode" do
|
||||
MSpec.should_receive(:register_mode).with(:pretend)
|
||||
expect(MSpec).to receive(:register_mode).with(:pretend)
|
||||
@script.register
|
||||
end
|
||||
|
||||
it "registers MSpec in unguarded mode" do
|
||||
MSpec.should_receive(:register_mode).with(:unguarded)
|
||||
expect(MSpec).to receive(:register_mode).with(:unguarded)
|
||||
@script.register
|
||||
end
|
||||
|
||||
it "sets config[:formatter] to false" do
|
||||
@script.register
|
||||
@config[:formatter].should be_false
|
||||
expect(@config[:formatter]).to be_falsey
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,29 +1,29 @@
|
|||
require 'spec_helper'
|
||||
require 'mspec/expectations/expectations'
|
||||
|
||||
describe SpecExpectationNotMetError do
|
||||
RSpec.describe SpecExpectationNotMetError do
|
||||
it "is a subclass of StandardError" do
|
||||
SpecExpectationNotMetError.ancestors.should include(StandardError)
|
||||
expect(SpecExpectationNotMetError.ancestors).to include(StandardError)
|
||||
end
|
||||
end
|
||||
|
||||
describe SpecExpectationNotFoundError do
|
||||
RSpec.describe SpecExpectationNotFoundError do
|
||||
it "is a subclass of StandardError" do
|
||||
SpecExpectationNotFoundError.ancestors.should include(StandardError)
|
||||
expect(SpecExpectationNotFoundError.ancestors).to include(StandardError)
|
||||
end
|
||||
end
|
||||
|
||||
describe SpecExpectationNotFoundError, "#message" do
|
||||
RSpec.describe SpecExpectationNotFoundError, "#message" do
|
||||
it "returns 'No behavior expectation was found in the example'" do
|
||||
m = SpecExpectationNotFoundError.new.message
|
||||
m.should == "No behavior expectation was found in the example"
|
||||
expect(m).to eq("No behavior expectation was found in the example")
|
||||
end
|
||||
end
|
||||
|
||||
describe SpecExpectation, "#fail_with" do
|
||||
RSpec.describe SpecExpectation, "#fail_with" do
|
||||
it "raises an SpecExpectationNotMetError" do
|
||||
lambda {
|
||||
expect {
|
||||
SpecExpectation.fail_with "expected this", "to equal that"
|
||||
}.should raise_error(SpecExpectationNotMetError, "expected this to equal that")
|
||||
}.to raise_error(SpecExpectationNotMetError, "expected this to equal that")
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,17 +1,17 @@
|
|||
require 'spec_helper'
|
||||
require 'rbconfig'
|
||||
|
||||
describe "MSpec" do
|
||||
RSpec.describe "MSpec" do
|
||||
before :all do
|
||||
path = RbConfig::CONFIG['bindir']
|
||||
exe = RbConfig::CONFIG['ruby_install_name']
|
||||
file = File.dirname(__FILE__) + '/should.rb'
|
||||
file = File.expand_path('../../fixtures/should.rb', __FILE__)
|
||||
@out = `#{path}/#{exe} #{file}`
|
||||
end
|
||||
|
||||
describe "#should" do
|
||||
it "records failures" do
|
||||
@out.should include <<-EOS
|
||||
expect(@out).to include <<-EOS
|
||||
1)
|
||||
MSpec expectation method #should causes a failure to be recorded FAILED
|
||||
Expected 1 == 2
|
||||
|
@ -20,7 +20,7 @@ EOS
|
|||
end
|
||||
|
||||
it "raises exceptions for examples with no expectations" do
|
||||
@out.should include <<-EOS
|
||||
expect(@out).to include <<-EOS
|
||||
2)
|
||||
MSpec expectation method #should registers that an expectation has been encountered FAILED
|
||||
No behavior expectation was found in the example
|
||||
|
@ -30,7 +30,7 @@ EOS
|
|||
|
||||
describe "#should_not" do
|
||||
it "records failures" do
|
||||
@out.should include <<-EOS
|
||||
expect(@out).to include <<-EOS
|
||||
3)
|
||||
MSpec expectation method #should_not causes a failure to be recorded FAILED
|
||||
Expected 1 == 1
|
||||
|
@ -39,7 +39,7 @@ EOS
|
|||
end
|
||||
|
||||
it "raises exceptions for examples with no expectations" do
|
||||
@out.should include <<-EOS
|
||||
expect(@out).to include <<-EOS
|
||||
4)
|
||||
MSpec expectation method #should_not registers that an expectation has been encountered FAILED
|
||||
No behavior expectation was found in the example
|
||||
|
@ -48,14 +48,14 @@ EOS
|
|||
end
|
||||
|
||||
it "prints status information" do
|
||||
@out.should include ".FF..FF."
|
||||
expect(@out).to include ".FF..FF."
|
||||
end
|
||||
|
||||
it "prints out a summary" do
|
||||
@out.should include "0 files, 8 examples, 6 expectations, 4 failures, 0 errors"
|
||||
expect(@out).to include "0 files, 8 examples, 6 expectations, 4 failures, 0 errors"
|
||||
end
|
||||
|
||||
it "records expectations" do
|
||||
@out.should include "I was called 6 times"
|
||||
expect(@out).to include "I was called 6 times"
|
||||
end
|
||||
end
|
||||
|
|
|
@ -8,6 +8,8 @@ require 'mspec/utils/script'
|
|||
# specs but is run by MSpec. This avoids conflicting with
|
||||
# RSpec's #should and #should_not methods.
|
||||
|
||||
raise "RSpec should not be loaded" if defined?(RSpec)
|
||||
|
||||
class ShouldSpecsMonitor
|
||||
def initialize
|
||||
@called = 0
|
|
@ -1,46 +1,46 @@
|
|||
require 'spec_helper'
|
||||
require 'mspec/guards'
|
||||
|
||||
describe Object, "#with_block_device" do
|
||||
RSpec.describe Object, "#with_block_device" do
|
||||
before :each do
|
||||
ScratchPad.clear
|
||||
|
||||
@guard = BlockDeviceGuard.new
|
||||
BlockDeviceGuard.stub(:new).and_return(@guard)
|
||||
allow(BlockDeviceGuard).to receive(:new).and_return(@guard)
|
||||
end
|
||||
|
||||
platform_is_not :freebsd, :windows do
|
||||
it "yields if block device is available" do
|
||||
@guard.should_receive(:`).and_return("block devices")
|
||||
expect(@guard).to receive(:`).and_return("block devices")
|
||||
with_block_device { ScratchPad.record :yield }
|
||||
ScratchPad.recorded.should == :yield
|
||||
expect(ScratchPad.recorded).to eq(:yield)
|
||||
end
|
||||
|
||||
it "does not yield if block device is not available" do
|
||||
@guard.should_receive(:`).and_return(nil)
|
||||
expect(@guard).to receive(:`).and_return(nil)
|
||||
with_block_device { ScratchPad.record :yield }
|
||||
ScratchPad.recorded.should_not == :yield
|
||||
expect(ScratchPad.recorded).not_to eq(:yield)
|
||||
end
|
||||
end
|
||||
|
||||
platform_is :freebsd, :windows do
|
||||
it "does not yield, since platform does not support block devices" do
|
||||
@guard.should_not_receive(:`)
|
||||
expect(@guard).not_to receive(:`)
|
||||
with_block_device { ScratchPad.record :yield }
|
||||
ScratchPad.recorded.should_not == :yield
|
||||
expect(ScratchPad.recorded).not_to eq(:yield)
|
||||
end
|
||||
end
|
||||
|
||||
it "sets the name of the guard to :with_block_device" do
|
||||
with_block_device { }
|
||||
@guard.name.should == :with_block_device
|
||||
expect(@guard.name).to eq(:with_block_device)
|
||||
end
|
||||
|
||||
it "calls #unregister even when an exception is raised in the guard block" do
|
||||
@guard.should_receive(:match?).and_return(true)
|
||||
@guard.should_receive(:unregister)
|
||||
lambda do
|
||||
expect(@guard).to receive(:match?).and_return(true)
|
||||
expect(@guard).to receive(:unregister)
|
||||
expect do
|
||||
with_block_device { raise Exception }
|
||||
end.should raise_error(Exception)
|
||||
end.to raise_error(Exception)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
require 'spec_helper'
|
||||
require 'mspec/guards'
|
||||
|
||||
describe BugGuard, "#match? when #implementation? is 'ruby'" do
|
||||
RSpec.describe BugGuard, "#match? when #implementation? is 'ruby'" do
|
||||
before :all do
|
||||
@verbose = $VERBOSE
|
||||
$VERBOSE = nil
|
||||
|
@ -23,47 +23,47 @@ describe BugGuard, "#match? when #implementation? is 'ruby'" do
|
|||
end
|
||||
|
||||
it "returns false when version argument is less than RUBY_VERSION" do
|
||||
BugGuard.new("#1", "1.8.5").match?.should == false
|
||||
expect(BugGuard.new("#1", "1.8.5").match?).to eq(false)
|
||||
end
|
||||
|
||||
it "returns true when version argument is equal to RUBY_VERSION" do
|
||||
BugGuard.new("#1", "1.8.6").match?.should == true
|
||||
expect(BugGuard.new("#1", "1.8.6").match?).to eq(true)
|
||||
end
|
||||
|
||||
it "returns true when version argument is greater than RUBY_VERSION" do
|
||||
BugGuard.new("#1", "1.8.7").match?.should == true
|
||||
expect(BugGuard.new("#1", "1.8.7").match?).to eq(true)
|
||||
end
|
||||
|
||||
it "returns true when version argument implicitly includes RUBY_VERSION" do
|
||||
BugGuard.new("#1", "1.8").match?.should == true
|
||||
BugGuard.new("#1", "1.8.6").match?.should == true
|
||||
expect(BugGuard.new("#1", "1.8").match?).to eq(true)
|
||||
expect(BugGuard.new("#1", "1.8.6").match?).to eq(true)
|
||||
end
|
||||
|
||||
it "returns true when the argument range includes RUBY_VERSION" do
|
||||
BugGuard.new("#1", '1.8.5'..'1.8.7').match?.should == true
|
||||
BugGuard.new("#1", '1.8'..'1.9').match?.should == true
|
||||
BugGuard.new("#1", '1.8'...'1.9').match?.should == true
|
||||
BugGuard.new("#1", '1.8'..'1.8.6').match?.should == true
|
||||
BugGuard.new("#1", '1.8.5'..'1.8.6').match?.should == true
|
||||
BugGuard.new("#1", ''...'1.8.7').match?.should == true
|
||||
expect(BugGuard.new("#1", '1.8.5'..'1.8.7').match?).to eq(true)
|
||||
expect(BugGuard.new("#1", '1.8'..'1.9').match?).to eq(true)
|
||||
expect(BugGuard.new("#1", '1.8'...'1.9').match?).to eq(true)
|
||||
expect(BugGuard.new("#1", '1.8'..'1.8.6').match?).to eq(true)
|
||||
expect(BugGuard.new("#1", '1.8.5'..'1.8.6').match?).to eq(true)
|
||||
expect(BugGuard.new("#1", ''...'1.8.7').match?).to eq(true)
|
||||
end
|
||||
|
||||
it "returns false when the argument range does not include RUBY_VERSION" do
|
||||
BugGuard.new("#1", '1.8.7'..'1.8.9').match?.should == false
|
||||
BugGuard.new("#1", '1.8.4'..'1.8.5').match?.should == false
|
||||
BugGuard.new("#1", '1.8.4'...'1.8.6').match?.should == false
|
||||
BugGuard.new("#1", '1.8.5'...'1.8.6').match?.should == false
|
||||
BugGuard.new("#1", ''...'1.8.6').match?.should == false
|
||||
expect(BugGuard.new("#1", '1.8.7'..'1.8.9').match?).to eq(false)
|
||||
expect(BugGuard.new("#1", '1.8.4'..'1.8.5').match?).to eq(false)
|
||||
expect(BugGuard.new("#1", '1.8.4'...'1.8.6').match?).to eq(false)
|
||||
expect(BugGuard.new("#1", '1.8.5'...'1.8.6').match?).to eq(false)
|
||||
expect(BugGuard.new("#1", ''...'1.8.6').match?).to eq(false)
|
||||
end
|
||||
|
||||
it "returns false when MSpec.mode?(:no_ruby_bug) is true" do
|
||||
MSpec.should_receive(:mode?).with(:no_ruby_bug).twice.and_return(:true)
|
||||
BugGuard.new("#1", "1.8.5").match?.should == false
|
||||
BugGuard.new("#1", "1.8").match?.should == false
|
||||
expect(MSpec).to receive(:mode?).with(:no_ruby_bug).twice.and_return(:true)
|
||||
expect(BugGuard.new("#1", "1.8.5").match?).to eq(false)
|
||||
expect(BugGuard.new("#1", "1.8").match?).to eq(false)
|
||||
end
|
||||
end
|
||||
|
||||
describe BugGuard, "#match? when #implementation? is not 'ruby'" do
|
||||
RSpec.describe BugGuard, "#match? when #implementation? is not 'ruby'" do
|
||||
before :all do
|
||||
@verbose = $VERBOSE
|
||||
$VERBOSE = nil
|
||||
|
@ -88,64 +88,64 @@ describe BugGuard, "#match? when #implementation? is not 'ruby'" do
|
|||
end
|
||||
|
||||
it "returns false when version argument is less than RUBY_VERSION" do
|
||||
BugGuard.new("#1", "1.8").match?.should == false
|
||||
BugGuard.new("#1", "1.8.6").match?.should == false
|
||||
expect(BugGuard.new("#1", "1.8").match?).to eq(false)
|
||||
expect(BugGuard.new("#1", "1.8.6").match?).to eq(false)
|
||||
end
|
||||
|
||||
it "returns false when version argument is equal to RUBY_VERSION" do
|
||||
BugGuard.new("#1", "1.8.6").match?.should == false
|
||||
expect(BugGuard.new("#1", "1.8.6").match?).to eq(false)
|
||||
end
|
||||
|
||||
it "returns false when version argument is greater than RUBY_VERSION" do
|
||||
BugGuard.new("#1", "1.8.7").match?.should == false
|
||||
expect(BugGuard.new("#1", "1.8.7").match?).to eq(false)
|
||||
end
|
||||
|
||||
it "returns false no matter if the argument range includes RUBY_VERSION" do
|
||||
BugGuard.new("#1", '1.8'...'1.9').match?.should == false
|
||||
BugGuard.new("#1", '1.8.5'...'1.8.7').match?.should == false
|
||||
BugGuard.new("#1", '1.8.4'...'1.8.6').match?.should == false
|
||||
expect(BugGuard.new("#1", '1.8'...'1.9').match?).to eq(false)
|
||||
expect(BugGuard.new("#1", '1.8.5'...'1.8.7').match?).to eq(false)
|
||||
expect(BugGuard.new("#1", '1.8.4'...'1.8.6').match?).to eq(false)
|
||||
end
|
||||
|
||||
it "returns false when MSpec.mode?(:no_ruby_bug) is true" do
|
||||
MSpec.stub(:mode?).and_return(:true)
|
||||
BugGuard.new("#1", "1.8.6").match?.should == false
|
||||
allow(MSpec).to receive(:mode?).and_return(:true)
|
||||
expect(BugGuard.new("#1", "1.8.6").match?).to eq(false)
|
||||
end
|
||||
end
|
||||
|
||||
describe Object, "#ruby_bug" do
|
||||
RSpec.describe Object, "#ruby_bug" do
|
||||
before :each do
|
||||
hide_deprecation_warnings
|
||||
@guard = BugGuard.new "#1234", "x.x.x"
|
||||
BugGuard.stub(:new).and_return(@guard)
|
||||
allow(BugGuard).to receive(:new).and_return(@guard)
|
||||
ScratchPad.clear
|
||||
end
|
||||
|
||||
it "yields when #match? returns false" do
|
||||
@guard.stub(:match?).and_return(false)
|
||||
allow(@guard).to receive(:match?).and_return(false)
|
||||
ruby_bug("#1234", "1.8.6") { ScratchPad.record :yield }
|
||||
ScratchPad.recorded.should == :yield
|
||||
expect(ScratchPad.recorded).to eq(:yield)
|
||||
end
|
||||
|
||||
it "does not yield when #match? returns true" do
|
||||
@guard.stub(:match?).and_return(true)
|
||||
allow(@guard).to receive(:match?).and_return(true)
|
||||
ruby_bug("#1234", "1.8.6") { ScratchPad.record :yield }
|
||||
ScratchPad.recorded.should_not == :yield
|
||||
expect(ScratchPad.recorded).not_to eq(:yield)
|
||||
end
|
||||
|
||||
it "requires a bug tracker number and a version number" do
|
||||
lambda { ruby_bug { } }.should raise_error(ArgumentError)
|
||||
lambda { ruby_bug("#1234") { } }.should raise_error(ArgumentError)
|
||||
expect { ruby_bug { } }.to raise_error(ArgumentError)
|
||||
expect { ruby_bug("#1234") { } }.to raise_error(ArgumentError)
|
||||
end
|
||||
|
||||
it "sets the name of the guard to :ruby_bug" do
|
||||
ruby_bug("#1234", "1.8.6") { }
|
||||
@guard.name.should == :ruby_bug
|
||||
expect(@guard.name).to eq(:ruby_bug)
|
||||
end
|
||||
|
||||
it "calls #unregister even when an exception is raised in the guard block" do
|
||||
@guard.should_receive(:unregister)
|
||||
lambda do
|
||||
expect(@guard).to receive(:unregister)
|
||||
expect do
|
||||
ruby_bug("", "") { raise Exception }
|
||||
end.should raise_error(Exception)
|
||||
end.to raise_error(Exception)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,53 +1,53 @@
|
|||
require 'spec_helper'
|
||||
require 'mspec/guards'
|
||||
|
||||
describe Object, "#conflicts_with" do
|
||||
RSpec.describe Object, "#conflicts_with" do
|
||||
before :each do
|
||||
hide_deprecation_warnings
|
||||
ScratchPad.clear
|
||||
end
|
||||
|
||||
it "does not yield if Object.constants includes any of the arguments" do
|
||||
Object.stub(:constants).and_return(["SomeClass", "OtherClass"])
|
||||
allow(Object).to receive(:constants).and_return(["SomeClass", "OtherClass"])
|
||||
conflicts_with(:SomeClass, :AClass, :BClass) { ScratchPad.record :yield }
|
||||
ScratchPad.recorded.should_not == :yield
|
||||
expect(ScratchPad.recorded).not_to eq(:yield)
|
||||
end
|
||||
|
||||
it "does not yield if Object.constants (as Symbols) includes any of the arguments" do
|
||||
Object.stub(:constants).and_return([:SomeClass, :OtherClass])
|
||||
allow(Object).to receive(:constants).and_return([:SomeClass, :OtherClass])
|
||||
conflicts_with(:SomeClass, :AClass, :BClass) { ScratchPad.record :yield }
|
||||
ScratchPad.recorded.should_not == :yield
|
||||
expect(ScratchPad.recorded).not_to eq(:yield)
|
||||
end
|
||||
|
||||
it "yields if Object.constants does not include any of the arguments" do
|
||||
Object.stub(:constants).and_return(["SomeClass", "OtherClass"])
|
||||
allow(Object).to receive(:constants).and_return(["SomeClass", "OtherClass"])
|
||||
conflicts_with(:AClass, :BClass) { ScratchPad.record :yield }
|
||||
ScratchPad.recorded.should == :yield
|
||||
expect(ScratchPad.recorded).to eq(:yield)
|
||||
end
|
||||
|
||||
it "yields if Object.constants (as Symbols) does not include any of the arguments" do
|
||||
Object.stub(:constants).and_return([:SomeClass, :OtherClass])
|
||||
allow(Object).to receive(:constants).and_return([:SomeClass, :OtherClass])
|
||||
conflicts_with(:AClass, :BClass) { ScratchPad.record :yield }
|
||||
ScratchPad.recorded.should == :yield
|
||||
expect(ScratchPad.recorded).to eq(:yield)
|
||||
end
|
||||
end
|
||||
|
||||
describe Object, "#conflicts_with" do
|
||||
RSpec.describe Object, "#conflicts_with" do
|
||||
before :each do
|
||||
hide_deprecation_warnings
|
||||
@guard = ConflictsGuard.new
|
||||
ConflictsGuard.stub(:new).and_return(@guard)
|
||||
allow(ConflictsGuard).to receive(:new).and_return(@guard)
|
||||
end
|
||||
|
||||
it "sets the name of the guard to :conflicts_with" do
|
||||
conflicts_with(:AClass, :BClass) { }
|
||||
@guard.name.should == :conflicts_with
|
||||
expect(@guard.name).to eq(:conflicts_with)
|
||||
end
|
||||
|
||||
it "calls #unregister even when an exception is raised in the guard block" do
|
||||
@guard.should_receive(:unregister)
|
||||
lambda do
|
||||
expect(@guard).to receive(:unregister)
|
||||
expect do
|
||||
conflicts_with(:AClass, :BClass) { raise Exception }
|
||||
end.should raise_error(Exception)
|
||||
end.to raise_error(Exception)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,55 +1,55 @@
|
|||
require 'spec_helper'
|
||||
require 'mspec/guards'
|
||||
|
||||
describe Object, "#big_endian" do
|
||||
RSpec.describe Object, "#big_endian" do
|
||||
before :each do
|
||||
@guard = BigEndianGuard.new
|
||||
BigEndianGuard.stub(:new).and_return(@guard)
|
||||
allow(BigEndianGuard).to receive(:new).and_return(@guard)
|
||||
ScratchPad.clear
|
||||
end
|
||||
|
||||
it "yields on big-endian platforms" do
|
||||
@guard.stub(:pattern).and_return([?\001])
|
||||
allow(@guard).to receive(:pattern).and_return([?\001])
|
||||
big_endian { ScratchPad.record :yield }
|
||||
ScratchPad.recorded.should == :yield
|
||||
expect(ScratchPad.recorded).to eq(:yield)
|
||||
end
|
||||
|
||||
it "does not yield on little-endian platforms" do
|
||||
@guard.stub(:pattern).and_return([?\000])
|
||||
allow(@guard).to receive(:pattern).and_return([?\000])
|
||||
big_endian { ScratchPad.record :yield }
|
||||
ScratchPad.recorded.should_not == :yield
|
||||
expect(ScratchPad.recorded).not_to eq(:yield)
|
||||
end
|
||||
|
||||
it "sets the name of the guard to :big_endian" do
|
||||
big_endian { }
|
||||
@guard.name.should == :big_endian
|
||||
expect(@guard.name).to eq(:big_endian)
|
||||
end
|
||||
|
||||
it "calls #unregister even when an exception is raised in the guard block" do
|
||||
@guard.stub(:pattern).and_return([?\001])
|
||||
@guard.should_receive(:unregister)
|
||||
lambda do
|
||||
allow(@guard).to receive(:pattern).and_return([?\001])
|
||||
expect(@guard).to receive(:unregister)
|
||||
expect do
|
||||
big_endian { raise Exception }
|
||||
end.should raise_error(Exception)
|
||||
end.to raise_error(Exception)
|
||||
end
|
||||
end
|
||||
|
||||
describe Object, "#little_endian" do
|
||||
RSpec.describe Object, "#little_endian" do
|
||||
before :each do
|
||||
@guard = BigEndianGuard.new
|
||||
BigEndianGuard.stub(:new).and_return(@guard)
|
||||
allow(BigEndianGuard).to receive(:new).and_return(@guard)
|
||||
ScratchPad.clear
|
||||
end
|
||||
|
||||
it "yields on little-endian platforms" do
|
||||
@guard.stub(:pattern).and_return([?\000])
|
||||
allow(@guard).to receive(:pattern).and_return([?\000])
|
||||
little_endian { ScratchPad.record :yield }
|
||||
ScratchPad.recorded.should == :yield
|
||||
expect(ScratchPad.recorded).to eq(:yield)
|
||||
end
|
||||
|
||||
it "does not yield on big-endian platforms" do
|
||||
@guard.stub(:pattern).and_return([?\001])
|
||||
allow(@guard).to receive(:pattern).and_return([?\001])
|
||||
little_endian { ScratchPad.record :yield }
|
||||
ScratchPad.recorded.should_not == :yield
|
||||
expect(ScratchPad.recorded).not_to eq(:yield)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,120 +1,120 @@
|
|||
require 'spec_helper'
|
||||
require 'mspec/guards'
|
||||
|
||||
describe FeatureGuard, ".enabled?" do
|
||||
RSpec.describe FeatureGuard, ".enabled?" do
|
||||
it "returns true if the feature is enabled" do
|
||||
MSpec.should_receive(:feature_enabled?).with(:encoding).and_return(true)
|
||||
FeatureGuard.enabled?(:encoding).should be_true
|
||||
expect(MSpec).to receive(:feature_enabled?).with(:encoding).and_return(true)
|
||||
expect(FeatureGuard.enabled?(:encoding)).to be_truthy
|
||||
end
|
||||
|
||||
it "returns false if the feature is not enabled" do
|
||||
MSpec.should_receive(:feature_enabled?).with(:encoding).and_return(false)
|
||||
FeatureGuard.enabled?(:encoding).should be_false
|
||||
expect(MSpec).to receive(:feature_enabled?).with(:encoding).and_return(false)
|
||||
expect(FeatureGuard.enabled?(:encoding)).to be_falsey
|
||||
end
|
||||
|
||||
it "returns true if all the features are enabled" do
|
||||
MSpec.should_receive(:feature_enabled?).with(:one).and_return(true)
|
||||
MSpec.should_receive(:feature_enabled?).with(:two).and_return(true)
|
||||
FeatureGuard.enabled?(:one, :two).should be_true
|
||||
expect(MSpec).to receive(:feature_enabled?).with(:one).and_return(true)
|
||||
expect(MSpec).to receive(:feature_enabled?).with(:two).and_return(true)
|
||||
expect(FeatureGuard.enabled?(:one, :two)).to be_truthy
|
||||
end
|
||||
|
||||
it "returns false if any of the features are not enabled" do
|
||||
MSpec.should_receive(:feature_enabled?).with(:one).and_return(true)
|
||||
MSpec.should_receive(:feature_enabled?).with(:two).and_return(false)
|
||||
FeatureGuard.enabled?(:one, :two).should be_false
|
||||
expect(MSpec).to receive(:feature_enabled?).with(:one).and_return(true)
|
||||
expect(MSpec).to receive(:feature_enabled?).with(:two).and_return(false)
|
||||
expect(FeatureGuard.enabled?(:one, :two)).to be_falsey
|
||||
end
|
||||
end
|
||||
|
||||
describe Object, "#with_feature" do
|
||||
RSpec.describe Object, "#with_feature" do
|
||||
before :each do
|
||||
ScratchPad.clear
|
||||
|
||||
@guard = FeatureGuard.new :encoding
|
||||
FeatureGuard.stub(:new).and_return(@guard)
|
||||
allow(FeatureGuard).to receive(:new).and_return(@guard)
|
||||
end
|
||||
|
||||
it "sets the name of the guard to :with_feature" do
|
||||
with_feature(:encoding) { }
|
||||
@guard.name.should == :with_feature
|
||||
expect(@guard.name).to eq(:with_feature)
|
||||
end
|
||||
|
||||
it "calls #unregister even when an exception is raised in the guard block" do
|
||||
@guard.should_receive(:match?).and_return(true)
|
||||
@guard.should_receive(:unregister)
|
||||
lambda do
|
||||
expect(@guard).to receive(:match?).and_return(true)
|
||||
expect(@guard).to receive(:unregister)
|
||||
expect do
|
||||
with_feature { raise Exception }
|
||||
end.should raise_error(Exception)
|
||||
end.to raise_error(Exception)
|
||||
end
|
||||
end
|
||||
|
||||
describe Object, "#with_feature" do
|
||||
RSpec.describe Object, "#with_feature" do
|
||||
before :each do
|
||||
ScratchPad.clear
|
||||
end
|
||||
|
||||
it "yields if the feature is enabled" do
|
||||
MSpec.should_receive(:feature_enabled?).with(:encoding).and_return(true)
|
||||
expect(MSpec).to receive(:feature_enabled?).with(:encoding).and_return(true)
|
||||
with_feature(:encoding) { ScratchPad.record :yield }
|
||||
ScratchPad.recorded.should == :yield
|
||||
expect(ScratchPad.recorded).to eq(:yield)
|
||||
end
|
||||
|
||||
it "yields if all the features are enabled" do
|
||||
MSpec.should_receive(:feature_enabled?).with(:one).and_return(true)
|
||||
MSpec.should_receive(:feature_enabled?).with(:two).and_return(true)
|
||||
expect(MSpec).to receive(:feature_enabled?).with(:one).and_return(true)
|
||||
expect(MSpec).to receive(:feature_enabled?).with(:two).and_return(true)
|
||||
with_feature(:one, :two) { ScratchPad.record :yield }
|
||||
ScratchPad.recorded.should == :yield
|
||||
expect(ScratchPad.recorded).to eq(:yield)
|
||||
end
|
||||
|
||||
it "does not yield if the feature is not enabled" do
|
||||
MSpec.should_receive(:feature_enabled?).with(:encoding).and_return(false)
|
||||
expect(MSpec).to receive(:feature_enabled?).with(:encoding).and_return(false)
|
||||
with_feature(:encoding) { ScratchPad.record :yield }
|
||||
ScratchPad.recorded.should be_nil
|
||||
expect(ScratchPad.recorded).to be_nil
|
||||
end
|
||||
|
||||
it "does not yield if any of the features are not enabled" do
|
||||
MSpec.should_receive(:feature_enabled?).with(:one).and_return(true)
|
||||
MSpec.should_receive(:feature_enabled?).with(:two).and_return(false)
|
||||
expect(MSpec).to receive(:feature_enabled?).with(:one).and_return(true)
|
||||
expect(MSpec).to receive(:feature_enabled?).with(:two).and_return(false)
|
||||
with_feature(:one, :two) { ScratchPad.record :yield }
|
||||
ScratchPad.recorded.should be_nil
|
||||
expect(ScratchPad.recorded).to be_nil
|
||||
end
|
||||
end
|
||||
|
||||
describe Object, "#without_feature" do
|
||||
RSpec.describe Object, "#without_feature" do
|
||||
before :each do
|
||||
ScratchPad.clear
|
||||
|
||||
@guard = FeatureGuard.new :encoding
|
||||
FeatureGuard.stub(:new).and_return(@guard)
|
||||
allow(FeatureGuard).to receive(:new).and_return(@guard)
|
||||
end
|
||||
|
||||
it "sets the name of the guard to :without_feature" do
|
||||
without_feature(:encoding) { }
|
||||
@guard.name.should == :without_feature
|
||||
expect(@guard.name).to eq(:without_feature)
|
||||
end
|
||||
|
||||
it "calls #unregister even when an exception is raised in the guard block" do
|
||||
@guard.should_receive(:match?).and_return(false)
|
||||
@guard.should_receive(:unregister)
|
||||
lambda do
|
||||
expect(@guard).to receive(:match?).and_return(false)
|
||||
expect(@guard).to receive(:unregister)
|
||||
expect do
|
||||
without_feature { raise Exception }
|
||||
end.should raise_error(Exception)
|
||||
end.to raise_error(Exception)
|
||||
end
|
||||
end
|
||||
|
||||
describe Object, "#without_feature" do
|
||||
RSpec.describe Object, "#without_feature" do
|
||||
before :each do
|
||||
ScratchPad.clear
|
||||
end
|
||||
|
||||
it "does not yield if the feature is enabled" do
|
||||
MSpec.should_receive(:feature_enabled?).with(:encoding).and_return(true)
|
||||
expect(MSpec).to receive(:feature_enabled?).with(:encoding).and_return(true)
|
||||
without_feature(:encoding) { ScratchPad.record :yield }
|
||||
ScratchPad.recorded.should be_nil
|
||||
expect(ScratchPad.recorded).to be_nil
|
||||
end
|
||||
|
||||
it "yields if the feature is disabled" do
|
||||
MSpec.should_receive(:feature_enabled?).with(:encoding).and_return(false)
|
||||
expect(MSpec).to receive(:feature_enabled?).with(:encoding).and_return(false)
|
||||
without_feature(:encoding) { ScratchPad.record :yield }
|
||||
ScratchPad.recorded.should == :yield
|
||||
expect(ScratchPad.recorded).to eq(:yield)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -2,41 +2,41 @@ require 'spec_helper'
|
|||
require 'mspec/guards'
|
||||
require 'rbconfig'
|
||||
|
||||
describe SpecGuard, ".ruby_version" do
|
||||
RSpec.describe SpecGuard, ".ruby_version" do
|
||||
before :each do
|
||||
stub_const "RUBY_VERSION", "8.2.3"
|
||||
end
|
||||
|
||||
it "returns the full version for :full" do
|
||||
SpecGuard.ruby_version(:full).should == "8.2.3"
|
||||
expect(SpecGuard.ruby_version(:full)).to eq("8.2.3")
|
||||
end
|
||||
|
||||
it "returns major.minor.tiny for :tiny" do
|
||||
SpecGuard.ruby_version(:tiny).should == "8.2.3"
|
||||
expect(SpecGuard.ruby_version(:tiny)).to eq("8.2.3")
|
||||
end
|
||||
|
||||
it "returns major.minor.tiny for :teeny" do
|
||||
SpecGuard.ruby_version(:tiny).should == "8.2.3"
|
||||
expect(SpecGuard.ruby_version(:tiny)).to eq("8.2.3")
|
||||
end
|
||||
|
||||
it "returns major.minor for :minor" do
|
||||
SpecGuard.ruby_version(:minor).should == "8.2"
|
||||
expect(SpecGuard.ruby_version(:minor)).to eq("8.2")
|
||||
end
|
||||
|
||||
it "defaults to :minor" do
|
||||
SpecGuard.ruby_version.should == "8.2"
|
||||
expect(SpecGuard.ruby_version).to eq("8.2")
|
||||
end
|
||||
|
||||
it "returns major for :major" do
|
||||
SpecGuard.ruby_version(:major).should == "8"
|
||||
expect(SpecGuard.ruby_version(:major)).to eq("8")
|
||||
end
|
||||
end
|
||||
|
||||
describe SpecGuard, "#yield?" do
|
||||
RSpec.describe SpecGuard, "#yield?" do
|
||||
before :each do
|
||||
MSpec.clear_modes
|
||||
@guard = SpecGuard.new
|
||||
@guard.stub(:match?).and_return(false)
|
||||
allow(@guard).to receive(:match?).and_return(false)
|
||||
end
|
||||
|
||||
after :each do
|
||||
|
@ -47,77 +47,77 @@ describe SpecGuard, "#yield?" do
|
|||
|
||||
it "returns true if MSpec.mode?(:unguarded) is true" do
|
||||
MSpec.register_mode :unguarded
|
||||
@guard.yield?.should == true
|
||||
expect(@guard.yield?).to eq(true)
|
||||
end
|
||||
|
||||
it "returns true if MSpec.mode?(:verify) is true" do
|
||||
MSpec.register_mode :verify
|
||||
@guard.yield?.should == true
|
||||
expect(@guard.yield?).to eq(true)
|
||||
end
|
||||
|
||||
it "returns true if MSpec.mode?(:verify) is true regardless of invert being true" do
|
||||
MSpec.register_mode :verify
|
||||
@guard.yield?(true).should == true
|
||||
expect(@guard.yield?(true)).to eq(true)
|
||||
end
|
||||
|
||||
it "returns true if MSpec.mode?(:report) is true" do
|
||||
MSpec.register_mode :report
|
||||
@guard.yield?.should == true
|
||||
expect(@guard.yield?).to eq(true)
|
||||
end
|
||||
|
||||
it "returns true if MSpec.mode?(:report) is true regardless of invert being true" do
|
||||
MSpec.register_mode :report
|
||||
@guard.yield?(true).should == true
|
||||
expect(@guard.yield?(true)).to eq(true)
|
||||
end
|
||||
|
||||
it "returns true if MSpec.mode?(:report_on) is true and SpecGuards.guards contains the named guard" do
|
||||
MSpec.register_mode :report_on
|
||||
SpecGuard.guards << :guard_name
|
||||
@guard.yield?.should == false
|
||||
expect(@guard.yield?).to eq(false)
|
||||
@guard.name = :guard_name
|
||||
@guard.yield?.should == true
|
||||
expect(@guard.yield?).to eq(true)
|
||||
end
|
||||
|
||||
it "returns #match? if neither report nor verify mode are true" do
|
||||
@guard.stub(:match?).and_return(false)
|
||||
@guard.yield?.should == false
|
||||
@guard.stub(:match?).and_return(true)
|
||||
@guard.yield?.should == true
|
||||
allow(@guard).to receive(:match?).and_return(false)
|
||||
expect(@guard.yield?).to eq(false)
|
||||
allow(@guard).to receive(:match?).and_return(true)
|
||||
expect(@guard.yield?).to eq(true)
|
||||
end
|
||||
|
||||
it "returns #match? if invert is true and neither report nor verify mode are true" do
|
||||
@guard.stub(:match?).and_return(false)
|
||||
@guard.yield?(true).should == true
|
||||
@guard.stub(:match?).and_return(true)
|
||||
@guard.yield?(true).should == false
|
||||
allow(@guard).to receive(:match?).and_return(false)
|
||||
expect(@guard.yield?(true)).to eq(true)
|
||||
allow(@guard).to receive(:match?).and_return(true)
|
||||
expect(@guard.yield?(true)).to eq(false)
|
||||
end
|
||||
end
|
||||
|
||||
describe SpecGuard, "#match?" do
|
||||
RSpec.describe SpecGuard, "#match?" do
|
||||
before :each do
|
||||
@guard = SpecGuard.new
|
||||
end
|
||||
|
||||
it "must be implemented in subclasses" do
|
||||
lambda {
|
||||
expect {
|
||||
@guard.match?
|
||||
}.should raise_error("must be implemented by the subclass")
|
||||
}.to raise_error("must be implemented by the subclass")
|
||||
end
|
||||
end
|
||||
|
||||
describe SpecGuard, "#unregister" do
|
||||
RSpec.describe SpecGuard, "#unregister" do
|
||||
before :each do
|
||||
MSpec.stub(:unregister)
|
||||
allow(MSpec).to receive(:unregister)
|
||||
@guard = SpecGuard.new
|
||||
end
|
||||
|
||||
it "unregisters from MSpec :add actions" do
|
||||
MSpec.should_receive(:unregister).with(:add, @guard)
|
||||
expect(MSpec).to receive(:unregister).with(:add, @guard)
|
||||
@guard.unregister
|
||||
end
|
||||
end
|
||||
|
||||
describe SpecGuard, "#record" do
|
||||
RSpec.describe SpecGuard, "#record" do
|
||||
after :each do
|
||||
SpecGuard.clear
|
||||
end
|
||||
|
@ -126,28 +126,28 @@ describe SpecGuard, "#record" do
|
|||
guard = SpecGuard.new "a", "1.8"..."1.9"
|
||||
guard.name = :named_guard
|
||||
guard.record "SomeClass#action returns true"
|
||||
SpecGuard.report.should == {
|
||||
expect(SpecGuard.report).to eq({
|
||||
'named_guard a, 1.8...1.9' => ["SomeClass#action returns true"]
|
||||
}
|
||||
})
|
||||
end
|
||||
end
|
||||
|
||||
describe SpecGuard, ".guards" do
|
||||
RSpec.describe SpecGuard, ".guards" do
|
||||
it "returns an Array" do
|
||||
SpecGuard.guards.should be_kind_of(Array)
|
||||
expect(SpecGuard.guards).to be_kind_of(Array)
|
||||
end
|
||||
end
|
||||
|
||||
describe SpecGuard, ".clear_guards" do
|
||||
RSpec.describe SpecGuard, ".clear_guards" do
|
||||
it "resets the array to empty" do
|
||||
SpecGuard.guards << :guard
|
||||
SpecGuard.guards.should == [:guard]
|
||||
expect(SpecGuard.guards).to eq([:guard])
|
||||
SpecGuard.clear_guards
|
||||
SpecGuard.guards.should == []
|
||||
expect(SpecGuard.guards).to eq([])
|
||||
end
|
||||
end
|
||||
|
||||
describe SpecGuard, ".finish" do
|
||||
RSpec.describe SpecGuard, ".finish" do
|
||||
before :each do
|
||||
$stdout = @out = IOStub.new
|
||||
end
|
||||
|
@ -163,88 +163,88 @@ describe SpecGuard, ".finish" do
|
|||
guard.record "SomeClass#action returns true"
|
||||
guard.record "SomeClass#reverse returns false"
|
||||
SpecGuard.finish
|
||||
$stdout.should == %[
|
||||
expect($stdout).to eq(%[
|
||||
|
||||
2 specs omitted by guard: named_guard a, 1.8...1.9:
|
||||
|
||||
SomeClass#action returns true
|
||||
SomeClass#reverse returns false
|
||||
|
||||
]
|
||||
])
|
||||
end
|
||||
end
|
||||
|
||||
describe SpecGuard, ".run_if" do
|
||||
RSpec.describe SpecGuard, ".run_if" do
|
||||
before :each do
|
||||
@guard = SpecGuard.new
|
||||
ScratchPad.clear
|
||||
end
|
||||
|
||||
it "yields if match? returns true" do
|
||||
@guard.stub(:match?).and_return(true)
|
||||
allow(@guard).to receive(:match?).and_return(true)
|
||||
@guard.run_if(:name) { ScratchPad.record :yield }
|
||||
ScratchPad.recorded.should == :yield
|
||||
expect(ScratchPad.recorded).to eq(:yield)
|
||||
end
|
||||
|
||||
it "does not yield if match? returns false" do
|
||||
@guard.stub(:match?).and_return(false)
|
||||
allow(@guard).to receive(:match?).and_return(false)
|
||||
@guard.run_if(:name) { fail }
|
||||
end
|
||||
|
||||
it "returns the result of the block if match? is true" do
|
||||
@guard.stub(:match?).and_return(true)
|
||||
@guard.run_if(:name) { 42 }.should == 42
|
||||
allow(@guard).to receive(:match?).and_return(true)
|
||||
expect(@guard.run_if(:name) { 42 }).to eq(42)
|
||||
end
|
||||
|
||||
it "returns nil if given a block and match? is false" do
|
||||
@guard.stub(:match?).and_return(false)
|
||||
@guard.run_if(:name) { 42 }.should == nil
|
||||
allow(@guard).to receive(:match?).and_return(false)
|
||||
expect(@guard.run_if(:name) { 42 }).to eq(nil)
|
||||
end
|
||||
|
||||
it "returns what #match? returns when no block is given" do
|
||||
@guard.stub(:match?).and_return(true)
|
||||
@guard.run_if(:name).should == true
|
||||
@guard.stub(:match?).and_return(false)
|
||||
@guard.run_if(:name).should == false
|
||||
allow(@guard).to receive(:match?).and_return(true)
|
||||
expect(@guard.run_if(:name)).to eq(true)
|
||||
allow(@guard).to receive(:match?).and_return(false)
|
||||
expect(@guard.run_if(:name)).to eq(false)
|
||||
end
|
||||
end
|
||||
|
||||
describe SpecGuard, ".run_unless" do
|
||||
RSpec.describe SpecGuard, ".run_unless" do
|
||||
before :each do
|
||||
@guard = SpecGuard.new
|
||||
ScratchPad.clear
|
||||
end
|
||||
|
||||
it "yields if match? returns false" do
|
||||
@guard.stub(:match?).and_return(false)
|
||||
allow(@guard).to receive(:match?).and_return(false)
|
||||
@guard.run_unless(:name) { ScratchPad.record :yield }
|
||||
ScratchPad.recorded.should == :yield
|
||||
expect(ScratchPad.recorded).to eq(:yield)
|
||||
end
|
||||
|
||||
it "does not yield if match? returns true" do
|
||||
@guard.stub(:match?).and_return(true)
|
||||
allow(@guard).to receive(:match?).and_return(true)
|
||||
@guard.run_unless(:name) { fail }
|
||||
end
|
||||
|
||||
it "returns the result of the block if match? is false" do
|
||||
@guard.stub(:match?).and_return(false)
|
||||
@guard.run_unless(:name) { 42 }.should == 42
|
||||
allow(@guard).to receive(:match?).and_return(false)
|
||||
expect(@guard.run_unless(:name) { 42 }).to eq(42)
|
||||
end
|
||||
|
||||
it "returns nil if given a block and match? is true" do
|
||||
@guard.stub(:match?).and_return(true)
|
||||
@guard.run_unless(:name) { 42 }.should == nil
|
||||
allow(@guard).to receive(:match?).and_return(true)
|
||||
expect(@guard.run_unless(:name) { 42 }).to eq(nil)
|
||||
end
|
||||
|
||||
it "returns the opposite of what #match? returns when no block is given" do
|
||||
@guard.stub(:match?).and_return(true)
|
||||
@guard.run_unless(:name).should == false
|
||||
@guard.stub(:match?).and_return(false)
|
||||
@guard.run_unless(:name).should == true
|
||||
allow(@guard).to receive(:match?).and_return(true)
|
||||
expect(@guard.run_unless(:name)).to eq(false)
|
||||
allow(@guard).to receive(:match?).and_return(false)
|
||||
expect(@guard.run_unless(:name)).to eq(true)
|
||||
end
|
||||
end
|
||||
|
||||
describe Object, "#guard" do
|
||||
RSpec.describe Object, "#guard" do
|
||||
before :each do
|
||||
ScratchPad.clear
|
||||
end
|
||||
|
@ -255,31 +255,31 @@ describe Object, "#guard" do
|
|||
|
||||
it "allows to combine guards" do
|
||||
guard1 = VersionGuard.new '1.2.3', 'x.x.x'
|
||||
VersionGuard.stub(:new).and_return(guard1)
|
||||
allow(VersionGuard).to receive(:new).and_return(guard1)
|
||||
guard2 = PlatformGuard.new :dummy
|
||||
PlatformGuard.stub(:new).and_return(guard2)
|
||||
allow(PlatformGuard).to receive(:new).and_return(guard2)
|
||||
|
||||
guard1.stub(:match?).and_return(true)
|
||||
guard2.stub(:match?).and_return(true)
|
||||
allow(guard1).to receive(:match?).and_return(true)
|
||||
allow(guard2).to receive(:match?).and_return(true)
|
||||
guard -> { ruby_version_is "2.4" and platform_is :linux } do
|
||||
ScratchPad.record :yield
|
||||
end
|
||||
ScratchPad.recorded.should == :yield
|
||||
expect(ScratchPad.recorded).to eq(:yield)
|
||||
|
||||
guard1.stub(:match?).and_return(false)
|
||||
guard2.stub(:match?).and_return(true)
|
||||
allow(guard1).to receive(:match?).and_return(false)
|
||||
allow(guard2).to receive(:match?).and_return(true)
|
||||
guard -> { ruby_version_is "2.4" and platform_is :linux } do
|
||||
fail
|
||||
end
|
||||
|
||||
guard1.stub(:match?).and_return(true)
|
||||
guard2.stub(:match?).and_return(false)
|
||||
allow(guard1).to receive(:match?).and_return(true)
|
||||
allow(guard2).to receive(:match?).and_return(false)
|
||||
guard -> { ruby_version_is "2.4" and platform_is :linux } do
|
||||
fail
|
||||
end
|
||||
|
||||
guard1.stub(:match?).and_return(false)
|
||||
guard2.stub(:match?).and_return(false)
|
||||
allow(guard1).to receive(:match?).and_return(false)
|
||||
allow(guard2).to receive(:match?).and_return(false)
|
||||
guard -> { ruby_version_is "2.4" and platform_is :linux } do
|
||||
fail
|
||||
end
|
||||
|
@ -289,7 +289,7 @@ describe Object, "#guard" do
|
|||
guard -> { true } do
|
||||
ScratchPad.record :yield
|
||||
end
|
||||
ScratchPad.recorded.should == :yield
|
||||
expect(ScratchPad.recorded).to eq(:yield)
|
||||
end
|
||||
|
||||
it "does not yield when the Proc returns false" do
|
||||
|
@ -304,12 +304,12 @@ describe Object, "#guard" do
|
|||
guard -> { false } do
|
||||
ScratchPad.record :yield1
|
||||
end
|
||||
ScratchPad.recorded.should == :yield1
|
||||
expect(ScratchPad.recorded).to eq(:yield1)
|
||||
|
||||
guard -> { true } do
|
||||
ScratchPad.record :yield2
|
||||
end
|
||||
ScratchPad.recorded.should == :yield2
|
||||
expect(ScratchPad.recorded).to eq(:yield2)
|
||||
end
|
||||
|
||||
it "yields if MSpec.mode?(:verify) is true" do
|
||||
|
@ -318,12 +318,12 @@ describe Object, "#guard" do
|
|||
guard -> { false } do
|
||||
ScratchPad.record :yield1
|
||||
end
|
||||
ScratchPad.recorded.should == :yield1
|
||||
expect(ScratchPad.recorded).to eq(:yield1)
|
||||
|
||||
guard -> { true } do
|
||||
ScratchPad.record :yield2
|
||||
end
|
||||
ScratchPad.recorded.should == :yield2
|
||||
expect(ScratchPad.recorded).to eq(:yield2)
|
||||
end
|
||||
|
||||
it "yields if MSpec.mode?(:report) is true" do
|
||||
|
@ -332,72 +332,72 @@ describe Object, "#guard" do
|
|||
guard -> { false } do
|
||||
ScratchPad.record :yield1
|
||||
end
|
||||
ScratchPad.recorded.should == :yield1
|
||||
expect(ScratchPad.recorded).to eq(:yield1)
|
||||
|
||||
guard -> { true } do
|
||||
ScratchPad.record :yield2
|
||||
end
|
||||
ScratchPad.recorded.should == :yield2
|
||||
expect(ScratchPad.recorded).to eq(:yield2)
|
||||
end
|
||||
|
||||
it "raises an error if no Proc is given" do
|
||||
-> { guard :foo }.should raise_error(RuntimeError)
|
||||
expect { guard :foo }.to raise_error(RuntimeError)
|
||||
end
|
||||
|
||||
it "requires a block" do
|
||||
-> {
|
||||
expect {
|
||||
guard(-> { true })
|
||||
}.should raise_error(LocalJumpError)
|
||||
-> {
|
||||
}.to raise_error(LocalJumpError)
|
||||
expect {
|
||||
guard(-> { false })
|
||||
}.should raise_error(LocalJumpError)
|
||||
}.to raise_error(LocalJumpError)
|
||||
end
|
||||
end
|
||||
|
||||
describe Object, "#guard_not" do
|
||||
RSpec.describe Object, "#guard_not" do
|
||||
before :each do
|
||||
ScratchPad.clear
|
||||
end
|
||||
|
||||
it "allows to combine guards" do
|
||||
guard1 = VersionGuard.new '1.2.3', 'x.x.x'
|
||||
VersionGuard.stub(:new).and_return(guard1)
|
||||
allow(VersionGuard).to receive(:new).and_return(guard1)
|
||||
guard2 = PlatformGuard.new :dummy
|
||||
PlatformGuard.stub(:new).and_return(guard2)
|
||||
allow(PlatformGuard).to receive(:new).and_return(guard2)
|
||||
|
||||
guard1.stub(:match?).and_return(true)
|
||||
guard2.stub(:match?).and_return(true)
|
||||
allow(guard1).to receive(:match?).and_return(true)
|
||||
allow(guard2).to receive(:match?).and_return(true)
|
||||
guard_not -> { ruby_version_is "2.4" and platform_is :linux } do
|
||||
fail
|
||||
end
|
||||
|
||||
guard1.stub(:match?).and_return(false)
|
||||
guard2.stub(:match?).and_return(true)
|
||||
allow(guard1).to receive(:match?).and_return(false)
|
||||
allow(guard2).to receive(:match?).and_return(true)
|
||||
guard_not -> { ruby_version_is "2.4" and platform_is :linux } do
|
||||
ScratchPad.record :yield1
|
||||
end
|
||||
ScratchPad.recorded.should == :yield1
|
||||
expect(ScratchPad.recorded).to eq(:yield1)
|
||||
|
||||
guard1.stub(:match?).and_return(true)
|
||||
guard2.stub(:match?).and_return(false)
|
||||
allow(guard1).to receive(:match?).and_return(true)
|
||||
allow(guard2).to receive(:match?).and_return(false)
|
||||
guard_not -> { ruby_version_is "2.4" and platform_is :linux } do
|
||||
ScratchPad.record :yield2
|
||||
end
|
||||
ScratchPad.recorded.should == :yield2
|
||||
expect(ScratchPad.recorded).to eq(:yield2)
|
||||
|
||||
guard1.stub(:match?).and_return(false)
|
||||
guard2.stub(:match?).and_return(false)
|
||||
allow(guard1).to receive(:match?).and_return(false)
|
||||
allow(guard2).to receive(:match?).and_return(false)
|
||||
guard_not -> { ruby_version_is "2.4" and platform_is :linux } do
|
||||
ScratchPad.record :yield3
|
||||
end
|
||||
ScratchPad.recorded.should == :yield3
|
||||
expect(ScratchPad.recorded).to eq(:yield3)
|
||||
end
|
||||
|
||||
it "yields when the Proc returns false" do
|
||||
guard_not -> { false } do
|
||||
ScratchPad.record :yield
|
||||
end
|
||||
ScratchPad.recorded.should == :yield
|
||||
expect(ScratchPad.recorded).to eq(:yield)
|
||||
end
|
||||
|
||||
it "does not yield when the Proc returns true" do
|
||||
|
@ -407,15 +407,15 @@ describe Object, "#guard_not" do
|
|||
end
|
||||
|
||||
it "raises an error if no Proc is given" do
|
||||
-> { guard_not :foo }.should raise_error(RuntimeError)
|
||||
expect { guard_not :foo }.to raise_error(RuntimeError)
|
||||
end
|
||||
|
||||
it "requires a block" do
|
||||
-> {
|
||||
expect {
|
||||
guard_not(-> { true })
|
||||
}.should raise_error(LocalJumpError)
|
||||
-> {
|
||||
}.to raise_error(LocalJumpError)
|
||||
expect {
|
||||
guard_not(-> { false })
|
||||
}.should raise_error(LocalJumpError)
|
||||
}.to raise_error(LocalJumpError)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,252 +1,252 @@
|
|||
require 'spec_helper'
|
||||
require 'mspec/guards'
|
||||
|
||||
describe Object, "#platform_is" do
|
||||
RSpec.describe Object, "#platform_is" do
|
||||
before :each do
|
||||
@guard = PlatformGuard.new :dummy
|
||||
PlatformGuard.stub(:new).and_return(@guard)
|
||||
allow(PlatformGuard).to receive(:new).and_return(@guard)
|
||||
ScratchPad.clear
|
||||
end
|
||||
|
||||
it "does not yield when #os? returns false" do
|
||||
PlatformGuard.stub(:os?).and_return(false)
|
||||
allow(PlatformGuard).to receive(:os?).and_return(false)
|
||||
platform_is(:ruby) { ScratchPad.record :yield }
|
||||
ScratchPad.recorded.should_not == :yield
|
||||
expect(ScratchPad.recorded).not_to eq(:yield)
|
||||
end
|
||||
|
||||
it "yields when #os? returns true" do
|
||||
PlatformGuard.stub(:os?).and_return(true)
|
||||
allow(PlatformGuard).to receive(:os?).and_return(true)
|
||||
platform_is(:solarce) { ScratchPad.record :yield }
|
||||
ScratchPad.recorded.should == :yield
|
||||
expect(ScratchPad.recorded).to eq(:yield)
|
||||
end
|
||||
|
||||
it "returns what #os? returns when no block is given" do
|
||||
PlatformGuard.stub(:os?).and_return(true)
|
||||
platform_is(:solarce).should == true
|
||||
PlatformGuard.stub(:os?).and_return(false)
|
||||
platform_is(:solarce).should == false
|
||||
allow(PlatformGuard).to receive(:os?).and_return(true)
|
||||
expect(platform_is(:solarce)).to eq(true)
|
||||
allow(PlatformGuard).to receive(:os?).and_return(false)
|
||||
expect(platform_is(:solarce)).to eq(false)
|
||||
end
|
||||
|
||||
it "sets the name of the guard to :platform_is" do
|
||||
platform_is(:solarce) { }
|
||||
@guard.name.should == :platform_is
|
||||
expect(@guard.name).to eq(:platform_is)
|
||||
end
|
||||
|
||||
it "calls #unregister even when an exception is raised in the guard block" do
|
||||
@guard.should_receive(:match?).and_return(true)
|
||||
@guard.should_receive(:unregister)
|
||||
lambda do
|
||||
expect(@guard).to receive(:match?).and_return(true)
|
||||
expect(@guard).to receive(:unregister)
|
||||
expect do
|
||||
platform_is(:solarce) { raise Exception }
|
||||
end.should raise_error(Exception)
|
||||
end.to raise_error(Exception)
|
||||
end
|
||||
end
|
||||
|
||||
describe Object, "#platform_is_not" do
|
||||
RSpec.describe Object, "#platform_is_not" do
|
||||
before :each do
|
||||
@guard = PlatformGuard.new :dummy
|
||||
PlatformGuard.stub(:new).and_return(@guard)
|
||||
allow(PlatformGuard).to receive(:new).and_return(@guard)
|
||||
ScratchPad.clear
|
||||
end
|
||||
|
||||
it "does not yield when #os? returns true" do
|
||||
PlatformGuard.stub(:os?).and_return(true)
|
||||
allow(PlatformGuard).to receive(:os?).and_return(true)
|
||||
platform_is_not(:ruby) { ScratchPad.record :yield }
|
||||
ScratchPad.recorded.should_not == :yield
|
||||
expect(ScratchPad.recorded).not_to eq(:yield)
|
||||
end
|
||||
|
||||
it "yields when #os? returns false" do
|
||||
PlatformGuard.stub(:os?).and_return(false)
|
||||
allow(PlatformGuard).to receive(:os?).and_return(false)
|
||||
platform_is_not(:solarce) { ScratchPad.record :yield }
|
||||
ScratchPad.recorded.should == :yield
|
||||
expect(ScratchPad.recorded).to eq(:yield)
|
||||
end
|
||||
|
||||
it "returns the opposite of what #os? returns when no block is given" do
|
||||
PlatformGuard.stub(:os?).and_return(true)
|
||||
platform_is_not(:solarce).should == false
|
||||
PlatformGuard.stub(:os?).and_return(false)
|
||||
platform_is_not(:solarce).should == true
|
||||
allow(PlatformGuard).to receive(:os?).and_return(true)
|
||||
expect(platform_is_not(:solarce)).to eq(false)
|
||||
allow(PlatformGuard).to receive(:os?).and_return(false)
|
||||
expect(platform_is_not(:solarce)).to eq(true)
|
||||
end
|
||||
|
||||
it "sets the name of the guard to :platform_is_not" do
|
||||
platform_is_not(:solarce) { }
|
||||
@guard.name.should == :platform_is_not
|
||||
expect(@guard.name).to eq(:platform_is_not)
|
||||
end
|
||||
|
||||
it "calls #unregister even when an exception is raised in the guard block" do
|
||||
@guard.should_receive(:match?).and_return(false)
|
||||
@guard.should_receive(:unregister)
|
||||
lambda do
|
||||
expect(@guard).to receive(:match?).and_return(false)
|
||||
expect(@guard).to receive(:unregister)
|
||||
expect do
|
||||
platform_is_not(:solarce) { raise Exception }
|
||||
end.should raise_error(Exception)
|
||||
end.to raise_error(Exception)
|
||||
end
|
||||
end
|
||||
|
||||
describe Object, "#platform_is :wordsize => SIZE_SPEC" do
|
||||
RSpec.describe Object, "#platform_is :wordsize => SIZE_SPEC" do
|
||||
before :each do
|
||||
@guard = PlatformGuard.new :darwin, :wordsize => 32
|
||||
PlatformGuard.stub(:os?).and_return(true)
|
||||
PlatformGuard.stub(:new).and_return(@guard)
|
||||
allow(PlatformGuard).to receive(:os?).and_return(true)
|
||||
allow(PlatformGuard).to receive(:new).and_return(@guard)
|
||||
ScratchPad.clear
|
||||
end
|
||||
|
||||
it "yields when #wordsize? returns true" do
|
||||
PlatformGuard.stub(:wordsize?).and_return(true)
|
||||
allow(PlatformGuard).to receive(:wordsize?).and_return(true)
|
||||
platform_is(:wordsize => 32) { ScratchPad.record :yield }
|
||||
ScratchPad.recorded.should == :yield
|
||||
expect(ScratchPad.recorded).to eq(:yield)
|
||||
end
|
||||
|
||||
it "doesn not yield when #wordsize? returns false" do
|
||||
PlatformGuard.stub(:wordsize?).and_return(false)
|
||||
allow(PlatformGuard).to receive(:wordsize?).and_return(false)
|
||||
platform_is(:wordsize => 32) { ScratchPad.record :yield }
|
||||
ScratchPad.recorded.should_not == :yield
|
||||
expect(ScratchPad.recorded).not_to eq(:yield)
|
||||
end
|
||||
end
|
||||
|
||||
describe Object, "#platform_is_not :wordsize => SIZE_SPEC" do
|
||||
RSpec.describe Object, "#platform_is_not :wordsize => SIZE_SPEC" do
|
||||
before :each do
|
||||
@guard = PlatformGuard.new :darwin, :wordsize => 32
|
||||
PlatformGuard.stub(:os?).and_return(true)
|
||||
PlatformGuard.stub(:new).and_return(@guard)
|
||||
allow(PlatformGuard).to receive(:os?).and_return(true)
|
||||
allow(PlatformGuard).to receive(:new).and_return(@guard)
|
||||
ScratchPad.clear
|
||||
end
|
||||
|
||||
it "yields when #wordsize? returns false" do
|
||||
PlatformGuard.stub(:wordsize?).and_return(false)
|
||||
allow(PlatformGuard).to receive(:wordsize?).and_return(false)
|
||||
platform_is_not(:wordsize => 32) { ScratchPad.record :yield }
|
||||
ScratchPad.recorded.should == :yield
|
||||
expect(ScratchPad.recorded).to eq(:yield)
|
||||
end
|
||||
|
||||
it "doesn not yield when #wordsize? returns true" do
|
||||
PlatformGuard.stub(:wordsize?).and_return(true)
|
||||
allow(PlatformGuard).to receive(:wordsize?).and_return(true)
|
||||
platform_is_not(:wordsize => 32) { ScratchPad.record :yield }
|
||||
ScratchPad.recorded.should_not == :yield
|
||||
expect(ScratchPad.recorded).not_to eq(:yield)
|
||||
end
|
||||
end
|
||||
|
||||
describe PlatformGuard, ".implementation?" do
|
||||
RSpec.describe PlatformGuard, ".implementation?" do
|
||||
it "returns true if passed :ruby and RUBY_ENGINE == 'ruby'" do
|
||||
stub_const 'RUBY_ENGINE', 'ruby'
|
||||
PlatformGuard.implementation?(:ruby).should == true
|
||||
expect(PlatformGuard.implementation?(:ruby)).to eq(true)
|
||||
end
|
||||
|
||||
it "returns true if passed :rubinius and RUBY_ENGINE == 'rbx'" do
|
||||
stub_const 'RUBY_ENGINE', 'rbx'
|
||||
PlatformGuard.implementation?(:rubinius).should == true
|
||||
expect(PlatformGuard.implementation?(:rubinius)).to eq(true)
|
||||
end
|
||||
|
||||
it "returns true if passed :jruby and RUBY_ENGINE == 'jruby'" do
|
||||
stub_const 'RUBY_ENGINE', 'jruby'
|
||||
PlatformGuard.implementation?(:jruby).should == true
|
||||
expect(PlatformGuard.implementation?(:jruby)).to eq(true)
|
||||
end
|
||||
|
||||
it "returns true if passed :ironruby and RUBY_ENGINE == 'ironruby'" do
|
||||
stub_const 'RUBY_ENGINE', 'ironruby'
|
||||
PlatformGuard.implementation?(:ironruby).should == true
|
||||
expect(PlatformGuard.implementation?(:ironruby)).to eq(true)
|
||||
end
|
||||
|
||||
it "returns true if passed :maglev and RUBY_ENGINE == 'maglev'" do
|
||||
stub_const 'RUBY_ENGINE', 'maglev'
|
||||
PlatformGuard.implementation?(:maglev).should == true
|
||||
expect(PlatformGuard.implementation?(:maglev)).to eq(true)
|
||||
end
|
||||
|
||||
it "returns true if passed :topaz and RUBY_ENGINE == 'topaz'" do
|
||||
stub_const 'RUBY_ENGINE', 'topaz'
|
||||
PlatformGuard.implementation?(:topaz).should == true
|
||||
expect(PlatformGuard.implementation?(:topaz)).to eq(true)
|
||||
end
|
||||
|
||||
it "returns true if passed :ruby and RUBY_ENGINE matches /^ruby/" do
|
||||
stub_const 'RUBY_ENGINE', 'ruby'
|
||||
PlatformGuard.implementation?(:ruby).should == true
|
||||
expect(PlatformGuard.implementation?(:ruby)).to eq(true)
|
||||
|
||||
stub_const 'RUBY_ENGINE', 'ruby1.8'
|
||||
PlatformGuard.implementation?(:ruby).should == true
|
||||
expect(PlatformGuard.implementation?(:ruby)).to eq(true)
|
||||
|
||||
stub_const 'RUBY_ENGINE', 'ruby1.9'
|
||||
PlatformGuard.implementation?(:ruby).should == true
|
||||
expect(PlatformGuard.implementation?(:ruby)).to eq(true)
|
||||
end
|
||||
|
||||
it "works for an unrecognized name" do
|
||||
stub_const 'RUBY_ENGINE', 'myrubyimplementation'
|
||||
PlatformGuard.implementation?(:myrubyimplementation).should == true
|
||||
PlatformGuard.implementation?(:other).should == false
|
||||
expect(PlatformGuard.implementation?(:myrubyimplementation)).to eq(true)
|
||||
expect(PlatformGuard.implementation?(:other)).to eq(false)
|
||||
end
|
||||
end
|
||||
|
||||
describe PlatformGuard, ".standard?" do
|
||||
RSpec.describe PlatformGuard, ".standard?" do
|
||||
it "returns true if implementation? returns true" do
|
||||
PlatformGuard.should_receive(:implementation?).with(:ruby).and_return(true)
|
||||
PlatformGuard.standard?.should be_true
|
||||
expect(PlatformGuard).to receive(:implementation?).with(:ruby).and_return(true)
|
||||
expect(PlatformGuard.standard?).to be_truthy
|
||||
end
|
||||
|
||||
it "returns false if implementation? returns false" do
|
||||
PlatformGuard.should_receive(:implementation?).with(:ruby).and_return(false)
|
||||
PlatformGuard.standard?.should be_false
|
||||
expect(PlatformGuard).to receive(:implementation?).with(:ruby).and_return(false)
|
||||
expect(PlatformGuard.standard?).to be_falsey
|
||||
end
|
||||
end
|
||||
|
||||
describe PlatformGuard, ".wordsize?" do
|
||||
RSpec.describe PlatformGuard, ".wordsize?" do
|
||||
it "returns true when arg is 32 and 1.size is 4" do
|
||||
PlatformGuard.wordsize?(32).should == (1.size == 4)
|
||||
expect(PlatformGuard.wordsize?(32)).to eq(1.size == 4)
|
||||
end
|
||||
|
||||
it "returns true when arg is 64 and 1.size is 8" do
|
||||
PlatformGuard.wordsize?(64).should == (1.size == 8)
|
||||
expect(PlatformGuard.wordsize?(64)).to eq(1.size == 8)
|
||||
end
|
||||
end
|
||||
|
||||
describe PlatformGuard, ".os?" do
|
||||
RSpec.describe PlatformGuard, ".os?" do
|
||||
before :each do
|
||||
stub_const 'PlatformGuard::PLATFORM', 'solarce'
|
||||
end
|
||||
|
||||
it "returns false when arg does not match the platform" do
|
||||
PlatformGuard.os?(:ruby).should == false
|
||||
expect(PlatformGuard.os?(:ruby)).to eq(false)
|
||||
end
|
||||
|
||||
it "returns false when no arg matches the platform" do
|
||||
PlatformGuard.os?(:ruby, :jruby, :rubinius, :maglev).should == false
|
||||
expect(PlatformGuard.os?(:ruby, :jruby, :rubinius, :maglev)).to eq(false)
|
||||
end
|
||||
|
||||
it "returns true when arg matches the platform" do
|
||||
PlatformGuard.os?(:solarce).should == true
|
||||
expect(PlatformGuard.os?(:solarce)).to eq(true)
|
||||
end
|
||||
|
||||
it "returns true when any arg matches the platform" do
|
||||
PlatformGuard.os?(:ruby, :jruby, :solarce, :rubinius, :maglev).should == true
|
||||
expect(PlatformGuard.os?(:ruby, :jruby, :solarce, :rubinius, :maglev)).to eq(true)
|
||||
end
|
||||
|
||||
it "returns true when arg is :windows and the platform contains 'mswin'" do
|
||||
stub_const 'PlatformGuard::PLATFORM', 'mswin32'
|
||||
PlatformGuard.os?(:windows).should == true
|
||||
expect(PlatformGuard.os?(:windows)).to eq(true)
|
||||
end
|
||||
|
||||
it "returns true when arg is :windows and the platform contains 'mingw'" do
|
||||
stub_const 'PlatformGuard::PLATFORM', 'i386-mingw32'
|
||||
PlatformGuard.os?(:windows).should == true
|
||||
expect(PlatformGuard.os?(:windows)).to eq(true)
|
||||
end
|
||||
|
||||
it "returns false when arg is not :windows and RbConfig::CONFIG['host_os'] contains 'mswin'" do
|
||||
stub_const 'PlatformGuard::PLATFORM', 'i386-mswin32'
|
||||
PlatformGuard.os?(:linux).should == false
|
||||
expect(PlatformGuard.os?(:linux)).to eq(false)
|
||||
end
|
||||
|
||||
it "returns false when arg is not :windows and RbConfig::CONFIG['host_os'] contains 'mingw'" do
|
||||
stub_const 'PlatformGuard::PLATFORM', 'i386-mingw32'
|
||||
PlatformGuard.os?(:linux).should == false
|
||||
expect(PlatformGuard.os?(:linux)).to eq(false)
|
||||
end
|
||||
end
|
||||
|
||||
describe PlatformGuard, ".os?" do
|
||||
RSpec.describe PlatformGuard, ".os?" do
|
||||
it "returns true if called with the current OS or architecture" do
|
||||
os = RbConfig::CONFIG["host_os"].sub("-gnu", "")
|
||||
arch = RbConfig::CONFIG["host_arch"]
|
||||
PlatformGuard.os?(os).should == true
|
||||
PlatformGuard.os?(arch).should == true
|
||||
PlatformGuard.os?("#{arch}-#{os}").should == true
|
||||
expect(PlatformGuard.os?(os)).to eq(true)
|
||||
expect(PlatformGuard.os?(arch)).to eq(true)
|
||||
expect(PlatformGuard.os?("#{arch}-#{os}")).to eq(true)
|
||||
end
|
||||
end
|
||||
|
||||
describe PlatformGuard, ".os? on JRuby" do
|
||||
RSpec.describe PlatformGuard, ".os? on JRuby" do
|
||||
before :all do
|
||||
@verbose = $VERBOSE
|
||||
$VERBOSE = nil
|
||||
|
@ -266,72 +266,72 @@ describe PlatformGuard, ".os? on JRuby" do
|
|||
end
|
||||
|
||||
it "raises an error when testing for a :java platform" do
|
||||
lambda {
|
||||
expect {
|
||||
PlatformGuard.os?(:java)
|
||||
}.should raise_error(":java is not a valid OS")
|
||||
}.to raise_error(":java is not a valid OS")
|
||||
end
|
||||
|
||||
it "returns true when arg is :windows and RUBY_PLATFORM contains 'java' and os?(:windows) is true" do
|
||||
stub_const 'PlatformGuard::PLATFORM', 'mswin32'
|
||||
PlatformGuard.os?(:windows).should == true
|
||||
expect(PlatformGuard.os?(:windows)).to eq(true)
|
||||
end
|
||||
|
||||
it "returns true when RUBY_PLATFORM contains 'java' and os?(argument) is true" do
|
||||
stub_const 'PlatformGuard::PLATFORM', 'amiga'
|
||||
PlatformGuard.os?(:amiga).should == true
|
||||
expect(PlatformGuard.os?(:amiga)).to eq(true)
|
||||
end
|
||||
end
|
||||
|
||||
describe PlatformGuard, ".os?" do
|
||||
RSpec.describe PlatformGuard, ".os?" do
|
||||
before :each do
|
||||
stub_const 'PlatformGuard::PLATFORM', 'unreal'
|
||||
end
|
||||
|
||||
it "returns true if argument matches RbConfig::CONFIG['host_os']" do
|
||||
PlatformGuard.os?(:unreal).should == true
|
||||
expect(PlatformGuard.os?(:unreal)).to eq(true)
|
||||
end
|
||||
|
||||
it "returns true if any argument matches RbConfig::CONFIG['host_os']" do
|
||||
PlatformGuard.os?(:bsd, :unreal, :amiga).should == true
|
||||
expect(PlatformGuard.os?(:bsd, :unreal, :amiga)).to eq(true)
|
||||
end
|
||||
|
||||
it "returns false if no argument matches RbConfig::CONFIG['host_os']" do
|
||||
PlatformGuard.os?(:bsd, :netbsd, :amiga, :msdos).should == false
|
||||
expect(PlatformGuard.os?(:bsd, :netbsd, :amiga, :msdos)).to eq(false)
|
||||
end
|
||||
|
||||
it "returns false if argument does not match RbConfig::CONFIG['host_os']" do
|
||||
PlatformGuard.os?(:amiga).should == false
|
||||
expect(PlatformGuard.os?(:amiga)).to eq(false)
|
||||
end
|
||||
|
||||
it "returns true when arg is :windows and RbConfig::CONFIG['host_os'] contains 'mswin'" do
|
||||
stub_const 'PlatformGuard::PLATFORM', 'i386-mswin32'
|
||||
PlatformGuard.os?(:windows).should == true
|
||||
expect(PlatformGuard.os?(:windows)).to eq(true)
|
||||
end
|
||||
|
||||
it "returns true when arg is :windows and RbConfig::CONFIG['host_os'] contains 'mingw'" do
|
||||
stub_const 'PlatformGuard::PLATFORM', 'i386-mingw32'
|
||||
PlatformGuard.os?(:windows).should == true
|
||||
expect(PlatformGuard.os?(:windows)).to eq(true)
|
||||
end
|
||||
|
||||
it "returns false when arg is not :windows and RbConfig::CONFIG['host_os'] contains 'mswin'" do
|
||||
stub_const 'PlatformGuard::PLATFORM', 'i386-mingw32'
|
||||
PlatformGuard.os?(:linux).should == false
|
||||
expect(PlatformGuard.os?(:linux)).to eq(false)
|
||||
end
|
||||
|
||||
it "returns false when arg is not :windows and RbConfig::CONFIG['host_os'] contains 'mingw'" do
|
||||
stub_const 'PlatformGuard::PLATFORM', 'i386-mingw32'
|
||||
PlatformGuard.os?(:linux).should == false
|
||||
expect(PlatformGuard.os?(:linux)).to eq(false)
|
||||
end
|
||||
end
|
||||
|
||||
describe PlatformGuard, ".windows?" do
|
||||
RSpec.describe PlatformGuard, ".windows?" do
|
||||
it "returns true on windows" do
|
||||
stub_const 'PlatformGuard::PLATFORM', 'i386-mingw32'
|
||||
PlatformGuard.windows?.should == true
|
||||
expect(PlatformGuard.windows?).to eq(true)
|
||||
end
|
||||
|
||||
it "returns false on non-windows" do
|
||||
stub_const 'PlatformGuard::PLATFORM', 'i586-linux'
|
||||
PlatformGuard.windows?.should == false
|
||||
expect(PlatformGuard.windows?).to eq(false)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,35 +1,35 @@
|
|||
require 'spec_helper'
|
||||
require 'mspec/guards'
|
||||
|
||||
describe QuarantineGuard, "#match?" do
|
||||
RSpec.describe QuarantineGuard, "#match?" do
|
||||
it "returns true" do
|
||||
QuarantineGuard.new.match?.should == true
|
||||
expect(QuarantineGuard.new.match?).to eq(true)
|
||||
end
|
||||
end
|
||||
|
||||
describe Object, "#quarantine!" do
|
||||
RSpec.describe Object, "#quarantine!" do
|
||||
before :each do
|
||||
ScratchPad.clear
|
||||
|
||||
@guard = QuarantineGuard.new
|
||||
QuarantineGuard.stub(:new).and_return(@guard)
|
||||
allow(QuarantineGuard).to receive(:new).and_return(@guard)
|
||||
end
|
||||
|
||||
it "does not yield" do
|
||||
quarantine! { ScratchPad.record :yield }
|
||||
ScratchPad.recorded.should_not == :yield
|
||||
expect(ScratchPad.recorded).not_to eq(:yield)
|
||||
end
|
||||
|
||||
it "sets the name of the guard to :quarantine!" do
|
||||
quarantine! { }
|
||||
@guard.name.should == :quarantine!
|
||||
expect(@guard.name).to eq(:quarantine!)
|
||||
end
|
||||
|
||||
it "calls #unregister even when an exception is raised in the guard block" do
|
||||
@guard.should_receive(:match?).and_return(false)
|
||||
@guard.should_receive(:unregister)
|
||||
lambda do
|
||||
expect(@guard).to receive(:match?).and_return(false)
|
||||
expect(@guard).to receive(:unregister)
|
||||
expect do
|
||||
quarantine! { raise Exception }
|
||||
end.should raise_error(Exception)
|
||||
end.to raise_error(Exception)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,35 +1,35 @@
|
|||
require 'spec_helper'
|
||||
require 'mspec/guards'
|
||||
|
||||
describe Object, "#as_superuser" do
|
||||
RSpec.describe Object, "#as_superuser" do
|
||||
before :each do
|
||||
@guard = SuperUserGuard.new
|
||||
SuperUserGuard.stub(:new).and_return(@guard)
|
||||
allow(SuperUserGuard).to receive(:new).and_return(@guard)
|
||||
ScratchPad.clear
|
||||
end
|
||||
|
||||
it "does not yield when Process.euid is not 0" do
|
||||
Process.stub(:euid).and_return(501)
|
||||
allow(Process).to receive(:euid).and_return(501)
|
||||
as_superuser { ScratchPad.record :yield }
|
||||
ScratchPad.recorded.should_not == :yield
|
||||
expect(ScratchPad.recorded).not_to eq(:yield)
|
||||
end
|
||||
|
||||
it "yields when Process.euid is 0" do
|
||||
Process.stub(:euid).and_return(0)
|
||||
allow(Process).to receive(:euid).and_return(0)
|
||||
as_superuser { ScratchPad.record :yield }
|
||||
ScratchPad.recorded.should == :yield
|
||||
expect(ScratchPad.recorded).to eq(:yield)
|
||||
end
|
||||
|
||||
it "sets the name of the guard to :as_superuser" do
|
||||
as_superuser { }
|
||||
@guard.name.should == :as_superuser
|
||||
expect(@guard.name).to eq(:as_superuser)
|
||||
end
|
||||
|
||||
it "calls #unregister even when an exception is raised in the guard block" do
|
||||
@guard.should_receive(:match?).and_return(true)
|
||||
@guard.should_receive(:unregister)
|
||||
lambda do
|
||||
expect(@guard).to receive(:match?).and_return(true)
|
||||
expect(@guard).to receive(:unregister)
|
||||
expect do
|
||||
as_superuser { raise Exception }
|
||||
end.should raise_error(Exception)
|
||||
end.to raise_error(Exception)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,54 +1,54 @@
|
|||
require 'spec_helper'
|
||||
require 'mspec/guards'
|
||||
|
||||
describe Object, "#not_supported_on" do
|
||||
RSpec.describe Object, "#not_supported_on" do
|
||||
before :each do
|
||||
ScratchPad.clear
|
||||
end
|
||||
|
||||
it "raises an Exception when passed :ruby" do
|
||||
stub_const "RUBY_ENGINE", "jruby"
|
||||
lambda {
|
||||
expect {
|
||||
not_supported_on(:ruby) { ScratchPad.record :yield }
|
||||
}.should raise_error(Exception)
|
||||
ScratchPad.recorded.should_not == :yield
|
||||
}.to raise_error(Exception)
|
||||
expect(ScratchPad.recorded).not_to eq(:yield)
|
||||
end
|
||||
|
||||
it "does not yield when #implementation? returns true" do
|
||||
stub_const "RUBY_ENGINE", "jruby"
|
||||
not_supported_on(:jruby) { ScratchPad.record :yield }
|
||||
ScratchPad.recorded.should_not == :yield
|
||||
expect(ScratchPad.recorded).not_to eq(:yield)
|
||||
end
|
||||
|
||||
it "yields when #standard? returns true" do
|
||||
stub_const "RUBY_ENGINE", "ruby"
|
||||
not_supported_on(:rubinius) { ScratchPad.record :yield }
|
||||
ScratchPad.recorded.should == :yield
|
||||
expect(ScratchPad.recorded).to eq(:yield)
|
||||
end
|
||||
|
||||
it "yields when #implementation? returns false" do
|
||||
stub_const "RUBY_ENGINE", "jruby"
|
||||
not_supported_on(:rubinius) { ScratchPad.record :yield }
|
||||
ScratchPad.recorded.should == :yield
|
||||
expect(ScratchPad.recorded).to eq(:yield)
|
||||
end
|
||||
end
|
||||
|
||||
describe Object, "#not_supported_on" do
|
||||
RSpec.describe Object, "#not_supported_on" do
|
||||
before :each do
|
||||
@guard = SupportedGuard.new
|
||||
SupportedGuard.stub(:new).and_return(@guard)
|
||||
allow(SupportedGuard).to receive(:new).and_return(@guard)
|
||||
end
|
||||
|
||||
it "sets the name of the guard to :not_supported_on" do
|
||||
not_supported_on(:rubinius) { }
|
||||
@guard.name.should == :not_supported_on
|
||||
expect(@guard.name).to eq(:not_supported_on)
|
||||
end
|
||||
|
||||
it "calls #unregister even when an exception is raised in the guard block" do
|
||||
@guard.should_receive(:match?).and_return(false)
|
||||
@guard.should_receive(:unregister)
|
||||
lambda do
|
||||
expect(@guard).to receive(:match?).and_return(false)
|
||||
expect(@guard).to receive(:unregister)
|
||||
expect do
|
||||
not_supported_on(:rubinius) { raise Exception }
|
||||
end.should raise_error(Exception)
|
||||
end.to raise_error(Exception)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,20 +1,20 @@
|
|||
require 'spec_helper'
|
||||
require 'mspec/guards'
|
||||
|
||||
describe Object, "#as_user" do
|
||||
RSpec.describe Object, "#as_user" do
|
||||
before :each do
|
||||
ScratchPad.clear
|
||||
end
|
||||
|
||||
it "yields when the Process.euid is not 0" do
|
||||
Process.stub(:euid).and_return(501)
|
||||
allow(Process).to receive(:euid).and_return(501)
|
||||
as_user { ScratchPad.record :yield }
|
||||
ScratchPad.recorded.should == :yield
|
||||
expect(ScratchPad.recorded).to eq(:yield)
|
||||
end
|
||||
|
||||
it "does not yield when the Process.euid is 0" do
|
||||
Process.stub(:euid).and_return(0)
|
||||
allow(Process).to receive(:euid).and_return(0)
|
||||
as_user { ScratchPad.record :yield }
|
||||
ScratchPad.recorded.should_not == :yield
|
||||
expect(ScratchPad.recorded).not_to eq(:yield)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -11,102 +11,102 @@ require 'mspec/guards'
|
|||
# is as typically understood: a..b means v >= a and v <= b;
|
||||
# a...b means v >= a and v < b.
|
||||
|
||||
describe VersionGuard, "#match?" do
|
||||
RSpec.describe VersionGuard, "#match?" do
|
||||
before :each do
|
||||
hide_deprecation_warnings
|
||||
@current = '1.8.6'
|
||||
end
|
||||
|
||||
it "returns true when the argument is equal to RUBY_VERSION" do
|
||||
VersionGuard.new(@current, '1.8.6').match?.should == true
|
||||
expect(VersionGuard.new(@current, '1.8.6').match?).to eq(true)
|
||||
end
|
||||
|
||||
it "returns true when the argument is less than RUBY_VERSION" do
|
||||
VersionGuard.new(@current, '1.8').match?.should == true
|
||||
VersionGuard.new(@current, '1.8.5').match?.should == true
|
||||
expect(VersionGuard.new(@current, '1.8').match?).to eq(true)
|
||||
expect(VersionGuard.new(@current, '1.8.5').match?).to eq(true)
|
||||
end
|
||||
|
||||
it "returns false when the argument is greater than RUBY_VERSION" do
|
||||
VersionGuard.new(@current, '1.8.7').match?.should == false
|
||||
VersionGuard.new(@current, '1.9.2').match?.should == false
|
||||
expect(VersionGuard.new(@current, '1.8.7').match?).to eq(false)
|
||||
expect(VersionGuard.new(@current, '1.9.2').match?).to eq(false)
|
||||
end
|
||||
|
||||
it "returns true when the argument range includes RUBY_VERSION" do
|
||||
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
|
||||
expect(VersionGuard.new(@current, '1.8.5'..'1.8.7').match?).to eq(true)
|
||||
expect(VersionGuard.new(@current, '1.8'..'1.9').match?).to eq(true)
|
||||
expect(VersionGuard.new(@current, '1.8'...'1.9').match?).to eq(true)
|
||||
expect(VersionGuard.new(@current, '1.8'..'1.8.6').match?).to eq(true)
|
||||
expect(VersionGuard.new(@current, '1.8.5'..'1.8.6').match?).to eq(true)
|
||||
expect(VersionGuard.new(@current, ''...'1.8.7').match?).to eq(true)
|
||||
end
|
||||
|
||||
it "returns false when the argument range does not include RUBY_VERSION" do
|
||||
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
|
||||
expect(VersionGuard.new(@current, '1.8.7'..'1.8.9').match?).to eq(false)
|
||||
expect(VersionGuard.new(@current, '1.8.4'..'1.8.5').match?).to eq(false)
|
||||
expect(VersionGuard.new(@current, '1.8.4'...'1.8.6').match?).to eq(false)
|
||||
expect(VersionGuard.new(@current, '1.8.5'...'1.8.6').match?).to eq(false)
|
||||
expect(VersionGuard.new(@current, ''...'1.8.6').match?).to eq(false)
|
||||
end
|
||||
end
|
||||
|
||||
describe Object, "#ruby_version_is" do
|
||||
RSpec.describe Object, "#ruby_version_is" do
|
||||
before :each do
|
||||
@guard = VersionGuard.new '1.2.3', 'x.x.x'
|
||||
VersionGuard.stub(:new).and_return(@guard)
|
||||
allow(VersionGuard).to receive(:new).and_return(@guard)
|
||||
ScratchPad.clear
|
||||
end
|
||||
|
||||
it "yields when #match? returns true" do
|
||||
@guard.stub(:match?).and_return(true)
|
||||
allow(@guard).to receive(:match?).and_return(true)
|
||||
ruby_version_is('x.x.x') { ScratchPad.record :yield }
|
||||
ScratchPad.recorded.should == :yield
|
||||
expect(ScratchPad.recorded).to eq(:yield)
|
||||
end
|
||||
|
||||
it "does not yield when #match? returns false" do
|
||||
@guard.stub(:match?).and_return(false)
|
||||
allow(@guard).to receive(:match?).and_return(false)
|
||||
ruby_version_is('x.x.x') { ScratchPad.record :yield }
|
||||
ScratchPad.recorded.should_not == :yield
|
||||
expect(ScratchPad.recorded).not_to eq(:yield)
|
||||
end
|
||||
|
||||
it "returns what #match? returns when no block is given" do
|
||||
@guard.stub(:match?).and_return(true)
|
||||
ruby_version_is('x.x.x').should == true
|
||||
@guard.stub(:match?).and_return(false)
|
||||
ruby_version_is('x.x.x').should == false
|
||||
allow(@guard).to receive(:match?).and_return(true)
|
||||
expect(ruby_version_is('x.x.x')).to eq(true)
|
||||
allow(@guard).to receive(:match?).and_return(false)
|
||||
expect(ruby_version_is('x.x.x')).to eq(false)
|
||||
end
|
||||
|
||||
it "sets the name of the guard to :ruby_version_is" do
|
||||
ruby_version_is("") { }
|
||||
@guard.name.should == :ruby_version_is
|
||||
expect(@guard.name).to eq(:ruby_version_is)
|
||||
end
|
||||
|
||||
it "calls #unregister even when an exception is raised in the guard block" do
|
||||
@guard.should_receive(:match?).and_return(true)
|
||||
@guard.should_receive(:unregister)
|
||||
lambda do
|
||||
expect(@guard).to receive(:match?).and_return(true)
|
||||
expect(@guard).to receive(:unregister)
|
||||
expect do
|
||||
ruby_version_is("") { raise Exception }
|
||||
end.should raise_error(Exception)
|
||||
end.to raise_error(Exception)
|
||||
end
|
||||
end
|
||||
|
||||
describe Object, "#version_is" do
|
||||
RSpec.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
|
||||
expect(version_is('1.2.3', '1.2.2')).to eq(true)
|
||||
expect(version_is('1.2.3', '1.2.3')).to eq(true)
|
||||
expect(version_is('1.2.3', '1.2.4')).to eq(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
|
||||
expect(version_is('1.2.3', '1')).to eq(true)
|
||||
expect(version_is('1.2.3', '1.0')).to eq(true)
|
||||
expect(version_is('1.2.3', '2')).to eq(false)
|
||||
expect(version_is('1.2.3', '2.0')).to eq(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
|
||||
expect(version_is('1.2.3', '1.2.2'..'1.2.4')).to eq(true)
|
||||
expect(version_is('1.2.3', '1.2.2'..'1.2.3')).to eq(true)
|
||||
expect(version_is('1.2.3', '1.2.2'...'1.2.3')).to eq(false)
|
||||
expect(version_is('1.2.3', '1.2.3'..'1.2.4')).to eq(true)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -2,7 +2,7 @@ require 'spec_helper'
|
|||
require 'mspec/guards'
|
||||
require 'mspec/helpers'
|
||||
|
||||
describe Object, "#argf" do
|
||||
RSpec.describe Object, "#argf" do
|
||||
before :each do
|
||||
@saved_argv = ARGV.dup
|
||||
@argv = [__FILE__]
|
||||
|
@ -10,28 +10,28 @@ describe Object, "#argf" do
|
|||
|
||||
it "sets @argf to an instance of ARGF.class with the given argv" do
|
||||
argf @argv do
|
||||
@argf.should be_an_instance_of ARGF.class
|
||||
@argf.filename.should == @argv.first
|
||||
expect(@argf).to be_an_instance_of ARGF.class
|
||||
expect(@argf.filename).to eq(@argv.first)
|
||||
end
|
||||
@argf.should be_nil
|
||||
expect(@argf).to be_nil
|
||||
end
|
||||
|
||||
it "does not alter ARGV nor ARGF" do
|
||||
argf @argv do
|
||||
end
|
||||
ARGV.should == @saved_argv
|
||||
ARGF.argv.should == @saved_argv
|
||||
expect(ARGV).to eq(@saved_argv)
|
||||
expect(ARGF.argv).to eq(@saved_argv)
|
||||
end
|
||||
|
||||
it "does not close STDIN" do
|
||||
argf ['-'] do
|
||||
end
|
||||
STDIN.should_not be_closed
|
||||
expect(STDIN).not_to be_closed
|
||||
end
|
||||
|
||||
it "disallows nested calls" do
|
||||
argf @argv do
|
||||
lambda { argf @argv }.should raise_error
|
||||
expect { argf @argv }.to raise_error
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -2,7 +2,7 @@ require 'spec_helper'
|
|||
require 'mspec/guards'
|
||||
require 'mspec/helpers'
|
||||
|
||||
describe Object, "#argv" do
|
||||
RSpec.describe Object, "#argv" do
|
||||
before :each do
|
||||
ScratchPad.clear
|
||||
|
||||
|
@ -12,16 +12,16 @@ describe Object, "#argv" do
|
|||
|
||||
it "replaces and restores the value of ARGV" do
|
||||
argv @argv
|
||||
ARGV.should == @argv
|
||||
expect(ARGV).to eq(@argv)
|
||||
argv :restore
|
||||
ARGV.should == @saved_argv
|
||||
expect(ARGV).to eq(@saved_argv)
|
||||
end
|
||||
|
||||
it "yields to the block after setting ARGV" do
|
||||
argv @argv do
|
||||
ScratchPad.record ARGV.dup
|
||||
end
|
||||
ScratchPad.recorded.should == @argv
|
||||
ARGV.should == @saved_argv
|
||||
expect(ScratchPad.recorded).to eq(@argv)
|
||||
expect(ARGV).to eq(@saved_argv)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -2,43 +2,43 @@ require 'spec_helper'
|
|||
require 'mspec/guards'
|
||||
require 'mspec/helpers'
|
||||
|
||||
describe Object, "#new_datetime" do
|
||||
RSpec.describe Object, "#new_datetime" do
|
||||
it "returns a default DateTime instance" do
|
||||
new_datetime.should == DateTime.new
|
||||
expect(new_datetime).to eq(DateTime.new)
|
||||
end
|
||||
|
||||
it "returns a DateTime instance with the specified year value" do
|
||||
d = new_datetime :year => 1970
|
||||
d.year.should == 1970
|
||||
expect(d.year).to eq(1970)
|
||||
end
|
||||
|
||||
it "returns a DateTime instance with the specified month value" do
|
||||
d = new_datetime :month => 11
|
||||
d.mon.should == 11
|
||||
expect(d.mon).to eq(11)
|
||||
end
|
||||
|
||||
it "returns a DateTime instance with the specified day value" do
|
||||
d = new_datetime :day => 23
|
||||
d.day.should == 23
|
||||
expect(d.day).to eq(23)
|
||||
end
|
||||
|
||||
it "returns a DateTime instance with the specified hour value" do
|
||||
d = new_datetime :hour => 10
|
||||
d.hour.should == 10
|
||||
expect(d.hour).to eq(10)
|
||||
end
|
||||
|
||||
it "returns a DateTime instance with the specified minute value" do
|
||||
d = new_datetime :minute => 10
|
||||
d.min.should == 10
|
||||
expect(d.min).to eq(10)
|
||||
end
|
||||
|
||||
it "returns a DateTime instance with the specified second value" do
|
||||
d = new_datetime :second => 2
|
||||
d.sec.should == 2
|
||||
expect(d.sec).to eq(2)
|
||||
end
|
||||
|
||||
it "returns a DateTime instance with the specified offset value" do
|
||||
d = new_datetime :offset => Rational(3,24)
|
||||
d.offset.should == Rational(3,24)
|
||||
expect(d.offset).to eq(Rational(3,24))
|
||||
end
|
||||
end
|
||||
|
|
|
@ -2,24 +2,24 @@ require 'spec_helper'
|
|||
require 'mspec/guards'
|
||||
require 'mspec/helpers'
|
||||
|
||||
describe Object, "#fixture" do
|
||||
RSpec.describe Object, "#fixture" do
|
||||
before :each do
|
||||
@dir = File.realpath("..", __FILE__)
|
||||
end
|
||||
|
||||
it "returns the expanded path to a fixture file" do
|
||||
name = fixture(__FILE__, "subdir", "file.txt")
|
||||
name.should == "#{@dir}/fixtures/subdir/file.txt"
|
||||
expect(name).to eq("#{@dir}/fixtures/subdir/file.txt")
|
||||
end
|
||||
|
||||
it "omits '/shared' if it is the suffix of the directory string" do
|
||||
name = fixture("#{@dir}/shared/file.rb", "subdir", "file.txt")
|
||||
name.should == "#{@dir}/fixtures/subdir/file.txt"
|
||||
expect(name).to eq("#{@dir}/fixtures/subdir/file.txt")
|
||||
end
|
||||
|
||||
it "does not append '/fixtures' if it is the suffix of the directory string" do
|
||||
commands_dir = "#{File.dirname(@dir)}/commands"
|
||||
name = fixture("#{commands_dir}/fixtures/file.rb", "subdir", "file.txt")
|
||||
name.should == "#{commands_dir}/fixtures/subdir/file.txt"
|
||||
expect(name).to eq("#{commands_dir}/fixtures/subdir/file.txt")
|
||||
end
|
||||
end
|
||||
|
|
|
@ -4,17 +4,17 @@ require 'mspec/runner/mspec'
|
|||
require 'mspec/guards'
|
||||
require 'mspec/helpers'
|
||||
|
||||
describe Object, "#flunk" do
|
||||
RSpec.describe Object, "#flunk" do
|
||||
before :each do
|
||||
MSpec.stub(:actions)
|
||||
MSpec.stub(:current).and_return(double("spec state").as_null_object)
|
||||
allow(MSpec).to receive(:actions)
|
||||
allow(MSpec).to receive(:current).and_return(double("spec state").as_null_object)
|
||||
end
|
||||
|
||||
it "raises an SpecExpectationNotMetError unconditionally" do
|
||||
lambda { flunk }.should raise_error(SpecExpectationNotMetError)
|
||||
expect { flunk }.to raise_error(SpecExpectationNotMetError)
|
||||
end
|
||||
|
||||
it "accepts on argument for an optional message" do
|
||||
lambda {flunk "test"}.should raise_error(SpecExpectationNotMetError)
|
||||
expect {flunk "test"}.to raise_error(SpecExpectationNotMetError)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -2,7 +2,7 @@ require 'spec_helper'
|
|||
require 'mspec/guards'
|
||||
require 'mspec/helpers'
|
||||
|
||||
describe Object, "#cp" do
|
||||
RSpec.describe Object, "#cp" do
|
||||
before :each do
|
||||
@source = tmp("source.txt")
|
||||
@copy = tmp("copied.txt")
|
||||
|
@ -19,12 +19,12 @@ describe Object, "#cp" do
|
|||
it "copies a file" do
|
||||
cp @source, @copy
|
||||
data = IO.read(@copy)
|
||||
data.should == @contents
|
||||
data.should == IO.read(@source)
|
||||
expect(data).to eq(@contents)
|
||||
expect(data).to eq(IO.read(@source))
|
||||
end
|
||||
end
|
||||
|
||||
describe Object, "#touch" do
|
||||
RSpec.describe Object, "#touch" do
|
||||
before :all do
|
||||
@name = tmp("touched.txt")
|
||||
end
|
||||
|
@ -35,29 +35,29 @@ describe Object, "#touch" do
|
|||
|
||||
it "creates a file" do
|
||||
touch @name
|
||||
File.exist?(@name).should be_true
|
||||
expect(File.exist?(@name)).to be_truthy
|
||||
end
|
||||
|
||||
it "accepts an optional mode argument" do
|
||||
touch @name, "wb"
|
||||
File.exist?(@name).should be_true
|
||||
expect(File.exist?(@name)).to be_truthy
|
||||
end
|
||||
|
||||
it "overwrites an existing file" do
|
||||
File.open(@name, "w") { |f| f.puts "used" }
|
||||
File.size(@name).should > 0
|
||||
expect(File.size(@name)).to be > 0
|
||||
|
||||
touch @name
|
||||
File.size(@name).should == 0
|
||||
expect(File.size(@name)).to eq(0)
|
||||
end
|
||||
|
||||
it "yields the open file if passed a block" do
|
||||
touch(@name) { |f| f.write "touching" }
|
||||
IO.read(@name).should == "touching"
|
||||
expect(IO.read(@name)).to eq("touching")
|
||||
end
|
||||
end
|
||||
|
||||
describe Object, "#touch" do
|
||||
RSpec.describe Object, "#touch" do
|
||||
before :all do
|
||||
@name = tmp("subdir/touched.txt")
|
||||
end
|
||||
|
@ -68,11 +68,11 @@ describe Object, "#touch" do
|
|||
|
||||
it "creates all the directories in the path to the file" do
|
||||
touch @name
|
||||
File.exist?(@name).should be_true
|
||||
expect(File.exist?(@name)).to be_truthy
|
||||
end
|
||||
end
|
||||
|
||||
describe Object, "#mkdir_p" do
|
||||
RSpec.describe Object, "#mkdir_p" do
|
||||
before :all do
|
||||
@dir1 = tmp("/nested")
|
||||
@dir2 = @dir1 + "/directory"
|
||||
|
@ -86,17 +86,17 @@ describe Object, "#mkdir_p" do
|
|||
|
||||
it "creates all the directories in a path" do
|
||||
mkdir_p @dir2
|
||||
File.directory?(@dir2).should be_true
|
||||
expect(File.directory?(@dir2)).to be_truthy
|
||||
end
|
||||
|
||||
it "raises an ArgumentError if a path component is a file" do
|
||||
File.open(@dir1, "w") { |f| }
|
||||
lambda { mkdir_p @dir2 }.should raise_error(ArgumentError)
|
||||
expect { mkdir_p @dir2 }.to raise_error(ArgumentError)
|
||||
end
|
||||
|
||||
it "works if multiple processes try to create the same directory concurrently" do
|
||||
original = File.method(:directory?)
|
||||
File.should_receive(:directory?).at_least(:once) { |dir|
|
||||
expect(File).to receive(:directory?).at_least(:once) { |dir|
|
||||
ret = original.call(dir)
|
||||
if !ret and dir == @dir1
|
||||
Dir.mkdir(dir) # Simulate race
|
||||
|
@ -104,11 +104,11 @@ describe Object, "#mkdir_p" do
|
|||
ret
|
||||
}
|
||||
mkdir_p @dir1
|
||||
original.call(@dir1).should be_true
|
||||
expect(original.call(@dir1)).to be_truthy
|
||||
end
|
||||
end
|
||||
|
||||
describe Object, "#rm_r" do
|
||||
RSpec.describe Object, "#rm_r" do
|
||||
before :all do
|
||||
@topdir = tmp("rm_r_tree")
|
||||
@topfile = @topdir + "/file.txt"
|
||||
|
@ -137,59 +137,59 @@ describe Object, "#rm_r" do
|
|||
end
|
||||
|
||||
it "raises an ArgumentError if the path is not prefixed by MSPEC_RM_PREFIX" do
|
||||
lambda { rm_r "some_file.txt" }.should raise_error(ArgumentError)
|
||||
expect { rm_r "some_file.txt" }.to raise_error(ArgumentError)
|
||||
end
|
||||
|
||||
it "removes a single file" do
|
||||
rm_r @subfile
|
||||
File.exist?(@subfile).should be_false
|
||||
expect(File.exist?(@subfile)).to be_falsey
|
||||
end
|
||||
|
||||
it "removes multiple files" do
|
||||
rm_r @topfile, @subfile
|
||||
File.exist?(@topfile).should be_false
|
||||
File.exist?(@subfile).should be_false
|
||||
expect(File.exist?(@topfile)).to be_falsey
|
||||
expect(File.exist?(@subfile)).to be_falsey
|
||||
end
|
||||
|
||||
platform_is_not :windows do
|
||||
it "removes a symlink to a file" do
|
||||
File.symlink @topfile, @link
|
||||
rm_r @link
|
||||
File.exist?(@link).should be_false
|
||||
expect(File.exist?(@link)).to be_falsey
|
||||
end
|
||||
|
||||
it "removes a symlink to a directory" do
|
||||
File.symlink @subdir1, @link
|
||||
rm_r @link
|
||||
lambda do
|
||||
expect do
|
||||
File.lstat(@link)
|
||||
end.should raise_error(Errno::ENOENT)
|
||||
File.exist?(@subdir1).should be_true
|
||||
end.to raise_error(Errno::ENOENT)
|
||||
expect(File.exist?(@subdir1)).to be_truthy
|
||||
end
|
||||
|
||||
it "removes a dangling symlink" do
|
||||
File.symlink "non_existent_file", @link
|
||||
rm_r @link
|
||||
lambda do
|
||||
expect do
|
||||
File.lstat(@link)
|
||||
end.should raise_error(Errno::ENOENT)
|
||||
end.to raise_error(Errno::ENOENT)
|
||||
end
|
||||
|
||||
it "removes a socket" do
|
||||
require 'socket'
|
||||
UNIXServer.new(@socket).close
|
||||
rm_r @socket
|
||||
File.exist?(@socket).should be_false
|
||||
expect(File.exist?(@socket)).to be_falsey
|
||||
end
|
||||
end
|
||||
|
||||
it "removes a single directory" do
|
||||
rm_r @subdir2
|
||||
File.directory?(@subdir2).should be_false
|
||||
expect(File.directory?(@subdir2)).to be_falsey
|
||||
end
|
||||
|
||||
it "recursively removes a directory tree" do
|
||||
rm_r @topdir
|
||||
File.directory?(@topdir).should be_false
|
||||
expect(File.directory?(@topdir)).to be_falsey
|
||||
end
|
||||
end
|
||||
|
|
|
@ -2,7 +2,7 @@ require 'spec_helper'
|
|||
require 'mspec/guards'
|
||||
require 'mspec/helpers'
|
||||
|
||||
describe IOStub do
|
||||
RSpec.describe IOStub do
|
||||
before :each do
|
||||
@out = IOStub.new
|
||||
@sep = $\
|
||||
|
@ -14,42 +14,42 @@ describe IOStub do
|
|||
|
||||
it "provides a write method" do
|
||||
@out.write "this"
|
||||
@out.should == "this"
|
||||
expect(@out).to eq("this")
|
||||
end
|
||||
|
||||
it "concatenates the arguments sent to write" do
|
||||
@out.write "flim ", "flam"
|
||||
@out.should == "flim flam"
|
||||
expect(@out).to eq("flim flam")
|
||||
end
|
||||
|
||||
it "provides a print method that appends the default separator" do
|
||||
$\ = " [newline] "
|
||||
@out.print "hello"
|
||||
@out.print "world"
|
||||
@out.should == "hello [newline] world [newline] "
|
||||
expect(@out).to eq("hello [newline] world [newline] ")
|
||||
end
|
||||
|
||||
it "provides a puts method that appends the default separator" do
|
||||
@out.puts "hello", 1, 2, 3
|
||||
@out.should == "hello\n1\n2\n3\n"
|
||||
expect(@out).to eq("hello\n1\n2\n3\n")
|
||||
end
|
||||
|
||||
it "provides a puts method that appends separator if argument not given" do
|
||||
@out.puts
|
||||
@out.should == "\n"
|
||||
expect(@out).to eq("\n")
|
||||
end
|
||||
|
||||
it "provides a printf method" do
|
||||
@out.printf "%-10s, %03d, %2.1f", "test", 42, 4.2
|
||||
@out.should == "test , 042, 4.2"
|
||||
expect(@out).to eq("test , 042, 4.2")
|
||||
end
|
||||
|
||||
it "provides a flush method that does nothing and returns self" do
|
||||
@out.flush.should == @out
|
||||
expect(@out.flush).to eq(@out)
|
||||
end
|
||||
end
|
||||
|
||||
describe Object, "#new_fd" do
|
||||
RSpec.describe Object, "#new_fd" do
|
||||
before :each do
|
||||
@name = tmp("io_specs")
|
||||
@io = nil
|
||||
|
@ -62,34 +62,34 @@ describe Object, "#new_fd" do
|
|||
|
||||
it "returns an Integer that can be used to create an IO instance" do
|
||||
fd = new_fd @name
|
||||
fd.should be_kind_of(Integer)
|
||||
expect(fd).to be_kind_of(Integer)
|
||||
|
||||
@io = IO.new fd, 'w:utf-8'
|
||||
@io.sync = true
|
||||
@io.print "io data"
|
||||
|
||||
IO.read(@name).should == "io data"
|
||||
expect(IO.read(@name)).to eq("io data")
|
||||
end
|
||||
|
||||
it "accepts an options Hash" do
|
||||
FeatureGuard.stub(:enabled?).and_return(true)
|
||||
allow(FeatureGuard).to receive(:enabled?).and_return(true)
|
||||
fd = new_fd @name, { :mode => 'w:utf-8' }
|
||||
fd.should be_kind_of(Integer)
|
||||
expect(fd).to be_kind_of(Integer)
|
||||
|
||||
@io = IO.new fd, 'w:utf-8'
|
||||
@io.sync = true
|
||||
@io.print "io data"
|
||||
|
||||
IO.read(@name).should == "io data"
|
||||
expect(IO.read(@name)).to eq("io data")
|
||||
end
|
||||
|
||||
it "raises an ArgumentError if the options Hash does not include :mode" do
|
||||
FeatureGuard.stub(:enabled?).and_return(true)
|
||||
lambda { new_fd @name, { :encoding => "utf-8" } }.should raise_error(ArgumentError)
|
||||
allow(FeatureGuard).to receive(:enabled?).and_return(true)
|
||||
expect { new_fd @name, { :encoding => "utf-8" } }.to raise_error(ArgumentError)
|
||||
end
|
||||
end
|
||||
|
||||
describe Object, "#new_io" do
|
||||
RSpec.describe Object, "#new_io" do
|
||||
before :each do
|
||||
@name = tmp("io_specs.txt")
|
||||
end
|
||||
|
@ -101,14 +101,14 @@ describe Object, "#new_io" do
|
|||
|
||||
it "returns a File instance" do
|
||||
@io = new_io @name
|
||||
@io.should be_an_instance_of(File)
|
||||
expect(@io).to be_an_instance_of(File)
|
||||
end
|
||||
|
||||
it "opens the IO for reading if passed 'r'" do
|
||||
touch(@name) { |f| f.print "io data" }
|
||||
@io = new_io @name, "r"
|
||||
@io.read.should == "io data"
|
||||
lambda { @io.puts "more data" }.should raise_error(IOError)
|
||||
expect(@io.read).to eq("io data")
|
||||
expect { @io.puts "more data" }.to raise_error(IOError)
|
||||
end
|
||||
|
||||
it "opens the IO for writing if passed 'w'" do
|
||||
|
@ -116,14 +116,14 @@ describe Object, "#new_io" do
|
|||
@io.sync = true
|
||||
|
||||
@io.print "io data"
|
||||
IO.read(@name).should == "io data"
|
||||
expect(IO.read(@name)).to eq("io data")
|
||||
end
|
||||
|
||||
it "opens the IO for reading if passed { :mode => 'r' }" do
|
||||
touch(@name) { |f| f.print "io data" }
|
||||
@io = new_io @name, { :mode => "r" }
|
||||
@io.read.should == "io data"
|
||||
lambda { @io.puts "more data" }.should raise_error(IOError)
|
||||
expect(@io.read).to eq("io data")
|
||||
expect { @io.puts "more data" }.to raise_error(IOError)
|
||||
end
|
||||
|
||||
it "opens the IO for writing if passed { :mode => 'w' }" do
|
||||
|
@ -131,6 +131,6 @@ describe Object, "#new_io" do
|
|||
@io.sync = true
|
||||
|
||||
@io.print "io data"
|
||||
IO.read(@name).should == "io data"
|
||||
expect(IO.read(@name)).to eq("io data")
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,17 +1,23 @@
|
|||
require 'spec_helper'
|
||||
require 'mspec/guards'
|
||||
require 'mspec/helpers'
|
||||
require 'mspec/mocks'
|
||||
|
||||
RSpec.describe Object, "#mock_to_path" do
|
||||
before :each do
|
||||
state = double("run state").as_null_object
|
||||
expect(MSpec).to receive(:current).and_return(state)
|
||||
end
|
||||
|
||||
describe Object, "#mock_to_path" do
|
||||
it "returns an object that responds to #to_path" do
|
||||
obj = mock_to_path("foo")
|
||||
obj.should be_a(MockObject)
|
||||
obj.should respond_to(:to_path)
|
||||
expect(obj).to be_a(MockObject)
|
||||
expect(obj).to respond_to(:to_path)
|
||||
obj.to_path
|
||||
end
|
||||
|
||||
it "returns the provided path when #to_path is called" do
|
||||
obj = mock_to_path("/tmp/foo")
|
||||
obj.to_path.should == "/tmp/foo"
|
||||
expect(obj.to_path).to eq("/tmp/foo")
|
||||
end
|
||||
end
|
||||
|
|
|
@ -2,24 +2,24 @@ require 'spec_helper'
|
|||
require 'mspec/guards'
|
||||
require 'mspec/helpers'
|
||||
|
||||
describe Object, "#bignum_value" do
|
||||
RSpec.describe Object, "#bignum_value" do
|
||||
it "returns a value that is an instance of Bignum on any platform" do
|
||||
bignum_value.should == 0x8000_0000_0000_0000
|
||||
expect(bignum_value).to eq(0x8000_0000_0000_0000)
|
||||
end
|
||||
|
||||
it "returns the default value incremented by the argument" do
|
||||
bignum_value(42).should == 0x8000_0000_0000_002a
|
||||
expect(bignum_value(42)).to eq(0x8000_0000_0000_002a)
|
||||
end
|
||||
end
|
||||
|
||||
describe Object, "#nan_value" do
|
||||
RSpec.describe Object, "#nan_value" do
|
||||
it "returns NaN" do
|
||||
nan_value.nan?.should be_true
|
||||
expect(nan_value.nan?).to be_truthy
|
||||
end
|
||||
end
|
||||
|
||||
describe Object, "#infinity_value" do
|
||||
RSpec.describe Object, "#infinity_value" do
|
||||
it "returns Infinity" do
|
||||
infinity_value.infinite?.should == 1
|
||||
expect(infinity_value.infinite?).to eq(1)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -10,7 +10,7 @@ class RubyExeSpecs
|
|||
public :ruby_exe
|
||||
end
|
||||
|
||||
describe "#ruby_exe_options" do
|
||||
RSpec.describe "#ruby_exe_options" do
|
||||
before :each do
|
||||
@ruby_exe_env = ENV['RUBY_EXE']
|
||||
@script = RubyExeSpecs.new
|
||||
|
@ -22,89 +22,89 @@ describe "#ruby_exe_options" do
|
|||
|
||||
it "returns ENV['RUBY_EXE'] when passed :env" do
|
||||
ENV['RUBY_EXE'] = "kowabunga"
|
||||
@script.ruby_exe_options(:env).should == "kowabunga"
|
||||
expect(@script.ruby_exe_options(:env)).to eq("kowabunga")
|
||||
end
|
||||
|
||||
it "returns 'bin/jruby' when passed :engine and RUBY_ENGINE is 'jruby'" do
|
||||
stub_const "RUBY_ENGINE", 'jruby'
|
||||
@script.ruby_exe_options(:engine).should == 'bin/jruby'
|
||||
expect(@script.ruby_exe_options(:engine)).to eq('bin/jruby')
|
||||
end
|
||||
|
||||
it "returns 'bin/rbx' when passed :engine, RUBY_ENGINE is 'rbx'" do
|
||||
stub_const "RUBY_ENGINE", 'rbx'
|
||||
@script.ruby_exe_options(:engine).should == 'bin/rbx'
|
||||
expect(@script.ruby_exe_options(:engine)).to eq('bin/rbx')
|
||||
end
|
||||
|
||||
it "returns 'ir' when passed :engine and RUBY_ENGINE is 'ironruby'" do
|
||||
stub_const "RUBY_ENGINE", 'ironruby'
|
||||
@script.ruby_exe_options(:engine).should == 'ir'
|
||||
expect(@script.ruby_exe_options(:engine)).to eq('ir')
|
||||
end
|
||||
|
||||
it "returns 'maglev-ruby' when passed :engine and RUBY_ENGINE is 'maglev'" do
|
||||
stub_const "RUBY_ENGINE", 'maglev'
|
||||
@script.ruby_exe_options(:engine).should == 'maglev-ruby'
|
||||
expect(@script.ruby_exe_options(:engine)).to eq('maglev-ruby')
|
||||
end
|
||||
|
||||
it "returns 'topaz' when passed :engine and RUBY_ENGINE is 'topaz'" do
|
||||
stub_const "RUBY_ENGINE", 'topaz'
|
||||
@script.ruby_exe_options(:engine).should == 'topaz'
|
||||
expect(@script.ruby_exe_options(:engine)).to eq('topaz')
|
||||
end
|
||||
|
||||
it "returns RUBY_ENGINE + $(EXEEXT) when passed :name" do
|
||||
bin = RUBY_ENGINE + (RbConfig::CONFIG['EXEEXT'] || RbConfig::CONFIG['exeext'] || '')
|
||||
name = File.join ".", bin
|
||||
@script.ruby_exe_options(:name).should == name
|
||||
expect(@script.ruby_exe_options(:name)).to eq(name)
|
||||
end
|
||||
|
||||
it "returns $(bindir)/$(RUBY_INSTALL_NAME) + $(EXEEXT) when passed :install_name" do
|
||||
bin = RbConfig::CONFIG['RUBY_INSTALL_NAME'] + (RbConfig::CONFIG['EXEEXT'] || RbConfig::CONFIG['exeext'] || '')
|
||||
name = File.join RbConfig::CONFIG['bindir'], bin
|
||||
@script.ruby_exe_options(:install_name).should == name
|
||||
expect(@script.ruby_exe_options(:install_name)).to eq(name)
|
||||
end
|
||||
end
|
||||
|
||||
describe "#resolve_ruby_exe" do
|
||||
RSpec.describe "#resolve_ruby_exe" do
|
||||
before :each do
|
||||
@name = "ruby_spec_exe"
|
||||
@script = RubyExeSpecs.new
|
||||
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)
|
||||
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
|
||||
expect(@script).to receive(:ruby_exe_options).and_return(@name)
|
||||
expect(File).to receive(:file?).with(@name).and_return(true)
|
||||
expect(File).to receive(:executable?).with(@name).and_return(true)
|
||||
expect(File).to receive(:expand_path).with(@name).and_return(@name)
|
||||
expect(@script.resolve_ruby_exe).to eq(@name)
|
||||
end
|
||||
|
||||
it "expands the path portion of the result of #ruby_exe_options" do
|
||||
@script.should_receive(:ruby_exe_options).and_return("#{@name}")
|
||||
File.should_receive(:file?).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}"
|
||||
expect(@script).to receive(:ruby_exe_options).and_return("#{@name}")
|
||||
expect(File).to receive(:file?).with(@name).and_return(true)
|
||||
expect(File).to receive(:executable?).with(@name).and_return(true)
|
||||
expect(File).to receive(:expand_path).with(@name).and_return("/usr/bin/#{@name}")
|
||||
expect(@script.resolve_ruby_exe).to eq("/usr/bin/#{@name}")
|
||||
end
|
||||
|
||||
it "adds the flags after the executable" do
|
||||
@name = 'bin/rbx'
|
||||
@script.should_receive(:ruby_exe_options).and_return(@name)
|
||||
File.should_receive(:file?).with(@name).and_return(true)
|
||||
File.should_receive(:executable?).with(@name).and_return(true)
|
||||
File.should_receive(:expand_path).with(@name).and_return(@name)
|
||||
expect(@script).to receive(:ruby_exe_options).and_return(@name)
|
||||
expect(File).to receive(:file?).with(@name).and_return(true)
|
||||
expect(File).to receive(:executable?).with(@name).and_return(true)
|
||||
expect(File).to receive(:expand_path).with(@name).and_return(@name)
|
||||
|
||||
ENV.should_receive(:[]).with("RUBY_FLAGS").and_return('-X19')
|
||||
@script.resolve_ruby_exe.should == 'bin/rbx -X19'
|
||||
expect(ENV).to receive(:[]).with("RUBY_FLAGS").and_return('-X19')
|
||||
expect(@script.resolve_ruby_exe).to eq('bin/rbx -X19')
|
||||
end
|
||||
|
||||
it "raises an exception if no exe is found" do
|
||||
File.should_receive(:file?).at_least(:once).and_return(false)
|
||||
lambda {
|
||||
expect(File).to receive(:file?).at_least(:once).and_return(false)
|
||||
expect {
|
||||
@script.resolve_ruby_exe
|
||||
}.should raise_error(Exception)
|
||||
}.to raise_error(Exception)
|
||||
end
|
||||
end
|
||||
|
||||
describe Object, "#ruby_cmd" do
|
||||
RSpec.describe Object, "#ruby_cmd" do
|
||||
before :each do
|
||||
stub_const 'RUBY_EXE', 'ruby_spec_exe -w -Q'
|
||||
|
||||
|
@ -115,83 +115,86 @@ describe Object, "#ruby_cmd" do
|
|||
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"
|
||||
expect(File).to receive(:exist?).with(@file).and_return(true)
|
||||
expect(@script.ruby_cmd(@file)).to eq("ruby_spec_exe -w -Q some/ruby/file.rb")
|
||||
end
|
||||
|
||||
it "includes the given options and arguments with a file" do
|
||||
File.should_receive(:exist?).with(@file).and_return(true)
|
||||
@script.ruby_cmd(@file, :options => "-w -Cdir", :args => "< file.txt").should ==
|
||||
expect(File).to receive(:exist?).with(@file).and_return(true)
|
||||
expect(@script.ruby_cmd(@file, :options => "-w -Cdir", :args => "< file.txt")).to eq(
|
||||
"ruby_spec_exe -w -Q -w -Cdir some/ruby/file.rb < file.txt"
|
||||
)
|
||||
end
|
||||
|
||||
it "includes the given options and arguments with -e" do
|
||||
File.should_receive(:exist?).with(@code).and_return(false)
|
||||
@script.ruby_cmd(@code, :options => "-W0 -Cdir", :args => "< file.txt").should ==
|
||||
expect(File).to receive(:exist?).with(@code).and_return(false)
|
||||
expect(@script.ruby_cmd(@code, :options => "-W0 -Cdir", :args => "< file.txt")).to eq(
|
||||
%(ruby_spec_exe -w -Q -W0 -Cdir -e "some \\"real\\" 'ruby' code" < file.txt)
|
||||
)
|
||||
end
|
||||
|
||||
it "returns a command with options and arguments but without code or file" do
|
||||
@script.ruby_cmd(nil, :options => "-c", :args => "> file.txt").should ==
|
||||
expect(@script.ruby_cmd(nil, :options => "-c", :args => "> file.txt")).to eq(
|
||||
"ruby_spec_exe -w -Q -c > file.txt"
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
describe Object, "#ruby_exe" do
|
||||
RSpec.describe Object, "#ruby_exe" do
|
||||
before :each do
|
||||
stub_const 'RUBY_EXE', 'ruby_spec_exe -w -Q'
|
||||
|
||||
@script = RubyExeSpecs.new
|
||||
@script.stub(:`)
|
||||
allow(@script).to receive(:`)
|
||||
end
|
||||
|
||||
it "returns an Array containing the interpreter executable and flags when given no arguments" do
|
||||
@script.ruby_exe.should == ['ruby_spec_exe', '-w', '-Q']
|
||||
expect(@script.ruby_exe).to eq(['ruby_spec_exe', '-w', '-Q'])
|
||||
end
|
||||
|
||||
it "executes (using `) the result of calling #ruby_cmd with the given arguments" do
|
||||
code = "code"
|
||||
options = {}
|
||||
@script.should_receive(:ruby_cmd).and_return("ruby_cmd")
|
||||
@script.should_receive(:`).with("ruby_cmd")
|
||||
expect(@script).to receive(:ruby_cmd).and_return("ruby_cmd")
|
||||
expect(@script).to receive(:`).with("ruby_cmd")
|
||||
@script.ruby_exe(code, options)
|
||||
end
|
||||
|
||||
describe "with :dir option" do
|
||||
it "is deprecated" do
|
||||
lambda {
|
||||
expect {
|
||||
@script.ruby_exe nil, :dir => "tmp"
|
||||
}.should raise_error(/no longer supported, use Dir\.chdir/)
|
||||
}.to raise_error(/no longer supported, use Dir\.chdir/)
|
||||
end
|
||||
end
|
||||
|
||||
describe "with :env option" do
|
||||
it "preserves the values of existing ENV keys" do
|
||||
ENV["ABC"] = "123"
|
||||
ENV.stub(:[])
|
||||
ENV.should_receive(:[]).with("ABC")
|
||||
allow(ENV).to receive(:[])
|
||||
expect(ENV).to receive(:[]).with("ABC")
|
||||
@script.ruby_exe nil, :env => { :ABC => "xyz" }
|
||||
end
|
||||
|
||||
it "adds the :env entries to ENV" do
|
||||
ENV.should_receive(:[]=).with("ABC", "xyz")
|
||||
expect(ENV).to receive(:[]=).with("ABC", "xyz")
|
||||
@script.ruby_exe nil, :env => { :ABC => "xyz" }
|
||||
end
|
||||
|
||||
it "deletes the :env entries in ENV when an exception is raised" do
|
||||
ENV.should_receive(:delete).with("XYZ")
|
||||
expect(ENV).to receive(:delete).with("XYZ")
|
||||
@script.ruby_exe nil, :env => { :XYZ => "xyz" }
|
||||
end
|
||||
|
||||
it "resets the values of existing ENV keys when an exception is raised" do
|
||||
ENV["ABC"] = "123"
|
||||
ENV.should_receive(:[]=).with("ABC", "xyz")
|
||||
ENV.should_receive(:[]=).with("ABC", "123")
|
||||
expect(ENV).to receive(:[]=).with("ABC", "xyz")
|
||||
expect(ENV).to receive(:[]=).with("ABC", "123")
|
||||
|
||||
@script.should_receive(:`).and_raise(Exception)
|
||||
lambda do
|
||||
expect(@script).to receive(:`).and_raise(Exception)
|
||||
expect do
|
||||
@script.ruby_exe nil, :env => { :ABC => "xyz" }
|
||||
end.should raise_error(Exception)
|
||||
end.to raise_error(Exception)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -2,23 +2,23 @@ require 'spec_helper'
|
|||
require 'mspec/guards'
|
||||
require 'mspec/helpers'
|
||||
|
||||
describe ScratchPad do
|
||||
RSpec.describe ScratchPad do
|
||||
it "records an object and returns a previously recorded object" do
|
||||
ScratchPad.record :this
|
||||
ScratchPad.recorded.should == :this
|
||||
expect(ScratchPad.recorded).to eq(:this)
|
||||
end
|
||||
|
||||
it "clears the recorded object" do
|
||||
ScratchPad.record :that
|
||||
ScratchPad.recorded.should == :that
|
||||
expect(ScratchPad.recorded).to eq(:that)
|
||||
ScratchPad.clear
|
||||
ScratchPad.recorded.should == nil
|
||||
expect(ScratchPad.recorded).to eq(nil)
|
||||
end
|
||||
|
||||
it "provides a convenience shortcut to append to a previously recorded object" do
|
||||
ScratchPad.record []
|
||||
ScratchPad << :new
|
||||
ScratchPad << :another
|
||||
ScratchPad.recorded.should == [:new, :another]
|
||||
expect(ScratchPad.recorded).to eq([:new, :another])
|
||||
end
|
||||
end
|
||||
|
|
|
@ -2,7 +2,7 @@ require 'spec_helper'
|
|||
require 'mspec/guards'
|
||||
require 'mspec/helpers'
|
||||
|
||||
describe Object, "#suppress_warning" do
|
||||
RSpec.describe Object, "#suppress_warning" do
|
||||
it "hides warnings" do
|
||||
suppress_warning do
|
||||
warn "should not be shown"
|
||||
|
@ -14,6 +14,6 @@ describe Object, "#suppress_warning" do
|
|||
suppress_warning do
|
||||
a = 1
|
||||
end
|
||||
a.should == 1
|
||||
expect(a).to eq(1)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -2,26 +2,26 @@ require 'spec_helper'
|
|||
require 'mspec/guards'
|
||||
require 'mspec/helpers'
|
||||
|
||||
describe Object, "#tmp" do
|
||||
RSpec.describe Object, "#tmp" do
|
||||
before :all do
|
||||
@dir = SPEC_TEMP_DIR
|
||||
end
|
||||
|
||||
it "returns a name relative to the current working directory" do
|
||||
tmp("test.txt").should == "#{@dir}/#{SPEC_TEMP_UNIQUIFIER}-test.txt"
|
||||
expect(tmp("test.txt")).to eq("#{@dir}/#{SPEC_TEMP_UNIQUIFIER}-test.txt")
|
||||
end
|
||||
|
||||
it "returns a 'unique' name on repeated calls" do
|
||||
a = tmp("text.txt")
|
||||
b = tmp("text.txt")
|
||||
a.should_not == b
|
||||
expect(a).not_to eq(b)
|
||||
end
|
||||
|
||||
it "does not 'uniquify' the name if requested not to" do
|
||||
tmp("test.txt", false).should == "#{@dir}/test.txt"
|
||||
expect(tmp("test.txt", false)).to eq("#{@dir}/test.txt")
|
||||
end
|
||||
|
||||
it "returns the name of the temporary directory when passed an empty string" do
|
||||
tmp("").should == "#{@dir}/"
|
||||
expect(tmp("")).to eq("#{@dir}/")
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe "The interpreter passed with -t" do
|
||||
RSpec.describe "The interpreter passed with -t" do
|
||||
it "is used in subprocess" do
|
||||
fixtures = "spec/fixtures"
|
||||
interpreter = "#{fixtures}/my_ruby"
|
||||
|
@ -8,11 +8,11 @@ describe "The interpreter passed with -t" do
|
|||
out = out.lines.map(&:chomp).reject { |line|
|
||||
line == 'RUBY_DESCRIPTION'
|
||||
}.take(3)
|
||||
out.should == [
|
||||
expect(out).to eq([
|
||||
interpreter,
|
||||
interpreter,
|
||||
"CWD/#{interpreter}"
|
||||
]
|
||||
ret.success?.should == true
|
||||
])
|
||||
expect(ret.success?).to eq(true)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -9,10 +9,10 @@ Finished in D.DDDDDD seconds
|
|||
1 file, 1 example, 1 expectation, 0 failures, 0 errors, 0 tagged
|
||||
EOS
|
||||
|
||||
describe "MSpec" do
|
||||
RSpec.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
|
||||
expect(out).to eq(expected_output)
|
||||
expect(ret.success?).to eq(true)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe "Running mspec" do
|
||||
RSpec.describe "Running mspec" do
|
||||
a_spec_output = <<EOS
|
||||
|
||||
1)
|
||||
|
@ -25,20 +25,20 @@ EOS
|
|||
|
||||
it "runs the specs" do
|
||||
out, ret = run_mspec("run", "#{fixtures}/a_spec.rb")
|
||||
out.should == "RUBY_DESCRIPTION\n.FE\n#{a_spec_output}\n#{a_stats}"
|
||||
ret.success?.should == false
|
||||
expect(out).to eq("RUBY_DESCRIPTION\n.FE\n#{a_spec_output}\n#{a_stats}")
|
||||
expect(ret.success?).to eq(false)
|
||||
end
|
||||
|
||||
it "directly with mspec-run runs the specs" do
|
||||
out, ret = run_mspec("-run", "#{fixtures}/a_spec.rb")
|
||||
out.should == "RUBY_DESCRIPTION\n.FE\n#{a_spec_output}\n#{a_stats}"
|
||||
ret.success?.should == false
|
||||
expect(out).to eq("RUBY_DESCRIPTION\n.FE\n#{a_spec_output}\n#{a_stats}")
|
||||
expect(ret.success?).to eq(false)
|
||||
end
|
||||
|
||||
it "runs the specs in parallel with -j using the dotted formatter" do
|
||||
out, ret = run_mspec("run", "-j #{fixtures}/a_spec.rb #{fixtures}/b_spec.rb")
|
||||
out.should == "RUBY_DESCRIPTION\n...\n#{a_spec_output}\n#{ab_stats}"
|
||||
ret.success?.should == false
|
||||
expect(out).to eq("RUBY_DESCRIPTION\n...\n#{a_spec_output}\n#{ab_stats}")
|
||||
expect(ret.success?).to eq(false)
|
||||
end
|
||||
|
||||
it "runs the specs in parallel with -j -fa" do
|
||||
|
@ -47,25 +47,25 @@ EOS
|
|||
"\r[/ | 0% | 00:00:00] \e[0;32m 0F \e[0;32m 0E\e[0m " +
|
||||
"\r[- | ==================50% | 00:00:00] \e[0;32m 0F \e[0;32m 0E\e[0m " +
|
||||
"\r[\\ | ==================100%================== | 00:00:00] \e[0;32m 0F \e[0;32m 0E\e[0m "
|
||||
out.should == "RUBY_DESCRIPTION\n#{progress_bar}\n#{a_spec_output}\n#{ab_stats}"
|
||||
ret.success?.should == false
|
||||
expect(out).to eq("RUBY_DESCRIPTION\n#{progress_bar}\n#{a_spec_output}\n#{ab_stats}")
|
||||
expect(ret.success?).to eq(false)
|
||||
end
|
||||
|
||||
it "gives a useful error message when a subprocess dies in parallel mode" do
|
||||
out, ret = run_mspec("run", "-j #{fixtures}/b_spec.rb #{fixtures}/die_spec.rb")
|
||||
lines = out.lines
|
||||
lines.should include "A child mspec-run process died unexpectedly while running CWD/spec/fixtures/die_spec.rb\n"
|
||||
lines.should include "Finished in D.DDDDDD seconds\n"
|
||||
lines.last.should =~ /^\d files?, \d examples?, \d expectations?, 0 failures, 0 errors, 0 tagged$/
|
||||
ret.success?.should == false
|
||||
expect(lines).to include "A child mspec-run process died unexpectedly while running CWD/spec/fixtures/die_spec.rb\n"
|
||||
expect(lines).to include "Finished in D.DDDDDD seconds\n"
|
||||
expect(lines.last).to match(/^\d files?, \d examples?, \d expectations?, 0 failures, 0 errors, 0 tagged$/)
|
||||
expect(ret.success?).to eq(false)
|
||||
end
|
||||
|
||||
it "gives a useful error message when a subprocess prints unexpected output on STDOUT in parallel mode" do
|
||||
out, ret = run_mspec("run", "-j #{fixtures}/b_spec.rb #{fixtures}/chatty_spec.rb")
|
||||
lines = out.lines
|
||||
lines.should include "A child mspec-run process printed unexpected output on STDOUT: #{'"Hello\nIt\'s me!\n"'} while running CWD/spec/fixtures/chatty_spec.rb\n"
|
||||
lines.should include "Finished in D.DDDDDD seconds\n"
|
||||
lines.last.should == "2 files, 2 examples, 2 expectations, 0 failures, 0 errors, 0 tagged\n"
|
||||
ret.success?.should == false
|
||||
expect(lines).to include "A child mspec-run process printed unexpected output on STDOUT: #{'"Hello\nIt\'s me!\n"'} while running CWD/spec/fixtures/chatty_spec.rb\n"
|
||||
expect(lines).to include "Finished in D.DDDDDD seconds\n"
|
||||
expect(lines.last).to eq("2 files, 2 examples, 2 expectations, 0 failures, 0 errors, 0 tagged\n")
|
||||
expect(ret.success?).to eq(false)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
# encoding: utf-8
|
||||
require 'spec_helper'
|
||||
|
||||
describe "Running mspec tag" do
|
||||
RSpec.describe "Running mspec tag" do
|
||||
before :all do
|
||||
FileUtils.rm_rf 'spec/fixtures/tags'
|
||||
end
|
||||
|
@ -13,7 +13,7 @@ describe "Running mspec tag" do
|
|||
it "tags the failing specs" do
|
||||
fixtures = "spec/fixtures"
|
||||
out, ret = run_mspec("tag", "--add fails --fail #{fixtures}/tagging_spec.rb")
|
||||
out.should == <<EOS
|
||||
expect(out).to eq <<EOS
|
||||
RUBY_DESCRIPTION
|
||||
.FF
|
||||
TagAction: specs tagged with 'fails':
|
||||
|
@ -40,13 +40,13 @@ Finished in D.DDDDDD seconds
|
|||
|
||||
1 file, 3 examples, 3 expectations, 2 failures, 0 errors, 0 tagged
|
||||
EOS
|
||||
ret.success?.should == false
|
||||
expect(ret.success?).to eq(false)
|
||||
end
|
||||
|
||||
it "does not run already tagged specs" do
|
||||
fixtures = "spec/fixtures"
|
||||
out, ret = run_mspec("run", "--excl-tag fails #{fixtures}/tagging_spec.rb")
|
||||
out.should == <<EOS
|
||||
expect(out).to eq <<EOS
|
||||
RUBY_DESCRIPTION
|
||||
.
|
||||
|
||||
|
@ -54,6 +54,6 @@ Finished in D.DDDDDD seconds
|
|||
|
||||
1 file, 3 examples, 1 expectation, 0 failures, 0 errors, 2 tagged
|
||||
EOS
|
||||
ret.success?.should == true
|
||||
expect(ret.success?).to eq(true)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -3,11 +3,11 @@ require 'mspec/expectations/expectations'
|
|||
require 'mspec/matchers'
|
||||
require 'time'
|
||||
|
||||
describe SpecPositiveOperatorMatcher, "== operator" do
|
||||
RSpec.describe SpecPositiveOperatorMatcher, "== operator" do
|
||||
it "provides a failure message that 'Expected x to equal y'" do
|
||||
lambda {
|
||||
expect {
|
||||
SpecPositiveOperatorMatcher.new(1) == 2
|
||||
}.should raise_error(SpecExpectationNotMetError, "Expected 1 == 2\nto be truthy but was false")
|
||||
}.to raise_error(SpecExpectationNotMetError, "Expected 1 == 2\nto be truthy but was false")
|
||||
end
|
||||
|
||||
it "does not raise an exception when == returns true" do
|
||||
|
@ -15,11 +15,11 @@ describe SpecPositiveOperatorMatcher, "== operator" do
|
|||
end
|
||||
end
|
||||
|
||||
describe SpecPositiveOperatorMatcher, "=~ operator" do
|
||||
RSpec.describe SpecPositiveOperatorMatcher, "=~ operator" do
|
||||
it "provides a failure message that 'Expected \"x\" to match y'" do
|
||||
lambda {
|
||||
expect {
|
||||
SpecPositiveOperatorMatcher.new('real') =~ /fake/
|
||||
}.should raise_error(SpecExpectationNotMetError, "Expected \"real\" =~ /fake/\nto be truthy but was nil")
|
||||
}.to raise_error(SpecExpectationNotMetError, "Expected \"real\" =~ /fake/\nto be truthy but was nil")
|
||||
end
|
||||
|
||||
it "does not raise an exception when =~ returns true" do
|
||||
|
@ -27,11 +27,11 @@ describe SpecPositiveOperatorMatcher, "=~ operator" do
|
|||
end
|
||||
end
|
||||
|
||||
describe SpecPositiveOperatorMatcher, "> operator" do
|
||||
RSpec.describe SpecPositiveOperatorMatcher, "> operator" do
|
||||
it "provides a failure message that 'Expected x to be greater than y'" do
|
||||
lambda {
|
||||
expect {
|
||||
SpecPositiveOperatorMatcher.new(4) > 5
|
||||
}.should raise_error(SpecExpectationNotMetError, "Expected 4 > 5\nto be truthy but was false")
|
||||
}.to raise_error(SpecExpectationNotMetError, "Expected 4 > 5\nto be truthy but was false")
|
||||
end
|
||||
|
||||
it "does not raise an exception when > returns true" do
|
||||
|
@ -39,11 +39,11 @@ describe SpecPositiveOperatorMatcher, "> operator" do
|
|||
end
|
||||
end
|
||||
|
||||
describe SpecPositiveOperatorMatcher, ">= operator" do
|
||||
RSpec.describe SpecPositiveOperatorMatcher, ">= operator" do
|
||||
it "provides a failure message that 'Expected x to be greater than or equal to y'" do
|
||||
lambda {
|
||||
expect {
|
||||
SpecPositiveOperatorMatcher.new(4) >= 5
|
||||
}.should raise_error(SpecExpectationNotMetError, "Expected 4 >= 5\nto be truthy but was false")
|
||||
}.to raise_error(SpecExpectationNotMetError, "Expected 4 >= 5\nto be truthy but was false")
|
||||
end
|
||||
|
||||
it "does not raise an exception when > returns true" do
|
||||
|
@ -52,11 +52,11 @@ describe SpecPositiveOperatorMatcher, ">= operator" do
|
|||
end
|
||||
end
|
||||
|
||||
describe SpecPositiveOperatorMatcher, "< operator" do
|
||||
RSpec.describe SpecPositiveOperatorMatcher, "< operator" do
|
||||
it "provides a failure message that 'Expected x to be less than y'" do
|
||||
lambda {
|
||||
expect {
|
||||
SpecPositiveOperatorMatcher.new(5) < 4
|
||||
}.should raise_error(SpecExpectationNotMetError, "Expected 5 < 4\nto be truthy but was false")
|
||||
}.to raise_error(SpecExpectationNotMetError, "Expected 5 < 4\nto be truthy but was false")
|
||||
end
|
||||
|
||||
it "does not raise an exception when < returns true" do
|
||||
|
@ -64,11 +64,11 @@ describe SpecPositiveOperatorMatcher, "< operator" do
|
|||
end
|
||||
end
|
||||
|
||||
describe SpecPositiveOperatorMatcher, "<= operator" do
|
||||
RSpec.describe SpecPositiveOperatorMatcher, "<= operator" do
|
||||
it "provides a failure message that 'Expected x to be less than or equal to y'" do
|
||||
lambda {
|
||||
expect {
|
||||
SpecPositiveOperatorMatcher.new(5) <= 4
|
||||
}.should raise_error(SpecExpectationNotMetError, "Expected 5 <= 4\nto be truthy but was false")
|
||||
}.to raise_error(SpecExpectationNotMetError, "Expected 5 <= 4\nto be truthy but was false")
|
||||
end
|
||||
|
||||
it "does not raise an exception when < returns true" do
|
||||
|
@ -77,7 +77,7 @@ describe SpecPositiveOperatorMatcher, "<= operator" do
|
|||
end
|
||||
end
|
||||
|
||||
describe SpecPositiveOperatorMatcher, "arbitrary predicates" do
|
||||
RSpec.describe SpecPositiveOperatorMatcher, "arbitrary predicates" do
|
||||
it "do not raise an exception when the predicate is truthy" do
|
||||
SpecPositiveOperatorMatcher.new(2).eql?(2)
|
||||
SpecPositiveOperatorMatcher.new(2).equal?(2)
|
||||
|
@ -89,31 +89,31 @@ describe SpecPositiveOperatorMatcher, "arbitrary predicates" do
|
|||
end
|
||||
|
||||
it "provide a failure message when the predicate returns a falsy value" do
|
||||
lambda {
|
||||
expect {
|
||||
SpecPositiveOperatorMatcher.new(2).eql?(3)
|
||||
}.should raise_error(SpecExpectationNotMetError, "Expected 2.eql? 3\nto be truthy but was false")
|
||||
lambda {
|
||||
}.to raise_error(SpecExpectationNotMetError, "Expected 2.eql? 3\nto be truthy but was false")
|
||||
expect {
|
||||
SpecPositiveOperatorMatcher.new(2).equal?(3)
|
||||
}.should raise_error(SpecExpectationNotMetError, "Expected 2.equal? 3\nto be truthy but was false")
|
||||
lambda {
|
||||
}.to raise_error(SpecExpectationNotMetError, "Expected 2.equal? 3\nto be truthy but was false")
|
||||
expect {
|
||||
SpecPositiveOperatorMatcher.new([1, 2, 3]).include?(4)
|
||||
}.should raise_error(SpecExpectationNotMetError, "Expected [1, 2, 3].include? 4\nto be truthy but was false")
|
||||
lambda {
|
||||
}.to raise_error(SpecExpectationNotMetError, "Expected [1, 2, 3].include? 4\nto be truthy but was false")
|
||||
expect {
|
||||
SpecPositiveOperatorMatcher.new("abc").start_with?("de")
|
||||
}.should raise_error(SpecExpectationNotMetError, "Expected \"abc\".start_with? \"de\"\nto be truthy but was false")
|
||||
lambda {
|
||||
}.to raise_error(SpecExpectationNotMetError, "Expected \"abc\".start_with? \"de\"\nto be truthy but was false")
|
||||
expect {
|
||||
SpecPositiveOperatorMatcher.new("abc").start_with?("d", "e")
|
||||
}.should raise_error(SpecExpectationNotMetError, "Expected \"abc\".start_with? \"d\", \"e\"\nto be truthy but was false")
|
||||
lambda {
|
||||
}.to raise_error(SpecExpectationNotMetError, "Expected \"abc\".start_with? \"d\", \"e\"\nto be truthy but was false")
|
||||
expect {
|
||||
SpecPositiveOperatorMatcher.new(2).odd?
|
||||
}.should raise_error(SpecExpectationNotMetError, "Expected 2.odd?\nto be truthy but was false")
|
||||
lambda {
|
||||
}.to raise_error(SpecExpectationNotMetError, "Expected 2.odd?\nto be truthy but was false")
|
||||
expect {
|
||||
SpecPositiveOperatorMatcher.new([1, 3]).any? { |e| e.even? }
|
||||
}.should raise_error(SpecExpectationNotMetError, "Expected [1, 3].any? { ... }\nto be truthy but was false")
|
||||
}.to raise_error(SpecExpectationNotMetError, "Expected [1, 3].any? { ... }\nto be truthy but was false")
|
||||
end
|
||||
end
|
||||
|
||||
describe SpecNegativeOperatorMatcher, "arbitrary predicates" do
|
||||
RSpec.describe SpecNegativeOperatorMatcher, "arbitrary predicates" do
|
||||
it "do not raise an exception when the predicate returns a falsy value" do
|
||||
SpecNegativeOperatorMatcher.new(2).eql?(3)
|
||||
SpecNegativeOperatorMatcher.new(2).equal?(3)
|
||||
|
@ -125,35 +125,35 @@ describe SpecNegativeOperatorMatcher, "arbitrary predicates" do
|
|||
end
|
||||
|
||||
it "provide a failure message when the predicate returns a truthy value" do
|
||||
lambda {
|
||||
expect {
|
||||
SpecNegativeOperatorMatcher.new(2).eql?(2)
|
||||
}.should raise_error(SpecExpectationNotMetError, "Expected 2.eql? 2\nto be falsy but was true")
|
||||
lambda {
|
||||
}.to raise_error(SpecExpectationNotMetError, "Expected 2.eql? 2\nto be falsy but was true")
|
||||
expect {
|
||||
SpecNegativeOperatorMatcher.new(2).equal?(2)
|
||||
}.should raise_error(SpecExpectationNotMetError, "Expected 2.equal? 2\nto be falsy but was true")
|
||||
lambda {
|
||||
}.to raise_error(SpecExpectationNotMetError, "Expected 2.equal? 2\nto be falsy but was true")
|
||||
expect {
|
||||
SpecNegativeOperatorMatcher.new([1, 2, 3]).include?(2)
|
||||
}.should raise_error(SpecExpectationNotMetError, "Expected [1, 2, 3].include? 2\nto be falsy but was true")
|
||||
lambda {
|
||||
}.to raise_error(SpecExpectationNotMetError, "Expected [1, 2, 3].include? 2\nto be falsy but was true")
|
||||
expect {
|
||||
SpecNegativeOperatorMatcher.new("abc").start_with?("ab")
|
||||
}.should raise_error(SpecExpectationNotMetError, "Expected \"abc\".start_with? \"ab\"\nto be falsy but was true")
|
||||
lambda {
|
||||
}.to raise_error(SpecExpectationNotMetError, "Expected \"abc\".start_with? \"ab\"\nto be falsy but was true")
|
||||
expect {
|
||||
SpecNegativeOperatorMatcher.new("abc").start_with?("d", "a")
|
||||
}.should raise_error(SpecExpectationNotMetError, "Expected \"abc\".start_with? \"d\", \"a\"\nto be falsy but was true")
|
||||
lambda {
|
||||
}.to raise_error(SpecExpectationNotMetError, "Expected \"abc\".start_with? \"d\", \"a\"\nto be falsy but was true")
|
||||
expect {
|
||||
SpecNegativeOperatorMatcher.new(3).odd?
|
||||
}.should raise_error(SpecExpectationNotMetError, "Expected 3.odd?\nto be falsy but was true")
|
||||
lambda {
|
||||
}.to raise_error(SpecExpectationNotMetError, "Expected 3.odd?\nto be falsy but was true")
|
||||
expect {
|
||||
SpecNegativeOperatorMatcher.new([1, 2]).any? { |e| e.even? }
|
||||
}.should raise_error(SpecExpectationNotMetError, "Expected [1, 2].any? { ... }\nto be falsy but was true")
|
||||
}.to raise_error(SpecExpectationNotMetError, "Expected [1, 2].any? { ... }\nto be falsy but was true")
|
||||
end
|
||||
end
|
||||
|
||||
describe SpecNegativeOperatorMatcher, "== operator" do
|
||||
RSpec.describe SpecNegativeOperatorMatcher, "== operator" do
|
||||
it "provides a failure message that 'Expected x not to equal y'" do
|
||||
lambda {
|
||||
expect {
|
||||
SpecNegativeOperatorMatcher.new(1) == 1
|
||||
}.should raise_error(SpecExpectationNotMetError, "Expected 1 == 1\nto be falsy but was true")
|
||||
}.to raise_error(SpecExpectationNotMetError, "Expected 1 == 1\nto be falsy but was true")
|
||||
end
|
||||
|
||||
it "does not raise an exception when == returns false" do
|
||||
|
@ -161,11 +161,11 @@ describe SpecNegativeOperatorMatcher, "== operator" do
|
|||
end
|
||||
end
|
||||
|
||||
describe SpecNegativeOperatorMatcher, "=~ operator" do
|
||||
RSpec.describe SpecNegativeOperatorMatcher, "=~ operator" do
|
||||
it "provides a failure message that 'Expected \"x\" not to match /y/'" do
|
||||
lambda {
|
||||
expect {
|
||||
SpecNegativeOperatorMatcher.new('real') =~ /real/
|
||||
}.should raise_error(SpecExpectationNotMetError, "Expected \"real\" =~ /real/\nto be falsy but was 0")
|
||||
}.to raise_error(SpecExpectationNotMetError, "Expected \"real\" =~ /real/\nto be falsy but was 0")
|
||||
end
|
||||
|
||||
it "does not raise an exception when =~ returns false" do
|
||||
|
@ -173,11 +173,11 @@ describe SpecNegativeOperatorMatcher, "=~ operator" do
|
|||
end
|
||||
end
|
||||
|
||||
describe SpecNegativeOperatorMatcher, "< operator" do
|
||||
RSpec.describe SpecNegativeOperatorMatcher, "< operator" do
|
||||
it "provides a failure message that 'Expected x not to be less than y'" do
|
||||
lambda {
|
||||
expect {
|
||||
SpecNegativeOperatorMatcher.new(4) < 5
|
||||
}.should raise_error(SpecExpectationNotMetError, "Expected 4 < 5\nto be falsy but was true")
|
||||
}.to raise_error(SpecExpectationNotMetError, "Expected 4 < 5\nto be falsy but was true")
|
||||
end
|
||||
|
||||
it "does not raise an exception when < returns false" do
|
||||
|
@ -185,14 +185,14 @@ describe SpecNegativeOperatorMatcher, "< operator" do
|
|||
end
|
||||
end
|
||||
|
||||
describe SpecNegativeOperatorMatcher, "<= operator" do
|
||||
RSpec.describe SpecNegativeOperatorMatcher, "<= operator" do
|
||||
it "provides a failure message that 'Expected x not to be less than or equal to y'" do
|
||||
lambda {
|
||||
expect {
|
||||
SpecNegativeOperatorMatcher.new(4) <= 5
|
||||
}.should raise_error(SpecExpectationNotMetError, "Expected 4 <= 5\nto be falsy but was true")
|
||||
lambda {
|
||||
}.to raise_error(SpecExpectationNotMetError, "Expected 4 <= 5\nto be falsy but was true")
|
||||
expect {
|
||||
SpecNegativeOperatorMatcher.new(5) <= 5
|
||||
}.should raise_error(SpecExpectationNotMetError, "Expected 5 <= 5\nto be falsy but was true")
|
||||
}.to raise_error(SpecExpectationNotMetError, "Expected 5 <= 5\nto be falsy but was true")
|
||||
end
|
||||
|
||||
it "does not raise an exception when <= returns false" do
|
||||
|
@ -200,11 +200,11 @@ describe SpecNegativeOperatorMatcher, "<= operator" do
|
|||
end
|
||||
end
|
||||
|
||||
describe SpecNegativeOperatorMatcher, "> operator" do
|
||||
RSpec.describe SpecNegativeOperatorMatcher, "> operator" do
|
||||
it "provides a failure message that 'Expected x not to be greater than y'" do
|
||||
lambda {
|
||||
expect {
|
||||
SpecNegativeOperatorMatcher.new(5) > 4
|
||||
}.should raise_error(SpecExpectationNotMetError, "Expected 5 > 4\nto be falsy but was true")
|
||||
}.to raise_error(SpecExpectationNotMetError, "Expected 5 > 4\nto be falsy but was true")
|
||||
end
|
||||
|
||||
it "does not raise an exception when > returns false" do
|
||||
|
@ -212,14 +212,14 @@ describe SpecNegativeOperatorMatcher, "> operator" do
|
|||
end
|
||||
end
|
||||
|
||||
describe SpecNegativeOperatorMatcher, ">= operator" do
|
||||
RSpec.describe SpecNegativeOperatorMatcher, ">= operator" do
|
||||
it "provides a failure message that 'Expected x not to be greater than or equal to y'" do
|
||||
lambda {
|
||||
expect {
|
||||
SpecNegativeOperatorMatcher.new(5) >= 4
|
||||
}.should raise_error(SpecExpectationNotMetError, "Expected 5 >= 4\nto be falsy but was true")
|
||||
lambda {
|
||||
}.to raise_error(SpecExpectationNotMetError, "Expected 5 >= 4\nto be falsy but was true")
|
||||
expect {
|
||||
SpecNegativeOperatorMatcher.new(5) >= 5
|
||||
}.should raise_error(SpecExpectationNotMetError, "Expected 5 >= 5\nto be falsy but was true")
|
||||
}.to raise_error(SpecExpectationNotMetError, "Expected 5 >= 5\nto be falsy but was true")
|
||||
end
|
||||
|
||||
it "does not raise an exception when >= returns false" do
|
||||
|
|
|
@ -13,38 +13,38 @@ module BeAnInOfSpecs
|
|||
end
|
||||
end
|
||||
|
||||
describe BeAnInstanceOfMatcher do
|
||||
RSpec.describe BeAnInstanceOfMatcher do
|
||||
it "matches when actual is an instance_of? expected" do
|
||||
a = BeAnInOfSpecs::A.new
|
||||
BeAnInstanceOfMatcher.new(BeAnInOfSpecs::A).matches?(a).should be_true
|
||||
expect(BeAnInstanceOfMatcher.new(BeAnInOfSpecs::A).matches?(a)).to be_truthy
|
||||
|
||||
b = BeAnInOfSpecs::B.new
|
||||
BeAnInstanceOfMatcher.new(BeAnInOfSpecs::B).matches?(b).should be_true
|
||||
expect(BeAnInstanceOfMatcher.new(BeAnInOfSpecs::B).matches?(b)).to be_truthy
|
||||
end
|
||||
|
||||
it "does not match when actual is not an instance_of? expected" do
|
||||
a = BeAnInOfSpecs::A.new
|
||||
BeAnInstanceOfMatcher.new(BeAnInOfSpecs::B).matches?(a).should be_false
|
||||
expect(BeAnInstanceOfMatcher.new(BeAnInOfSpecs::B).matches?(a)).to be_falsey
|
||||
|
||||
b = BeAnInOfSpecs::B.new
|
||||
BeAnInstanceOfMatcher.new(BeAnInOfSpecs::A).matches?(b).should be_false
|
||||
expect(BeAnInstanceOfMatcher.new(BeAnInOfSpecs::A).matches?(b)).to be_falsey
|
||||
|
||||
c = BeAnInOfSpecs::C.new
|
||||
BeAnInstanceOfMatcher.new(BeAnInOfSpecs::A).matches?(c).should be_false
|
||||
BeAnInstanceOfMatcher.new(BeAnInOfSpecs::B).matches?(c).should be_false
|
||||
expect(BeAnInstanceOfMatcher.new(BeAnInOfSpecs::A).matches?(c)).to be_falsey
|
||||
expect(BeAnInstanceOfMatcher.new(BeAnInOfSpecs::B).matches?(c)).to be_falsey
|
||||
end
|
||||
|
||||
it "provides a useful failure message" do
|
||||
matcher = BeAnInstanceOfMatcher.new(Numeric)
|
||||
matcher.matches?("string")
|
||||
matcher.failure_message.should == [
|
||||
"Expected \"string\" (String)", "to be an instance of Numeric"]
|
||||
expect(matcher.failure_message).to eq([
|
||||
"Expected \"string\" (String)", "to be an instance of Numeric"])
|
||||
end
|
||||
|
||||
it "provides a useful negative failure message" do
|
||||
matcher = BeAnInstanceOfMatcher.new(Numeric)
|
||||
matcher.matches?(4.0)
|
||||
matcher.negative_failure_message.should == [
|
||||
"Expected 4.0 (Float)", "not to be an instance of Numeric"]
|
||||
expect(matcher.negative_failure_message).to eq([
|
||||
"Expected 4.0 (Float)", "not to be an instance of Numeric"])
|
||||
end
|
||||
end
|
||||
|
|
|
@ -5,24 +5,24 @@ require 'mspec/matchers'
|
|||
class Parent; end
|
||||
class Child < Parent; end
|
||||
|
||||
describe BeAncestorOfMatcher do
|
||||
RSpec.describe BeAncestorOfMatcher do
|
||||
it "matches when actual is an ancestor of expected" do
|
||||
BeAncestorOfMatcher.new(Child).matches?(Parent).should == true
|
||||
expect(BeAncestorOfMatcher.new(Child).matches?(Parent)).to eq(true)
|
||||
end
|
||||
|
||||
it "does not match when actual is not an ancestor of expected" do
|
||||
BeAncestorOfMatcher.new(Parent).matches?(Child).should == false
|
||||
expect(BeAncestorOfMatcher.new(Parent).matches?(Child)).to eq(false)
|
||||
end
|
||||
|
||||
it "provides a useful failure message" do
|
||||
matcher = BeAncestorOfMatcher.new(Parent)
|
||||
matcher.matches?(Child)
|
||||
matcher.failure_message.should == ["Expected Child", "to be an ancestor of Parent"]
|
||||
expect(matcher.failure_message).to eq(["Expected Child", "to be an ancestor of Parent"])
|
||||
end
|
||||
|
||||
it "provides a useful negative failure message" do
|
||||
matcher = BeAncestorOfMatcher.new(Child)
|
||||
matcher.matches?(Parent)
|
||||
matcher.negative_failure_message.should == ["Expected Parent", "not to be an ancestor of Child"]
|
||||
expect(matcher.negative_failure_message).to eq(["Expected Parent", "not to be an ancestor of Child"])
|
||||
end
|
||||
end
|
||||
|
|
|
@ -3,46 +3,46 @@ require 'mspec/expectations/expectations'
|
|||
require 'mspec/matchers'
|
||||
|
||||
# Adapted from RSpec 1.0.8
|
||||
describe BeCloseMatcher do
|
||||
RSpec.describe BeCloseMatcher do
|
||||
it "matches when actual == expected" do
|
||||
BeCloseMatcher.new(5.0, 0.5).matches?(5.0).should == true
|
||||
expect(BeCloseMatcher.new(5.0, 0.5).matches?(5.0)).to eq(true)
|
||||
end
|
||||
|
||||
it "matches when actual < (expected + tolerance)" do
|
||||
BeCloseMatcher.new(5.0, 0.5).matches?(5.49).should == true
|
||||
expect(BeCloseMatcher.new(5.0, 0.5).matches?(5.49)).to eq(true)
|
||||
end
|
||||
|
||||
it "matches when actual > (expected - tolerance)" do
|
||||
BeCloseMatcher.new(5.0, 0.5).matches?(4.51).should == true
|
||||
expect(BeCloseMatcher.new(5.0, 0.5).matches?(4.51)).to eq(true)
|
||||
end
|
||||
|
||||
it "matches when actual == (expected + tolerance)" do
|
||||
BeCloseMatcher.new(5.0, 0.5).matches?(5.5).should == true
|
||||
BeCloseMatcher.new(3, 2).matches?(5).should == true
|
||||
expect(BeCloseMatcher.new(5.0, 0.5).matches?(5.5)).to eq(true)
|
||||
expect(BeCloseMatcher.new(3, 2).matches?(5)).to eq(true)
|
||||
end
|
||||
|
||||
it "matches when actual == (expected - tolerance)" do
|
||||
BeCloseMatcher.new(5.0, 0.5).matches?(4.5).should == true
|
||||
BeCloseMatcher.new(3, 2).matches?(1).should == true
|
||||
expect(BeCloseMatcher.new(5.0, 0.5).matches?(4.5)).to eq(true)
|
||||
expect(BeCloseMatcher.new(3, 2).matches?(1)).to eq(true)
|
||||
end
|
||||
|
||||
it "does not match when actual < (expected - tolerance)" do
|
||||
BeCloseMatcher.new(5.0, 0.5).matches?(4.49).should == false
|
||||
expect(BeCloseMatcher.new(5.0, 0.5).matches?(4.49)).to eq(false)
|
||||
end
|
||||
|
||||
it "does not match when actual > (expected + tolerance)" do
|
||||
BeCloseMatcher.new(5.0, 0.5).matches?(5.51).should == false
|
||||
expect(BeCloseMatcher.new(5.0, 0.5).matches?(5.51)).to eq(false)
|
||||
end
|
||||
|
||||
it "provides a useful failure message" do
|
||||
matcher = BeCloseMatcher.new(5.0, 0.5)
|
||||
matcher.matches?(6.5)
|
||||
matcher.failure_message.should == ["Expected 6.5", "to be within 5.0 +/- 0.5"]
|
||||
expect(matcher.failure_message).to eq(["Expected 6.5", "to be within 5.0 +/- 0.5"])
|
||||
end
|
||||
|
||||
it "provides a useful negative failure message" do
|
||||
matcher = BeCloseMatcher.new(5.0, 0.5)
|
||||
matcher.matches?(4.9)
|
||||
matcher.negative_failure_message.should == ["Expected 4.9", "not to be within 5.0 +/- 0.5"]
|
||||
expect(matcher.negative_failure_message).to eq(["Expected 4.9", "not to be within 5.0 +/- 0.5"])
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,35 +1,35 @@
|
|||
require 'spec_helper'
|
||||
require 'mspec/matchers'
|
||||
|
||||
describe BeComputedByMatcher do
|
||||
RSpec.describe BeComputedByMatcher do
|
||||
it "matches when all entries in the Array compute" do
|
||||
array = [ [65, "A"],
|
||||
[90, "Z"] ]
|
||||
BeComputedByMatcher.new(:chr).matches?(array).should be_true
|
||||
expect(BeComputedByMatcher.new(:chr).matches?(array)).to be_truthy
|
||||
end
|
||||
|
||||
it "matches when all entries in the Array with arguments compute" do
|
||||
array = [ [1, 2, 3],
|
||||
[2, 4, 6] ]
|
||||
BeComputedByMatcher.new(:+).matches?(array).should be_true
|
||||
expect(BeComputedByMatcher.new(:+).matches?(array)).to be_truthy
|
||||
end
|
||||
|
||||
it "does not match when any entry in the Array does not compute" do
|
||||
array = [ [65, "A" ],
|
||||
[91, "Z" ] ]
|
||||
BeComputedByMatcher.new(:chr).matches?(array).should be_false
|
||||
expect(BeComputedByMatcher.new(:chr).matches?(array)).to be_falsey
|
||||
end
|
||||
|
||||
it "accepts an argument list to apply to each method call" do
|
||||
array = [ [65, "1000001" ],
|
||||
[90, "1011010" ] ]
|
||||
BeComputedByMatcher.new(:to_s, 2).matches?(array).should be_true
|
||||
expect(BeComputedByMatcher.new(:to_s, 2).matches?(array)).to be_truthy
|
||||
end
|
||||
|
||||
it "does not match when any entry in the Array with arguments does not compute" do
|
||||
array = [ [1, 2, 3],
|
||||
[2, 4, 7] ]
|
||||
BeComputedByMatcher.new(:+).matches?(array).should be_false
|
||||
expect(BeComputedByMatcher.new(:+).matches?(array)).to be_falsey
|
||||
end
|
||||
|
||||
it "provides a useful failure message" do
|
||||
|
@ -37,6 +37,6 @@ describe BeComputedByMatcher do
|
|||
[91, "Z" ] ]
|
||||
matcher = BeComputedByMatcher.new(:chr)
|
||||
matcher.matches?(array)
|
||||
matcher.failure_message.should == ["Expected \"Z\"", "to be computed by 91.chr (computed \"[\" instead)"]
|
||||
expect(matcher.failure_message).to eq(["Expected \"Z\"", "to be computed by 91.chr (computed \"[\" instead)"])
|
||||
end
|
||||
end
|
||||
|
|
|
@ -2,25 +2,25 @@ require 'spec_helper'
|
|||
require 'mspec/expectations/expectations'
|
||||
require 'mspec/matchers'
|
||||
|
||||
describe BeEmptyMatcher do
|
||||
RSpec.describe BeEmptyMatcher do
|
||||
it "matches when actual is empty" do
|
||||
BeEmptyMatcher.new.matches?("").should == true
|
||||
expect(BeEmptyMatcher.new.matches?("")).to eq(true)
|
||||
end
|
||||
|
||||
it "does not match when actual is not empty" do
|
||||
BeEmptyMatcher.new.matches?([10]).should == false
|
||||
expect(BeEmptyMatcher.new.matches?([10])).to eq(false)
|
||||
end
|
||||
|
||||
it "provides a useful failure message" do
|
||||
matcher = BeEmptyMatcher.new
|
||||
matcher.matches?("not empty string")
|
||||
matcher.failure_message.should == ["Expected \"not empty string\"", "to be empty"]
|
||||
expect(matcher.failure_message).to eq(["Expected \"not empty string\"", "to be empty"])
|
||||
end
|
||||
|
||||
it "provides a useful negative failure message" do
|
||||
matcher = BeEmptyMatcher.new
|
||||
matcher.matches?("")
|
||||
matcher.negative_failure_message.should == ["Expected \"\"", "not to be empty"]
|
||||
expect(matcher.negative_failure_message).to eq(["Expected \"\"", "not to be empty"])
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -2,27 +2,27 @@ require 'spec_helper'
|
|||
require 'mspec/expectations/expectations'
|
||||
require 'mspec/matchers'
|
||||
|
||||
describe BeFalseMatcher do
|
||||
RSpec.describe BeFalseMatcher do
|
||||
it "matches when actual is false" do
|
||||
BeFalseMatcher.new.matches?(false).should == true
|
||||
expect(BeFalseMatcher.new.matches?(false)).to eq(true)
|
||||
end
|
||||
|
||||
it "does not match when actual is not false" do
|
||||
BeFalseMatcher.new.matches?("").should == false
|
||||
BeFalseMatcher.new.matches?(true).should == false
|
||||
BeFalseMatcher.new.matches?(nil).should == false
|
||||
BeFalseMatcher.new.matches?(0).should == false
|
||||
expect(BeFalseMatcher.new.matches?("")).to eq(false)
|
||||
expect(BeFalseMatcher.new.matches?(true)).to eq(false)
|
||||
expect(BeFalseMatcher.new.matches?(nil)).to eq(false)
|
||||
expect(BeFalseMatcher.new.matches?(0)).to eq(false)
|
||||
end
|
||||
|
||||
it "provides a useful failure message" do
|
||||
matcher = BeFalseMatcher.new
|
||||
matcher.matches?("some string")
|
||||
matcher.failure_message.should == ["Expected \"some string\"", "to be false"]
|
||||
expect(matcher.failure_message).to eq(["Expected \"some string\"", "to be false"])
|
||||
end
|
||||
|
||||
it "provides a useful negative failure message" do
|
||||
matcher = BeFalseMatcher.new
|
||||
matcher.matches?(false)
|
||||
matcher.negative_failure_message.should == ["Expected false", "not to be false"]
|
||||
expect(matcher.negative_failure_message).to eq(["Expected false", "not to be false"])
|
||||
end
|
||||
end
|
||||
|
|
|
@ -2,30 +2,30 @@ require 'spec_helper'
|
|||
require 'mspec/expectations/expectations'
|
||||
require 'mspec/matchers'
|
||||
|
||||
describe BeKindOfMatcher do
|
||||
RSpec.describe BeKindOfMatcher do
|
||||
it "matches when actual is a kind_of? expected" do
|
||||
BeKindOfMatcher.new(Numeric).matches?(1).should == true
|
||||
BeKindOfMatcher.new(Integer).matches?(2).should == true
|
||||
BeKindOfMatcher.new(Regexp).matches?(/m/).should == true
|
||||
expect(BeKindOfMatcher.new(Numeric).matches?(1)).to eq(true)
|
||||
expect(BeKindOfMatcher.new(Integer).matches?(2)).to eq(true)
|
||||
expect(BeKindOfMatcher.new(Regexp).matches?(/m/)).to eq(true)
|
||||
end
|
||||
|
||||
it "does not match when actual is not a kind_of? expected" do
|
||||
BeKindOfMatcher.new(Integer).matches?(1.5).should == false
|
||||
BeKindOfMatcher.new(String).matches?(:a).should == false
|
||||
BeKindOfMatcher.new(Hash).matches?([]).should == false
|
||||
expect(BeKindOfMatcher.new(Integer).matches?(1.5)).to eq(false)
|
||||
expect(BeKindOfMatcher.new(String).matches?(:a)).to eq(false)
|
||||
expect(BeKindOfMatcher.new(Hash).matches?([])).to eq(false)
|
||||
end
|
||||
|
||||
it "provides a useful failure message" do
|
||||
matcher = BeKindOfMatcher.new(Numeric)
|
||||
matcher.matches?('string')
|
||||
matcher.failure_message.should == [
|
||||
"Expected \"string\" (String)", "to be kind of Numeric"]
|
||||
expect(matcher.failure_message).to eq([
|
||||
"Expected \"string\" (String)", "to be kind of Numeric"])
|
||||
end
|
||||
|
||||
it "provides a useful negative failure message" do
|
||||
matcher = BeKindOfMatcher.new(Numeric)
|
||||
matcher.matches?(4.0)
|
||||
matcher.negative_failure_message.should == [
|
||||
"Expected 4.0 (Float)", "not to be kind of Numeric"]
|
||||
expect(matcher.negative_failure_message).to eq([
|
||||
"Expected 4.0 (Float)", "not to be kind of Numeric"])
|
||||
end
|
||||
end
|
||||
|
|
|
@ -4,25 +4,25 @@ require 'mspec/guards'
|
|||
require 'mspec/helpers'
|
||||
require 'mspec/matchers'
|
||||
|
||||
describe BeNaNMatcher do
|
||||
RSpec.describe BeNaNMatcher do
|
||||
it "matches when actual is NaN" do
|
||||
BeNaNMatcher.new.matches?(nan_value).should == true
|
||||
expect(BeNaNMatcher.new.matches?(nan_value)).to eq(true)
|
||||
end
|
||||
|
||||
it "does not match when actual is not NaN" do
|
||||
BeNaNMatcher.new.matches?(1.0).should == false
|
||||
BeNaNMatcher.new.matches?(0).should == false
|
||||
expect(BeNaNMatcher.new.matches?(1.0)).to eq(false)
|
||||
expect(BeNaNMatcher.new.matches?(0)).to eq(false)
|
||||
end
|
||||
|
||||
it "provides a useful failure message" do
|
||||
matcher = BeNaNMatcher.new
|
||||
matcher.matches?(0)
|
||||
matcher.failure_message.should == ["Expected 0", "to be NaN"]
|
||||
expect(matcher.failure_message).to eq(["Expected 0", "to be NaN"])
|
||||
end
|
||||
|
||||
it "provides a useful negative failure message" do
|
||||
matcher = BeNaNMatcher.new
|
||||
matcher.matches?(nan_value)
|
||||
matcher.negative_failure_message.should == ["Expected NaN", "not to be NaN"]
|
||||
expect(matcher.negative_failure_message).to eq(["Expected NaN", "not to be NaN"])
|
||||
end
|
||||
end
|
||||
|
|
|
@ -2,26 +2,26 @@ require 'spec_helper'
|
|||
require 'mspec/expectations/expectations'
|
||||
require 'mspec/matchers'
|
||||
|
||||
describe BeNilMatcher do
|
||||
RSpec.describe BeNilMatcher do
|
||||
it "matches when actual is nil" do
|
||||
BeNilMatcher.new.matches?(nil).should == true
|
||||
expect(BeNilMatcher.new.matches?(nil)).to eq(true)
|
||||
end
|
||||
|
||||
it "does not match when actual is not nil" do
|
||||
BeNilMatcher.new.matches?("").should == false
|
||||
BeNilMatcher.new.matches?(false).should == false
|
||||
BeNilMatcher.new.matches?(0).should == false
|
||||
expect(BeNilMatcher.new.matches?("")).to eq(false)
|
||||
expect(BeNilMatcher.new.matches?(false)).to eq(false)
|
||||
expect(BeNilMatcher.new.matches?(0)).to eq(false)
|
||||
end
|
||||
|
||||
it "provides a useful failure message" do
|
||||
matcher = BeNilMatcher.new
|
||||
matcher.matches?("some string")
|
||||
matcher.failure_message.should == ["Expected \"some string\"", "to be nil"]
|
||||
expect(matcher.failure_message).to eq(["Expected \"some string\"", "to be nil"])
|
||||
end
|
||||
|
||||
it "provides a useful negative failure message" do
|
||||
matcher = BeNilMatcher.new
|
||||
matcher.matches?(nil)
|
||||
matcher.negative_failure_message.should == ["Expected nil", "not to be nil"]
|
||||
expect(matcher.negative_failure_message).to eq(["Expected nil", "not to be nil"])
|
||||
end
|
||||
end
|
||||
|
|
|
@ -2,18 +2,18 @@ require 'spec_helper'
|
|||
require 'mspec/expectations/expectations'
|
||||
require 'mspec/matchers'
|
||||
|
||||
describe BeTrueOrFalseMatcher do
|
||||
RSpec.describe BeTrueOrFalseMatcher do
|
||||
it "matches when actual is true" do
|
||||
BeTrueOrFalseMatcher.new.matches?(true).should == true
|
||||
expect(BeTrueOrFalseMatcher.new.matches?(true)).to eq(true)
|
||||
end
|
||||
|
||||
it "matches when actual is false" do
|
||||
BeTrueOrFalseMatcher.new.matches?(false).should == true
|
||||
expect(BeTrueOrFalseMatcher.new.matches?(false)).to eq(true)
|
||||
end
|
||||
|
||||
it "provides a useful failure message" do
|
||||
matcher = BeTrueOrFalseMatcher.new
|
||||
matcher.matches?("some string")
|
||||
matcher.failure_message.should == ["Expected \"some string\"", "to be true or false"]
|
||||
expect(matcher.failure_message).to eq(["Expected \"some string\"", "to be true or false"])
|
||||
end
|
||||
end
|
||||
|
|
|
@ -2,27 +2,27 @@ require 'spec_helper'
|
|||
require 'mspec/expectations/expectations'
|
||||
require 'mspec/matchers'
|
||||
|
||||
describe BeTrueMatcher do
|
||||
RSpec.describe BeTrueMatcher do
|
||||
it "matches when actual is true" do
|
||||
BeTrueMatcher.new.matches?(true).should == true
|
||||
expect(BeTrueMatcher.new.matches?(true)).to eq(true)
|
||||
end
|
||||
|
||||
it "does not match when actual is not true" do
|
||||
BeTrueMatcher.new.matches?("").should == false
|
||||
BeTrueMatcher.new.matches?(false).should == false
|
||||
BeTrueMatcher.new.matches?(nil).should == false
|
||||
BeTrueMatcher.new.matches?(0).should == false
|
||||
expect(BeTrueMatcher.new.matches?("")).to eq(false)
|
||||
expect(BeTrueMatcher.new.matches?(false)).to eq(false)
|
||||
expect(BeTrueMatcher.new.matches?(nil)).to eq(false)
|
||||
expect(BeTrueMatcher.new.matches?(0)).to eq(false)
|
||||
end
|
||||
|
||||
it "provides a useful failure message" do
|
||||
matcher = BeTrueMatcher.new
|
||||
matcher.matches?("some string")
|
||||
matcher.failure_message.should == ["Expected \"some string\"", "to be true"]
|
||||
expect(matcher.failure_message).to eq(["Expected \"some string\"", "to be true"])
|
||||
end
|
||||
|
||||
it "provides a useful negative failure message" do
|
||||
matcher = BeTrueMatcher.new
|
||||
matcher.matches?(true)
|
||||
matcher.negative_failure_message.should == ["Expected true", "not to be true"]
|
||||
expect(matcher.negative_failure_message).to eq(["Expected true", "not to be true"])
|
||||
end
|
||||
end
|
||||
|
|
|
@ -2,12 +2,12 @@ require 'spec_helper'
|
|||
require 'mspec/expectations/expectations'
|
||||
require 'mspec/matchers'
|
||||
|
||||
describe BlockingMatcher do
|
||||
RSpec.describe BlockingMatcher do
|
||||
it 'matches when a Proc blocks the caller' do
|
||||
BlockingMatcher.new.matches?(proc { sleep }).should == true
|
||||
expect(BlockingMatcher.new.matches?(proc { sleep })).to eq(true)
|
||||
end
|
||||
|
||||
it 'does not match when a Proc does not block the caller' do
|
||||
BlockingMatcher.new.matches?(proc { 1 }).should == false
|
||||
expect(BlockingMatcher.new.matches?(proc { 1 })).to eq(false)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -2,52 +2,57 @@ require 'spec_helper'
|
|||
require 'mspec/expectations/expectations'
|
||||
require 'mspec/matchers'
|
||||
|
||||
describe ComplainMatcher do
|
||||
RSpec.describe ComplainMatcher do
|
||||
it "matches when executing the proc results in output to $stderr" do
|
||||
proc = lambda { warn "I'm gonna tell yo mama" }
|
||||
ComplainMatcher.new(nil).matches?(proc).should == true
|
||||
expect(ComplainMatcher.new(nil).matches?(proc)).to eq(true)
|
||||
end
|
||||
|
||||
it "matches when executing the proc results in the expected output to $stderr" do
|
||||
proc = lambda { warn "Que haces?" }
|
||||
ComplainMatcher.new("Que haces?\n").matches?(proc).should == true
|
||||
ComplainMatcher.new("Que pasa?\n").matches?(proc).should == false
|
||||
ComplainMatcher.new(/Que/).matches?(proc).should == true
|
||||
ComplainMatcher.new(/Quoi/).matches?(proc).should == false
|
||||
expect(ComplainMatcher.new("Que haces?\n").matches?(proc)).to eq(true)
|
||||
expect(ComplainMatcher.new("Que pasa?\n").matches?(proc)).to eq(false)
|
||||
expect(ComplainMatcher.new(/Que/).matches?(proc)).to eq(true)
|
||||
expect(ComplainMatcher.new(/Quoi/).matches?(proc)).to eq(false)
|
||||
end
|
||||
|
||||
it "does not match when there is no output to $stderr" do
|
||||
ComplainMatcher.new(nil).matches?(lambda {}).should == false
|
||||
expect(ComplainMatcher.new(nil).matches?(lambda {})).to eq(false)
|
||||
end
|
||||
|
||||
it "provides a useful failure message" do
|
||||
matcher = ComplainMatcher.new(nil)
|
||||
matcher.matches?(lambda { })
|
||||
matcher.failure_message.should == ["Expected a warning", "but received none"]
|
||||
expect(matcher.failure_message).to eq(["Expected a warning", "but received none"])
|
||||
matcher = ComplainMatcher.new("listen here")
|
||||
matcher.matches?(lambda { warn "look out" })
|
||||
matcher.failure_message.should ==
|
||||
expect(matcher.failure_message).to eq(
|
||||
["Expected warning: \"listen here\"", "but got: \"look out\""]
|
||||
)
|
||||
matcher = ComplainMatcher.new(/talk/)
|
||||
matcher.matches?(lambda { warn "listen up" })
|
||||
matcher.failure_message.should ==
|
||||
expect(matcher.failure_message).to eq(
|
||||
["Expected warning to match: /talk/", "but got: \"listen up\""]
|
||||
)
|
||||
end
|
||||
|
||||
it "provides a useful negative failure message" do
|
||||
proc = lambda { warn "ouch" }
|
||||
matcher = ComplainMatcher.new(nil)
|
||||
matcher.matches?(proc)
|
||||
matcher.negative_failure_message.should ==
|
||||
expect(matcher.negative_failure_message).to eq(
|
||||
["Unexpected warning: ", "\"ouch\""]
|
||||
)
|
||||
matcher = ComplainMatcher.new("ouchy")
|
||||
matcher.matches?(proc)
|
||||
matcher.negative_failure_message.should ==
|
||||
expect(matcher.negative_failure_message).to eq(
|
||||
["Expected warning: \"ouchy\"", "but got: \"ouch\""]
|
||||
)
|
||||
matcher = ComplainMatcher.new(/ou/)
|
||||
matcher.matches?(proc)
|
||||
matcher.negative_failure_message.should ==
|
||||
expect(matcher.negative_failure_message).to eq(
|
||||
["Expected warning not to match: /ou/", "but got: \"ouch\""]
|
||||
)
|
||||
end
|
||||
|
||||
context "`verbose` option specified" do
|
||||
|
@ -64,10 +69,10 @@ describe ComplainMatcher do
|
|||
proc = lambda { verbose = $VERBOSE }
|
||||
|
||||
ComplainMatcher.new(nil, verbose: true).matches?(proc)
|
||||
verbose.should == true
|
||||
expect(verbose).to eq(true)
|
||||
|
||||
ComplainMatcher.new(nil, verbose: false).matches?(proc)
|
||||
verbose.should == false
|
||||
expect(verbose).to eq(false)
|
||||
end
|
||||
|
||||
it "sets $VERBOSE with false by default" do
|
||||
|
@ -75,15 +80,15 @@ describe ComplainMatcher do
|
|||
proc = lambda { verbose = $VERBOSE }
|
||||
|
||||
ComplainMatcher.new(nil).matches?(proc)
|
||||
verbose.should == false
|
||||
expect(verbose).to eq(false)
|
||||
end
|
||||
|
||||
it "does not have side effect" do
|
||||
proc = lambda { safe_value = $VERBOSE }
|
||||
|
||||
lambda do
|
||||
expect do
|
||||
ComplainMatcher.new(nil, verbose: true).matches?(proc)
|
||||
end.should_not change { $VERBOSE }
|
||||
end.not_to change { $VERBOSE }
|
||||
end
|
||||
|
||||
it "accepts a verbose level as single argument" do
|
||||
|
@ -91,7 +96,7 @@ describe ComplainMatcher do
|
|||
proc = lambda { verbose = $VERBOSE }
|
||||
|
||||
ComplainMatcher.new(verbose: true).matches?(proc)
|
||||
verbose.should == true
|
||||
expect(verbose).to eq(true)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -2,32 +2,32 @@ require 'spec_helper'
|
|||
require 'mspec/expectations/expectations'
|
||||
require 'mspec/matchers'
|
||||
|
||||
describe EqlMatcher do
|
||||
RSpec.describe EqlMatcher do
|
||||
it "matches when actual is eql? to expected" do
|
||||
EqlMatcher.new(1).matches?(1).should == true
|
||||
EqlMatcher.new(1.5).matches?(1.5).should == true
|
||||
EqlMatcher.new("red").matches?("red").should == true
|
||||
EqlMatcher.new(:blue).matches?(:blue).should == true
|
||||
EqlMatcher.new(Object).matches?(Object).should == true
|
||||
expect(EqlMatcher.new(1).matches?(1)).to eq(true)
|
||||
expect(EqlMatcher.new(1.5).matches?(1.5)).to eq(true)
|
||||
expect(EqlMatcher.new("red").matches?("red")).to eq(true)
|
||||
expect(EqlMatcher.new(:blue).matches?(:blue)).to eq(true)
|
||||
expect(EqlMatcher.new(Object).matches?(Object)).to eq(true)
|
||||
|
||||
o = Object.new
|
||||
EqlMatcher.new(o).matches?(o).should == true
|
||||
expect(EqlMatcher.new(o).matches?(o)).to eq(true)
|
||||
end
|
||||
|
||||
it "does not match when actual is not eql? to expected" do
|
||||
EqlMatcher.new(1).matches?(1.0).should == false
|
||||
EqlMatcher.new(Hash).matches?(Object).should == false
|
||||
expect(EqlMatcher.new(1).matches?(1.0)).to eq(false)
|
||||
expect(EqlMatcher.new(Hash).matches?(Object)).to eq(false)
|
||||
end
|
||||
|
||||
it "provides a useful failure message" do
|
||||
matcher = EqlMatcher.new("red")
|
||||
matcher.matches?("red")
|
||||
matcher.failure_message.should == ["Expected \"red\"", "to have same value and type as \"red\""]
|
||||
expect(matcher.failure_message).to eq(["Expected \"red\"", "to have same value and type as \"red\""])
|
||||
end
|
||||
|
||||
it "provides a useful negative failure message" do
|
||||
matcher = EqlMatcher.new(1)
|
||||
matcher.matches?(1.0)
|
||||
matcher.negative_failure_message.should == ["Expected 1.0", "not to have same value or type as 1"]
|
||||
expect(matcher.negative_failure_message).to eq(["Expected 1.0", "not to have same value or type as 1"])
|
||||
end
|
||||
end
|
||||
|
|
|
@ -2,74 +2,74 @@ require 'spec_helper'
|
|||
require 'mspec/expectations/expectations'
|
||||
require 'mspec/matchers'
|
||||
|
||||
describe EqualElementMatcher do
|
||||
RSpec.describe EqualElementMatcher do
|
||||
it "matches if it finds an element with the passed name, no matter what attributes/content" do
|
||||
EqualElementMatcher.new("A").matches?('<A></A>').should be_true
|
||||
EqualElementMatcher.new("A").matches?('<A HREF="http://example.com"></A>').should be_true
|
||||
EqualElementMatcher.new("A").matches?('<A HREF="http://example.com"></A>').should be_true
|
||||
expect(EqualElementMatcher.new("A").matches?('<A></A>')).to be_truthy
|
||||
expect(EqualElementMatcher.new("A").matches?('<A HREF="http://example.com"></A>')).to be_truthy
|
||||
expect(EqualElementMatcher.new("A").matches?('<A HREF="http://example.com"></A>')).to be_truthy
|
||||
|
||||
EqualElementMatcher.new("BASE").matches?('<BASE></A>').should be_false
|
||||
EqualElementMatcher.new("BASE").matches?('<A></BASE>').should be_false
|
||||
EqualElementMatcher.new("BASE").matches?('<A></A>').should be_false
|
||||
EqualElementMatcher.new("BASE").matches?('<A HREF="http://example.com"></A>').should be_false
|
||||
EqualElementMatcher.new("BASE").matches?('<A HREF="http://example.com"></A>').should be_false
|
||||
expect(EqualElementMatcher.new("BASE").matches?('<BASE></A>')).to be_falsey
|
||||
expect(EqualElementMatcher.new("BASE").matches?('<A></BASE>')).to be_falsey
|
||||
expect(EqualElementMatcher.new("BASE").matches?('<A></A>')).to be_falsey
|
||||
expect(EqualElementMatcher.new("BASE").matches?('<A HREF="http://example.com"></A>')).to be_falsey
|
||||
expect(EqualElementMatcher.new("BASE").matches?('<A HREF="http://example.com"></A>')).to be_falsey
|
||||
end
|
||||
|
||||
it "matches if it finds an element with the passed name and the passed attributes" do
|
||||
EqualElementMatcher.new("A", {}).matches?('<A></A>').should be_true
|
||||
EqualElementMatcher.new("A", nil).matches?('<A HREF="http://example.com"></A>').should be_true
|
||||
EqualElementMatcher.new("A", "HREF" => "http://example.com").matches?('<A HREF="http://example.com"></A>').should be_true
|
||||
expect(EqualElementMatcher.new("A", {}).matches?('<A></A>')).to be_truthy
|
||||
expect(EqualElementMatcher.new("A", nil).matches?('<A HREF="http://example.com"></A>')).to be_truthy
|
||||
expect(EqualElementMatcher.new("A", "HREF" => "http://example.com").matches?('<A HREF="http://example.com"></A>')).to be_truthy
|
||||
|
||||
EqualElementMatcher.new("A", {}).matches?('<A HREF="http://example.com"></A>').should be_false
|
||||
EqualElementMatcher.new("A", "HREF" => "http://example.com").matches?('<A></A>').should be_false
|
||||
EqualElementMatcher.new("A", "HREF" => "http://example.com").matches?('<A HREF="http://test.com"></A>').should be_false
|
||||
EqualElementMatcher.new("A", "HREF" => "http://example.com").matches?('<A HREF="http://example.com" HREF="http://example.com"></A>').should be_false
|
||||
expect(EqualElementMatcher.new("A", {}).matches?('<A HREF="http://example.com"></A>')).to be_falsey
|
||||
expect(EqualElementMatcher.new("A", "HREF" => "http://example.com").matches?('<A></A>')).to be_falsey
|
||||
expect(EqualElementMatcher.new("A", "HREF" => "http://example.com").matches?('<A HREF="http://test.com"></A>')).to be_falsey
|
||||
expect(EqualElementMatcher.new("A", "HREF" => "http://example.com").matches?('<A HREF="http://example.com" HREF="http://example.com"></A>')).to be_falsey
|
||||
end
|
||||
|
||||
it "matches if it finds an element with the passed name, the passed attributes and the passed content" do
|
||||
EqualElementMatcher.new("A", {}, "").matches?('<A></A>').should be_true
|
||||
EqualElementMatcher.new("A", {"HREF" => "http://example.com"}, "Example").matches?('<A HREF="http://example.com">Example</A>').should be_true
|
||||
expect(EqualElementMatcher.new("A", {}, "").matches?('<A></A>')).to be_truthy
|
||||
expect(EqualElementMatcher.new("A", {"HREF" => "http://example.com"}, "Example").matches?('<A HREF="http://example.com">Example</A>')).to be_truthy
|
||||
|
||||
EqualElementMatcher.new("A", {}, "Test").matches?('<A></A>').should be_false
|
||||
EqualElementMatcher.new("A", {"HREF" => "http://example.com"}, "Example").matches?('<A HREF="http://example.com"></A>').should be_false
|
||||
EqualElementMatcher.new("A", {"HREF" => "http://example.com"}, "Example").matches?('<A HREF="http://example.com">Test</A>').should be_false
|
||||
expect(EqualElementMatcher.new("A", {}, "Test").matches?('<A></A>')).to be_falsey
|
||||
expect(EqualElementMatcher.new("A", {"HREF" => "http://example.com"}, "Example").matches?('<A HREF="http://example.com"></A>')).to be_falsey
|
||||
expect(EqualElementMatcher.new("A", {"HREF" => "http://example.com"}, "Example").matches?('<A HREF="http://example.com">Test</A>')).to be_falsey
|
||||
end
|
||||
|
||||
it "can match unclosed elements" do
|
||||
EqualElementMatcher.new("BASE", nil, nil, :not_closed => true).matches?('<BASE>').should be_true
|
||||
EqualElementMatcher.new("BASE", {"HREF" => "http://example.com"}, nil, :not_closed => true).matches?('<BASE HREF="http://example.com">').should be_true
|
||||
EqualElementMatcher.new("BASE", {"HREF" => "http://example.com"}, "Example", :not_closed => true).matches?('<BASE HREF="http://example.com">Example').should be_true
|
||||
expect(EqualElementMatcher.new("BASE", nil, nil, :not_closed => true).matches?('<BASE>')).to be_truthy
|
||||
expect(EqualElementMatcher.new("BASE", {"HREF" => "http://example.com"}, nil, :not_closed => true).matches?('<BASE HREF="http://example.com">')).to be_truthy
|
||||
expect(EqualElementMatcher.new("BASE", {"HREF" => "http://example.com"}, "Example", :not_closed => true).matches?('<BASE HREF="http://example.com">Example')).to be_truthy
|
||||
|
||||
EqualElementMatcher.new("BASE", {}, nil, :not_closed => true).matches?('<BASE HREF="http://example.com">').should be_false
|
||||
EqualElementMatcher.new("BASE", {"HREF" => "http://example.com"}, "", :not_closed => true).matches?('<BASE HREF="http://example.com">Example').should be_false
|
||||
EqualElementMatcher.new("BASE", {"HREF" => "http://example.com"}, "Test", :not_closed => true).matches?('<BASE HREF="http://example.com">Example').should be_false
|
||||
expect(EqualElementMatcher.new("BASE", {}, nil, :not_closed => true).matches?('<BASE HREF="http://example.com">')).to be_falsey
|
||||
expect(EqualElementMatcher.new("BASE", {"HREF" => "http://example.com"}, "", :not_closed => true).matches?('<BASE HREF="http://example.com">Example')).to be_falsey
|
||||
expect(EqualElementMatcher.new("BASE", {"HREF" => "http://example.com"}, "Test", :not_closed => true).matches?('<BASE HREF="http://example.com">Example')).to be_falsey
|
||||
end
|
||||
|
||||
it "provides a useful failure message" do
|
||||
equal_element = EqualElementMatcher.new("A", {}, "Test")
|
||||
equal_element.matches?('<A></A>').should be_false
|
||||
equal_element.failure_message.should == [%{Expected "<A></A>"}, %{to be a 'A' element with no attributes and "Test" as content}]
|
||||
expect(equal_element.matches?('<A></A>')).to be_falsey
|
||||
expect(equal_element.failure_message).to eq([%{Expected "<A></A>"}, %{to be a 'A' element with no attributes and "Test" as content}])
|
||||
|
||||
equal_element = EqualElementMatcher.new("A", {}, "")
|
||||
equal_element.matches?('<A>Test</A>').should be_false
|
||||
equal_element.failure_message.should == [%{Expected "<A>Test</A>"}, %{to be a 'A' element with no attributes and no content}]
|
||||
expect(equal_element.matches?('<A>Test</A>')).to be_falsey
|
||||
expect(equal_element.failure_message).to eq([%{Expected "<A>Test</A>"}, %{to be a 'A' element with no attributes and no content}])
|
||||
|
||||
equal_element = EqualElementMatcher.new("A", "HREF" => "http://www.example.com")
|
||||
equal_element.matches?('<A>Test</A>').should be_false
|
||||
equal_element.failure_message.should == [%{Expected "<A>Test</A>"}, %{to be a 'A' element with HREF="http://www.example.com" and any content}]
|
||||
expect(equal_element.matches?('<A>Test</A>')).to be_falsey
|
||||
expect(equal_element.failure_message).to eq([%{Expected "<A>Test</A>"}, %{to be a 'A' element with HREF="http://www.example.com" and any content}])
|
||||
end
|
||||
|
||||
it "provides a useful negative failure message" do
|
||||
equal_element = EqualElementMatcher.new("A", {}, "Test")
|
||||
equal_element.matches?('<A></A>').should be_false
|
||||
equal_element.negative_failure_message.should == [%{Expected "<A></A>"}, %{not to be a 'A' element with no attributes and "Test" as content}]
|
||||
expect(equal_element.matches?('<A></A>')).to be_falsey
|
||||
expect(equal_element.negative_failure_message).to eq([%{Expected "<A></A>"}, %{not to be a 'A' element with no attributes and "Test" as content}])
|
||||
|
||||
equal_element = EqualElementMatcher.new("A", {}, "")
|
||||
equal_element.matches?('<A>Test</A>').should be_false
|
||||
equal_element.negative_failure_message.should == [%{Expected "<A>Test</A>"}, %{not to be a 'A' element with no attributes and no content}]
|
||||
expect(equal_element.matches?('<A>Test</A>')).to be_falsey
|
||||
expect(equal_element.negative_failure_message).to eq([%{Expected "<A>Test</A>"}, %{not to be a 'A' element with no attributes and no content}])
|
||||
|
||||
equal_element = EqualElementMatcher.new("A", "HREF" => "http://www.example.com")
|
||||
equal_element.matches?('<A>Test</A>').should be_false
|
||||
equal_element.negative_failure_message.should == [%{Expected "<A>Test</A>"}, %{not to be a 'A' element with HREF="http://www.example.com" and any content}]
|
||||
expect(equal_element.matches?('<A>Test</A>')).to be_falsey
|
||||
expect(equal_element.negative_failure_message).to eq([%{Expected "<A>Test</A>"}, %{not to be a 'A' element with HREF="http://www.example.com" and any content}])
|
||||
end
|
||||
end
|
||||
|
|
|
@ -2,31 +2,31 @@ require 'spec_helper'
|
|||
require 'mspec/expectations/expectations'
|
||||
require 'mspec/matchers'
|
||||
|
||||
describe EqualMatcher do
|
||||
RSpec.describe EqualMatcher do
|
||||
it "matches when actual is equal? to expected" do
|
||||
EqualMatcher.new(1).matches?(1).should == true
|
||||
EqualMatcher.new(:blue).matches?(:blue).should == true
|
||||
EqualMatcher.new(Object).matches?(Object).should == true
|
||||
expect(EqualMatcher.new(1).matches?(1)).to eq(true)
|
||||
expect(EqualMatcher.new(:blue).matches?(:blue)).to eq(true)
|
||||
expect(EqualMatcher.new(Object).matches?(Object)).to eq(true)
|
||||
|
||||
o = Object.new
|
||||
EqualMatcher.new(o).matches?(o).should == true
|
||||
expect(EqualMatcher.new(o).matches?(o)).to eq(true)
|
||||
end
|
||||
|
||||
it "does not match when actual is not a equal? to expected" do
|
||||
EqualMatcher.new(1).matches?(1.0).should == false
|
||||
EqualMatcher.new("blue").matches?("blue").should == false
|
||||
EqualMatcher.new(Hash).matches?(Object).should == false
|
||||
expect(EqualMatcher.new(1).matches?(1.0)).to eq(false)
|
||||
expect(EqualMatcher.new("blue").matches?("blue")).to eq(false)
|
||||
expect(EqualMatcher.new(Hash).matches?(Object)).to eq(false)
|
||||
end
|
||||
|
||||
it "provides a useful failure message" do
|
||||
matcher = EqualMatcher.new("red")
|
||||
matcher.matches?("red")
|
||||
matcher.failure_message.should == ["Expected \"red\"", "to be identical to \"red\""]
|
||||
expect(matcher.failure_message).to eq(["Expected \"red\"", "to be identical to \"red\""])
|
||||
end
|
||||
|
||||
it "provides a useful negative failure message" do
|
||||
matcher = EqualMatcher.new(1)
|
||||
matcher.matches?(1)
|
||||
matcher.negative_failure_message.should == ["Expected 1", "not to be identical to 1"]
|
||||
expect(matcher.negative_failure_message).to eq(["Expected 1", "not to be identical to 1"])
|
||||
end
|
||||
end
|
||||
|
|
|
@ -8,42 +8,42 @@ class IVarModMock
|
|||
end
|
||||
end
|
||||
|
||||
describe HaveClassVariableMatcher, "on RUBY_VERSION >= 1.9" do
|
||||
RSpec.describe HaveClassVariableMatcher, "on RUBY_VERSION >= 1.9" do
|
||||
it "matches when mod has the class variable, given as string" do
|
||||
matcher = HaveClassVariableMatcher.new('@foo')
|
||||
matcher.matches?(IVarModMock).should be_true
|
||||
expect(matcher.matches?(IVarModMock)).to be_truthy
|
||||
end
|
||||
|
||||
it "matches when mod has the class variable, given as symbol" do
|
||||
matcher = HaveClassVariableMatcher.new(:@foo)
|
||||
matcher.matches?(IVarModMock).should be_true
|
||||
expect(matcher.matches?(IVarModMock)).to be_truthy
|
||||
end
|
||||
|
||||
it "does not match when mod hasn't got the class variable, given as string" do
|
||||
matcher = HaveClassVariableMatcher.new('@bar')
|
||||
matcher.matches?(IVarModMock).should be_false
|
||||
expect(matcher.matches?(IVarModMock)).to be_falsey
|
||||
end
|
||||
|
||||
it "does not match when mod hasn't got the class variable, given as symbol" do
|
||||
matcher = HaveClassVariableMatcher.new(:@bar)
|
||||
matcher.matches?(IVarModMock).should be_false
|
||||
expect(matcher.matches?(IVarModMock)).to be_falsey
|
||||
end
|
||||
|
||||
it "provides a failure message for #should" do
|
||||
matcher = HaveClassVariableMatcher.new(:@bar)
|
||||
matcher.matches?(IVarModMock)
|
||||
matcher.failure_message.should == [
|
||||
expect(matcher.failure_message).to eq([
|
||||
"Expected IVarModMock to have class variable '@bar'",
|
||||
"but it does not"
|
||||
]
|
||||
])
|
||||
end
|
||||
|
||||
it "provides a failure messoge for #should_not" do
|
||||
matcher = HaveClassVariableMatcher.new(:@bar)
|
||||
matcher.matches?(IVarModMock)
|
||||
matcher.negative_failure_message.should == [
|
||||
expect(matcher.negative_failure_message).to eq([
|
||||
"Expected IVarModMock NOT to have class variable '@bar'",
|
||||
"but it does"
|
||||
]
|
||||
])
|
||||
end
|
||||
end
|
||||
|
|
|
@ -6,32 +6,32 @@ class HCMSpecs
|
|||
X = :x
|
||||
end
|
||||
|
||||
describe HaveConstantMatcher do
|
||||
RSpec.describe HaveConstantMatcher do
|
||||
it "matches when mod has the constant" do
|
||||
matcher = HaveConstantMatcher.new :X
|
||||
matcher.matches?(HCMSpecs).should be_true
|
||||
expect(matcher.matches?(HCMSpecs)).to be_truthy
|
||||
end
|
||||
|
||||
it "does not match when mod does not have the constant" do
|
||||
matcher = HaveConstantMatcher.new :A
|
||||
matcher.matches?(HCMSpecs).should be_false
|
||||
expect(matcher.matches?(HCMSpecs)).to be_falsey
|
||||
end
|
||||
|
||||
it "provides a failure message for #should" do
|
||||
matcher = HaveConstantMatcher.new :A
|
||||
matcher.matches?(HCMSpecs)
|
||||
matcher.failure_message.should == [
|
||||
expect(matcher.failure_message).to eq([
|
||||
"Expected HCMSpecs to have constant 'A'",
|
||||
"but it does not"
|
||||
]
|
||||
])
|
||||
end
|
||||
|
||||
it "provides a failure messoge for #should_not" do
|
||||
matcher = HaveConstantMatcher.new :X
|
||||
matcher.matches?(HCMSpecs)
|
||||
matcher.negative_failure_message.should == [
|
||||
expect(matcher.negative_failure_message).to eq([
|
||||
"Expected HCMSpecs NOT to have constant 'X'",
|
||||
"but it does"
|
||||
]
|
||||
])
|
||||
end
|
||||
end
|
||||
|
|
|
@ -12,42 +12,42 @@ class HIMMSpecs
|
|||
end
|
||||
end
|
||||
|
||||
describe HaveInstanceMethodMatcher do
|
||||
RSpec.describe HaveInstanceMethodMatcher do
|
||||
it "inherits from MethodMatcher" do
|
||||
HaveInstanceMethodMatcher.new(:m).should be_kind_of(MethodMatcher)
|
||||
expect(HaveInstanceMethodMatcher.new(:m)).to be_kind_of(MethodMatcher)
|
||||
end
|
||||
|
||||
it "matches when mod has the instance method" do
|
||||
matcher = HaveInstanceMethodMatcher.new :instance_method
|
||||
matcher.matches?(HIMMSpecs).should be_true
|
||||
matcher.matches?(HIMMSpecs::Subclass).should be_true
|
||||
expect(matcher.matches?(HIMMSpecs)).to be_truthy
|
||||
expect(matcher.matches?(HIMMSpecs::Subclass)).to be_truthy
|
||||
end
|
||||
|
||||
it "does not match when mod does not have the instance method" do
|
||||
matcher = HaveInstanceMethodMatcher.new :another_method
|
||||
matcher.matches?(HIMMSpecs).should be_false
|
||||
expect(matcher.matches?(HIMMSpecs)).to be_falsey
|
||||
end
|
||||
|
||||
it "does not match if the method is in a superclass and include_super is false" do
|
||||
matcher = HaveInstanceMethodMatcher.new :instance_method, false
|
||||
matcher.matches?(HIMMSpecs::Subclass).should be_false
|
||||
expect(matcher.matches?(HIMMSpecs::Subclass)).to be_falsey
|
||||
end
|
||||
|
||||
it "provides a failure message for #should" do
|
||||
matcher = HaveInstanceMethodMatcher.new :some_method
|
||||
matcher.matches?(HIMMSpecs)
|
||||
matcher.failure_message.should == [
|
||||
expect(matcher.failure_message).to eq([
|
||||
"Expected HIMMSpecs to have instance method 'some_method'",
|
||||
"but it does not"
|
||||
]
|
||||
])
|
||||
end
|
||||
|
||||
it "provides a failure messoge for #should_not" do
|
||||
matcher = HaveInstanceMethodMatcher.new :some_method
|
||||
matcher.matches?(HIMMSpecs)
|
||||
matcher.negative_failure_message.should == [
|
||||
expect(matcher.negative_failure_message).to eq([
|
||||
"Expected HIMMSpecs NOT to have instance method 'some_method'",
|
||||
"but it does"
|
||||
]
|
||||
])
|
||||
end
|
||||
end
|
||||
|
|
|
@ -2,7 +2,7 @@ require 'spec_helper'
|
|||
require 'mspec/expectations/expectations'
|
||||
require 'mspec/matchers'
|
||||
|
||||
describe HaveInstanceVariableMatcher do
|
||||
RSpec.describe HaveInstanceVariableMatcher do
|
||||
before :each do
|
||||
@object = Object.new
|
||||
def @object.instance_variables
|
||||
|
@ -12,39 +12,39 @@ describe HaveInstanceVariableMatcher do
|
|||
|
||||
it "matches when object has the instance variable, given as string" do
|
||||
matcher = HaveInstanceVariableMatcher.new('@foo')
|
||||
matcher.matches?(@object).should be_true
|
||||
expect(matcher.matches?(@object)).to be_truthy
|
||||
end
|
||||
|
||||
it "matches when object has the instance variable, given as symbol" do
|
||||
matcher = HaveInstanceVariableMatcher.new(:@foo)
|
||||
matcher.matches?(@object).should be_true
|
||||
expect(matcher.matches?(@object)).to be_truthy
|
||||
end
|
||||
|
||||
it "does not match when object hasn't got the instance variable, given as string" do
|
||||
matcher = HaveInstanceVariableMatcher.new('@bar')
|
||||
matcher.matches?(@object).should be_false
|
||||
expect(matcher.matches?(@object)).to be_falsey
|
||||
end
|
||||
|
||||
it "does not match when object hasn't got the instance variable, given as symbol" do
|
||||
matcher = HaveInstanceVariableMatcher.new(:@bar)
|
||||
matcher.matches?(@object).should be_false
|
||||
expect(matcher.matches?(@object)).to be_falsey
|
||||
end
|
||||
|
||||
it "provides a failure message for #should" do
|
||||
matcher = HaveInstanceVariableMatcher.new(:@bar)
|
||||
matcher.matches?(@object)
|
||||
matcher.failure_message.should == [
|
||||
expect(matcher.failure_message).to eq([
|
||||
"Expected #{@object.inspect} to have instance variable '@bar'",
|
||||
"but it does not"
|
||||
]
|
||||
])
|
||||
end
|
||||
|
||||
it "provides a failure messoge for #should_not" do
|
||||
matcher = HaveInstanceVariableMatcher.new(:@bar)
|
||||
matcher.matches?(@object)
|
||||
matcher.negative_failure_message.should == [
|
||||
expect(matcher.negative_failure_message).to eq([
|
||||
"Expected #{@object.inspect} NOT to have instance variable '@bar'",
|
||||
"but it does"
|
||||
]
|
||||
])
|
||||
end
|
||||
end
|
||||
|
|
|
@ -12,44 +12,44 @@ class HMMSpecs
|
|||
end
|
||||
end
|
||||
|
||||
describe HaveMethodMatcher do
|
||||
RSpec.describe HaveMethodMatcher do
|
||||
it "inherits from MethodMatcher" do
|
||||
HaveMethodMatcher.new(:m).should be_kind_of(MethodMatcher)
|
||||
expect(HaveMethodMatcher.new(:m)).to be_kind_of(MethodMatcher)
|
||||
end
|
||||
|
||||
it "matches when mod has the method" do
|
||||
matcher = HaveMethodMatcher.new :instance_method
|
||||
matcher.matches?(HMMSpecs).should be_true
|
||||
matcher.matches?(HMMSpecs.new).should be_true
|
||||
matcher.matches?(HMMSpecs::Subclass).should be_true
|
||||
matcher.matches?(HMMSpecs::Subclass.new).should be_true
|
||||
expect(matcher.matches?(HMMSpecs)).to be_truthy
|
||||
expect(matcher.matches?(HMMSpecs.new)).to be_truthy
|
||||
expect(matcher.matches?(HMMSpecs::Subclass)).to be_truthy
|
||||
expect(matcher.matches?(HMMSpecs::Subclass.new)).to be_truthy
|
||||
end
|
||||
|
||||
it "does not match when mod does not have the method" do
|
||||
matcher = HaveMethodMatcher.new :another_method
|
||||
matcher.matches?(HMMSpecs).should be_false
|
||||
expect(matcher.matches?(HMMSpecs)).to be_falsey
|
||||
end
|
||||
|
||||
it "does not match if the method is in a superclass and include_super is false" do
|
||||
matcher = HaveMethodMatcher.new :instance_method, false
|
||||
matcher.matches?(HMMSpecs::Subclass).should be_false
|
||||
expect(matcher.matches?(HMMSpecs::Subclass)).to be_falsey
|
||||
end
|
||||
|
||||
it "provides a failure message for #should" do
|
||||
matcher = HaveMethodMatcher.new :some_method
|
||||
matcher.matches?(HMMSpecs)
|
||||
matcher.failure_message.should == [
|
||||
expect(matcher.failure_message).to eq([
|
||||
"Expected HMMSpecs to have method 'some_method'",
|
||||
"but it does not"
|
||||
]
|
||||
])
|
||||
end
|
||||
|
||||
it "provides a failure messoge for #should_not" do
|
||||
matcher = HaveMethodMatcher.new :some_method
|
||||
matcher.matches?(HMMSpecs)
|
||||
matcher.negative_failure_message.should == [
|
||||
expect(matcher.negative_failure_message).to eq([
|
||||
"Expected HMMSpecs NOT to have method 'some_method'",
|
||||
"but it does"
|
||||
]
|
||||
])
|
||||
end
|
||||
end
|
||||
|
|
|
@ -16,42 +16,42 @@ class HPIMMSpecs
|
|||
end
|
||||
end
|
||||
|
||||
describe HavePrivateInstanceMethodMatcher do
|
||||
RSpec.describe HavePrivateInstanceMethodMatcher do
|
||||
it "inherits from MethodMatcher" do
|
||||
HavePrivateInstanceMethodMatcher.new(:m).should be_kind_of(MethodMatcher)
|
||||
expect(HavePrivateInstanceMethodMatcher.new(:m)).to be_kind_of(MethodMatcher)
|
||||
end
|
||||
|
||||
it "matches when mod has the private instance method" do
|
||||
matcher = HavePrivateInstanceMethodMatcher.new :private_method
|
||||
matcher.matches?(HPIMMSpecs).should be_true
|
||||
matcher.matches?(HPIMMSpecs::Subclass).should be_true
|
||||
expect(matcher.matches?(HPIMMSpecs)).to be_truthy
|
||||
expect(matcher.matches?(HPIMMSpecs::Subclass)).to be_truthy
|
||||
end
|
||||
|
||||
it "does not match when mod does not have the private instance method" do
|
||||
matcher = HavePrivateInstanceMethodMatcher.new :another_method
|
||||
matcher.matches?(HPIMMSpecs).should be_false
|
||||
expect(matcher.matches?(HPIMMSpecs)).to be_falsey
|
||||
end
|
||||
|
||||
it "does not match if the method is in a superclass and include_super is false" do
|
||||
matcher = HavePrivateInstanceMethodMatcher.new :private_method, false
|
||||
matcher.matches?(HPIMMSpecs::Subclass).should be_false
|
||||
expect(matcher.matches?(HPIMMSpecs::Subclass)).to be_falsey
|
||||
end
|
||||
|
||||
it "provides a failure message for #should" do
|
||||
matcher = HavePrivateInstanceMethodMatcher.new :some_method
|
||||
matcher.matches?(HPIMMSpecs)
|
||||
matcher.failure_message.should == [
|
||||
expect(matcher.failure_message).to eq([
|
||||
"Expected HPIMMSpecs to have private instance method 'some_method'",
|
||||
"but it does not"
|
||||
]
|
||||
])
|
||||
end
|
||||
|
||||
it "provides a failure message for #should_not" do
|
||||
matcher = HavePrivateInstanceMethodMatcher.new :some_method
|
||||
matcher.matches?(HPIMMSpecs)
|
||||
matcher.negative_failure_message.should == [
|
||||
expect(matcher.negative_failure_message).to eq([
|
||||
"Expected HPIMMSpecs NOT to have private instance method 'some_method'",
|
||||
"but it does"
|
||||
]
|
||||
])
|
||||
end
|
||||
end
|
||||
|
|
|
@ -9,36 +9,36 @@ class HPMMSpecs
|
|||
private_class_method :private_method
|
||||
end
|
||||
|
||||
describe HavePrivateMethodMatcher do
|
||||
RSpec.describe HavePrivateMethodMatcher do
|
||||
it "inherits from MethodMatcher" do
|
||||
HavePrivateMethodMatcher.new(:m).should be_kind_of(MethodMatcher)
|
||||
expect(HavePrivateMethodMatcher.new(:m)).to be_kind_of(MethodMatcher)
|
||||
end
|
||||
|
||||
it "matches when mod has the private method" do
|
||||
matcher = HavePrivateMethodMatcher.new :private_method
|
||||
matcher.matches?(HPMMSpecs).should be_true
|
||||
expect(matcher.matches?(HPMMSpecs)).to be_truthy
|
||||
end
|
||||
|
||||
it "does not match when mod does not have the private method" do
|
||||
matcher = HavePrivateMethodMatcher.new :another_method
|
||||
matcher.matches?(HPMMSpecs).should be_false
|
||||
expect(matcher.matches?(HPMMSpecs)).to be_falsey
|
||||
end
|
||||
|
||||
it "provides a failure message for #should" do
|
||||
matcher = HavePrivateMethodMatcher.new :some_method
|
||||
matcher.matches?(HPMMSpecs)
|
||||
matcher.failure_message.should == [
|
||||
expect(matcher.failure_message).to eq([
|
||||
"Expected HPMMSpecs to have private method 'some_method'",
|
||||
"but it does not"
|
||||
]
|
||||
])
|
||||
end
|
||||
|
||||
it "provides a failure message for #should_not" do
|
||||
matcher = HavePrivateMethodMatcher.new :private_method
|
||||
matcher.matches?(HPMMSpecs)
|
||||
matcher.negative_failure_message.should == [
|
||||
expect(matcher.negative_failure_message).to eq([
|
||||
"Expected HPMMSpecs NOT to have private method 'private_method'",
|
||||
"but it does"
|
||||
]
|
||||
])
|
||||
end
|
||||
end
|
||||
|
|
|
@ -16,42 +16,42 @@ class HPIMMSpecs
|
|||
end
|
||||
end
|
||||
|
||||
describe HaveProtectedInstanceMethodMatcher do
|
||||
RSpec.describe HaveProtectedInstanceMethodMatcher do
|
||||
it "inherits from MethodMatcher" do
|
||||
HaveProtectedInstanceMethodMatcher.new(:m).should be_kind_of(MethodMatcher)
|
||||
expect(HaveProtectedInstanceMethodMatcher.new(:m)).to be_kind_of(MethodMatcher)
|
||||
end
|
||||
|
||||
it "matches when mod has the protected instance method" do
|
||||
matcher = HaveProtectedInstanceMethodMatcher.new :protected_method
|
||||
matcher.matches?(HPIMMSpecs).should be_true
|
||||
matcher.matches?(HPIMMSpecs::Subclass).should be_true
|
||||
expect(matcher.matches?(HPIMMSpecs)).to be_truthy
|
||||
expect(matcher.matches?(HPIMMSpecs::Subclass)).to be_truthy
|
||||
end
|
||||
|
||||
it "does not match when mod does not have the protected instance method" do
|
||||
matcher = HaveProtectedInstanceMethodMatcher.new :another_method
|
||||
matcher.matches?(HPIMMSpecs).should be_false
|
||||
expect(matcher.matches?(HPIMMSpecs)).to be_falsey
|
||||
end
|
||||
|
||||
it "does not match if the method is in a superclass and include_super is false" do
|
||||
matcher = HaveProtectedInstanceMethodMatcher.new :protected_method, false
|
||||
matcher.matches?(HPIMMSpecs::Subclass).should be_false
|
||||
expect(matcher.matches?(HPIMMSpecs::Subclass)).to be_falsey
|
||||
end
|
||||
|
||||
it "provides a failure message for #should" do
|
||||
matcher = HaveProtectedInstanceMethodMatcher.new :some_method
|
||||
matcher.matches?(HPIMMSpecs)
|
||||
matcher.failure_message.should == [
|
||||
expect(matcher.failure_message).to eq([
|
||||
"Expected HPIMMSpecs to have protected instance method 'some_method'",
|
||||
"but it does not"
|
||||
]
|
||||
])
|
||||
end
|
||||
|
||||
it "provides a failure messoge for #should_not" do
|
||||
matcher = HaveProtectedInstanceMethodMatcher.new :some_method
|
||||
matcher.matches?(HPIMMSpecs)
|
||||
matcher.negative_failure_message.should == [
|
||||
expect(matcher.negative_failure_message).to eq([
|
||||
"Expected HPIMMSpecs NOT to have protected instance method 'some_method'",
|
||||
"but it does"
|
||||
]
|
||||
])
|
||||
end
|
||||
end
|
||||
|
|
|
@ -12,42 +12,42 @@ class HPIMMSpecs
|
|||
end
|
||||
end
|
||||
|
||||
describe HavePublicInstanceMethodMatcher do
|
||||
RSpec.describe HavePublicInstanceMethodMatcher do
|
||||
it "inherits from MethodMatcher" do
|
||||
HavePublicInstanceMethodMatcher.new(:m).should be_kind_of(MethodMatcher)
|
||||
expect(HavePublicInstanceMethodMatcher.new(:m)).to be_kind_of(MethodMatcher)
|
||||
end
|
||||
|
||||
it "matches when mod has the public instance method" do
|
||||
matcher = HavePublicInstanceMethodMatcher.new :public_method
|
||||
matcher.matches?(HPIMMSpecs).should be_true
|
||||
matcher.matches?(HPIMMSpecs::Subclass).should be_true
|
||||
expect(matcher.matches?(HPIMMSpecs)).to be_truthy
|
||||
expect(matcher.matches?(HPIMMSpecs::Subclass)).to be_truthy
|
||||
end
|
||||
|
||||
it "does not match when mod does not have the public instance method" do
|
||||
matcher = HavePublicInstanceMethodMatcher.new :another_method
|
||||
matcher.matches?(HPIMMSpecs).should be_false
|
||||
expect(matcher.matches?(HPIMMSpecs)).to be_falsey
|
||||
end
|
||||
|
||||
it "does not match if the method is in a superclass and include_super is false" do
|
||||
matcher = HavePublicInstanceMethodMatcher.new :public_method, false
|
||||
matcher.matches?(HPIMMSpecs::Subclass).should be_false
|
||||
expect(matcher.matches?(HPIMMSpecs::Subclass)).to be_falsey
|
||||
end
|
||||
|
||||
it "provides a failure message for #should" do
|
||||
matcher = HavePublicInstanceMethodMatcher.new :some_method
|
||||
matcher.matches?(HPIMMSpecs)
|
||||
matcher.failure_message.should == [
|
||||
expect(matcher.failure_message).to eq([
|
||||
"Expected HPIMMSpecs to have public instance method 'some_method'",
|
||||
"but it does not"
|
||||
]
|
||||
])
|
||||
end
|
||||
|
||||
it "provides a failure messoge for #should_not" do
|
||||
matcher = HavePublicInstanceMethodMatcher.new :some_method
|
||||
matcher.matches?(HPIMMSpecs)
|
||||
matcher.negative_failure_message.should == [
|
||||
expect(matcher.negative_failure_message).to eq([
|
||||
"Expected HPIMMSpecs NOT to have public instance method 'some_method'",
|
||||
"but it does"
|
||||
]
|
||||
])
|
||||
end
|
||||
end
|
||||
|
|
|
@ -7,14 +7,14 @@ class HSMMSpecs
|
|||
end
|
||||
end
|
||||
|
||||
describe HaveSingletonMethodMatcher do
|
||||
RSpec.describe HaveSingletonMethodMatcher do
|
||||
it "inherits from MethodMatcher" do
|
||||
HaveSingletonMethodMatcher.new(:m).should be_kind_of(MethodMatcher)
|
||||
expect(HaveSingletonMethodMatcher.new(:m)).to be_kind_of(MethodMatcher)
|
||||
end
|
||||
|
||||
it "matches when the class has a singleton method" do
|
||||
matcher = HaveSingletonMethodMatcher.new :singleton_method
|
||||
matcher.matches?(HSMMSpecs).should be_true
|
||||
expect(matcher.matches?(HSMMSpecs)).to be_truthy
|
||||
end
|
||||
|
||||
it "matches when the object has a singleton method" do
|
||||
|
@ -22,24 +22,24 @@ describe HaveSingletonMethodMatcher do
|
|||
def obj.singleton_method; end
|
||||
|
||||
matcher = HaveSingletonMethodMatcher.new :singleton_method
|
||||
matcher.matches?(obj).should be_true
|
||||
expect(matcher.matches?(obj)).to be_truthy
|
||||
end
|
||||
|
||||
it "provides a failure message for #should" do
|
||||
matcher = HaveSingletonMethodMatcher.new :some_method
|
||||
matcher.matches?(HSMMSpecs)
|
||||
matcher.failure_message.should == [
|
||||
expect(matcher.failure_message).to eq([
|
||||
"Expected HSMMSpecs to have singleton method 'some_method'",
|
||||
"but it does not"
|
||||
]
|
||||
])
|
||||
end
|
||||
|
||||
it "provides a failure message for #should_not" do
|
||||
matcher = HaveSingletonMethodMatcher.new :singleton_method
|
||||
matcher.matches?(HSMMSpecs)
|
||||
matcher.negative_failure_message.should == [
|
||||
expect(matcher.negative_failure_message).to eq([
|
||||
"Expected HSMMSpecs NOT to have singleton method 'singleton_method'",
|
||||
"but it does"
|
||||
]
|
||||
])
|
||||
end
|
||||
end
|
||||
|
|
|
@ -2,41 +2,41 @@ require 'spec_helper'
|
|||
require 'mspec/expectations/expectations'
|
||||
require 'mspec/matchers'
|
||||
|
||||
describe IncludeAnyOfMatcher do
|
||||
RSpec.describe IncludeAnyOfMatcher do
|
||||
it "matches when actual includes expected" do
|
||||
IncludeAnyOfMatcher.new(2).matches?([1,2,3]).should == true
|
||||
IncludeAnyOfMatcher.new("b").matches?("abc").should == true
|
||||
expect(IncludeAnyOfMatcher.new(2).matches?([1,2,3])).to eq(true)
|
||||
expect(IncludeAnyOfMatcher.new("b").matches?("abc")).to eq(true)
|
||||
end
|
||||
|
||||
it "does not match when actual does not include expected" do
|
||||
IncludeAnyOfMatcher.new(4).matches?([1,2,3]).should == false
|
||||
IncludeAnyOfMatcher.new("d").matches?("abc").should == false
|
||||
expect(IncludeAnyOfMatcher.new(4).matches?([1,2,3])).to eq(false)
|
||||
expect(IncludeAnyOfMatcher.new("d").matches?("abc")).to eq(false)
|
||||
end
|
||||
|
||||
it "matches when actual includes all expected" do
|
||||
IncludeAnyOfMatcher.new(3, 2, 1).matches?([1,2,3]).should == true
|
||||
IncludeAnyOfMatcher.new("a", "b", "c").matches?("abc").should == true
|
||||
expect(IncludeAnyOfMatcher.new(3, 2, 1).matches?([1,2,3])).to eq(true)
|
||||
expect(IncludeAnyOfMatcher.new("a", "b", "c").matches?("abc")).to eq(true)
|
||||
end
|
||||
|
||||
it "matches when actual includes any expected" do
|
||||
IncludeAnyOfMatcher.new(3, 4, 5).matches?([1,2,3]).should == true
|
||||
IncludeAnyOfMatcher.new("c", "d", "e").matches?("abc").should == true
|
||||
expect(IncludeAnyOfMatcher.new(3, 4, 5).matches?([1,2,3])).to eq(true)
|
||||
expect(IncludeAnyOfMatcher.new("c", "d", "e").matches?("abc")).to eq(true)
|
||||
end
|
||||
|
||||
it "does not match when actual does not include any expected" do
|
||||
IncludeAnyOfMatcher.new(4, 5).matches?([1,2,3]).should == false
|
||||
IncludeAnyOfMatcher.new("de").matches?("abc").should == false
|
||||
expect(IncludeAnyOfMatcher.new(4, 5).matches?([1,2,3])).to eq(false)
|
||||
expect(IncludeAnyOfMatcher.new("de").matches?("abc")).to eq(false)
|
||||
end
|
||||
|
||||
it "provides a useful failure message" do
|
||||
matcher = IncludeAnyOfMatcher.new(5, 6)
|
||||
matcher.matches?([1,2,3])
|
||||
matcher.failure_message.should == ["Expected [1, 2, 3]", "to include any of [5, 6]"]
|
||||
expect(matcher.failure_message).to eq(["Expected [1, 2, 3]", "to include any of [5, 6]"])
|
||||
end
|
||||
|
||||
it "provides a useful negative failure message" do
|
||||
matcher = IncludeAnyOfMatcher.new(1, 2, 3)
|
||||
matcher.matches?([1,2])
|
||||
matcher.negative_failure_message.should == ["Expected [1, 2]", "not to include any of [1, 2, 3]"]
|
||||
expect(matcher.negative_failure_message).to eq(["Expected [1, 2]", "not to include any of [1, 2, 3]"])
|
||||
end
|
||||
end
|
||||
|
|
|
@ -2,36 +2,36 @@ require 'spec_helper'
|
|||
require 'mspec/expectations/expectations'
|
||||
require 'mspec/matchers'
|
||||
|
||||
describe IncludeMatcher do
|
||||
RSpec.describe IncludeMatcher do
|
||||
it "matches when actual includes expected" do
|
||||
IncludeMatcher.new(2).matches?([1,2,3]).should == true
|
||||
IncludeMatcher.new("b").matches?("abc").should == true
|
||||
expect(IncludeMatcher.new(2).matches?([1,2,3])).to eq(true)
|
||||
expect(IncludeMatcher.new("b").matches?("abc")).to eq(true)
|
||||
end
|
||||
|
||||
it "does not match when actual does not include expected" do
|
||||
IncludeMatcher.new(4).matches?([1,2,3]).should == false
|
||||
IncludeMatcher.new("d").matches?("abc").should == false
|
||||
expect(IncludeMatcher.new(4).matches?([1,2,3])).to eq(false)
|
||||
expect(IncludeMatcher.new("d").matches?("abc")).to eq(false)
|
||||
end
|
||||
|
||||
it "matches when actual includes all expected" do
|
||||
IncludeMatcher.new(3, 2, 1).matches?([1,2,3]).should == true
|
||||
IncludeMatcher.new("a", "b", "c").matches?("abc").should == true
|
||||
expect(IncludeMatcher.new(3, 2, 1).matches?([1,2,3])).to eq(true)
|
||||
expect(IncludeMatcher.new("a", "b", "c").matches?("abc")).to eq(true)
|
||||
end
|
||||
|
||||
it "does not match when actual does not include all expected" do
|
||||
IncludeMatcher.new(3, 2, 4).matches?([1,2,3]).should == false
|
||||
IncludeMatcher.new("a", "b", "c", "d").matches?("abc").should == false
|
||||
expect(IncludeMatcher.new(3, 2, 4).matches?([1,2,3])).to eq(false)
|
||||
expect(IncludeMatcher.new("a", "b", "c", "d").matches?("abc")).to eq(false)
|
||||
end
|
||||
|
||||
it "provides a useful failure message" do
|
||||
matcher = IncludeMatcher.new(5, 2)
|
||||
matcher.matches?([1,2,3])
|
||||
matcher.failure_message.should == ["Expected [1, 2, 3]", "to include 5"]
|
||||
expect(matcher.failure_message).to eq(["Expected [1, 2, 3]", "to include 5"])
|
||||
end
|
||||
|
||||
it "provides a useful negative failure message" do
|
||||
matcher = IncludeMatcher.new(1, 2, 3)
|
||||
matcher.matches?([1,2,3])
|
||||
matcher.negative_failure_message.should == ["Expected [1, 2, 3]", "not to include 3"]
|
||||
expect(matcher.negative_failure_message).to eq(["Expected [1, 2, 3]", "not to include 3"])
|
||||
end
|
||||
end
|
||||
|
|
|
@ -4,31 +4,31 @@ require 'mspec/guards'
|
|||
require 'mspec/helpers'
|
||||
require 'mspec/matchers'
|
||||
|
||||
describe InfinityMatcher do
|
||||
RSpec.describe InfinityMatcher do
|
||||
it "matches when actual is infinite and has the correct sign" do
|
||||
InfinityMatcher.new(1).matches?(infinity_value).should == true
|
||||
InfinityMatcher.new(-1).matches?(-infinity_value).should == true
|
||||
expect(InfinityMatcher.new(1).matches?(infinity_value)).to eq(true)
|
||||
expect(InfinityMatcher.new(-1).matches?(-infinity_value)).to eq(true)
|
||||
end
|
||||
|
||||
it "does not match when actual is not infinite" do
|
||||
InfinityMatcher.new(1).matches?(1.0).should == false
|
||||
InfinityMatcher.new(-1).matches?(-1.0).should == false
|
||||
expect(InfinityMatcher.new(1).matches?(1.0)).to eq(false)
|
||||
expect(InfinityMatcher.new(-1).matches?(-1.0)).to eq(false)
|
||||
end
|
||||
|
||||
it "does not match when actual is infinite but has the incorrect sign" do
|
||||
InfinityMatcher.new(1).matches?(-infinity_value).should == false
|
||||
InfinityMatcher.new(-1).matches?(infinity_value).should == false
|
||||
expect(InfinityMatcher.new(1).matches?(-infinity_value)).to eq(false)
|
||||
expect(InfinityMatcher.new(-1).matches?(infinity_value)).to eq(false)
|
||||
end
|
||||
|
||||
it "provides a useful failure message" do
|
||||
matcher = InfinityMatcher.new(-1)
|
||||
matcher.matches?(0)
|
||||
matcher.failure_message.should == ["Expected 0", "to be -Infinity"]
|
||||
expect(matcher.failure_message).to eq(["Expected 0", "to be -Infinity"])
|
||||
end
|
||||
|
||||
it "provides a useful negative failure message" do
|
||||
matcher = InfinityMatcher.new(1)
|
||||
matcher.matches?(infinity_value)
|
||||
matcher.negative_failure_message.should == ["Expected Infinity", "not to be Infinity"]
|
||||
expect(matcher.negative_failure_message).to eq(["Expected Infinity", "not to be Infinity"])
|
||||
end
|
||||
end
|
||||
|
|
|
@ -2,38 +2,38 @@ require 'spec_helper'
|
|||
require 'mspec/expectations/expectations'
|
||||
require 'mspec/matchers'
|
||||
|
||||
describe MatchYAMLMatcher do
|
||||
RSpec.describe MatchYAMLMatcher do
|
||||
before :each do
|
||||
@matcher = MatchYAMLMatcher.new("--- \nfoo: bar\n")
|
||||
end
|
||||
|
||||
it "compares YAML documents and matches if they're equivalent" do
|
||||
@matcher.matches?("--- \nfoo: bar\n").should == true
|
||||
expect(@matcher.matches?("--- \nfoo: bar\n")).to eq(true)
|
||||
end
|
||||
|
||||
it "compares YAML documents and does not match if they're not equivalent" do
|
||||
@matcher.matches?("--- \nbar: foo\n").should == false
|
||||
@matcher.matches?("--- \nfoo: \nbar\n").should == false
|
||||
expect(@matcher.matches?("--- \nbar: foo\n")).to eq(false)
|
||||
expect(@matcher.matches?("--- \nfoo: \nbar\n")).to eq(false)
|
||||
end
|
||||
|
||||
it "also receives objects that respond_to to_yaml" do
|
||||
matcher = MatchYAMLMatcher.new("some string")
|
||||
matcher.matches?("some string").should == true
|
||||
expect(matcher.matches?("some string")).to eq(true)
|
||||
|
||||
matcher = MatchYAMLMatcher.new(['a', 'b'])
|
||||
matcher.matches?("--- \n- a\n- b\n").should == true
|
||||
expect(matcher.matches?("--- \n- a\n- b\n")).to eq(true)
|
||||
|
||||
matcher = MatchYAMLMatcher.new("foo" => "bar")
|
||||
matcher.matches?("--- \nfoo: bar\n").should == true
|
||||
expect(matcher.matches?("--- \nfoo: bar\n")).to eq(true)
|
||||
end
|
||||
|
||||
it "matches documents with trailing whitespace" do
|
||||
@matcher.matches?("--- \nfoo: bar \n").should == true
|
||||
@matcher.matches?("--- \nfoo: bar \n").should == true
|
||||
expect(@matcher.matches?("--- \nfoo: bar \n")).to eq(true)
|
||||
expect(@matcher.matches?("--- \nfoo: bar \n")).to eq(true)
|
||||
end
|
||||
|
||||
it "fails with a descriptive error message" do
|
||||
@matcher.matches?("foo").should == false
|
||||
@matcher.failure_message.should == ["Expected \"foo\"", " to match \"--- \\nfoo: bar\\n\""]
|
||||
expect(@matcher.matches?("foo")).to eq(false)
|
||||
expect(@matcher.failure_message).to eq(["Expected \"foo\"", " to match \"--- \\nfoo: bar\\n\""])
|
||||
end
|
||||
end
|
||||
|
|
|
@ -2,73 +2,83 @@ require 'spec_helper'
|
|||
require 'mspec/expectations/expectations'
|
||||
require 'mspec/matchers'
|
||||
|
||||
describe OutputMatcher do
|
||||
RSpec.describe OutputMatcher do
|
||||
it "matches when executing the proc results in the expected output to $stdout" do
|
||||
proc = Proc.new { puts "bang!" }
|
||||
OutputMatcher.new("bang!\n", nil).matches?(proc).should == true
|
||||
OutputMatcher.new("pop", nil).matches?(proc).should == false
|
||||
OutputMatcher.new(/bang/, nil).matches?(proc).should == true
|
||||
OutputMatcher.new(/po/, nil).matches?(proc).should == false
|
||||
expect(OutputMatcher.new("bang!\n", nil).matches?(proc)).to eq(true)
|
||||
expect(OutputMatcher.new("pop", nil).matches?(proc)).to eq(false)
|
||||
expect(OutputMatcher.new(/bang/, nil).matches?(proc)).to eq(true)
|
||||
expect(OutputMatcher.new(/po/, nil).matches?(proc)).to eq(false)
|
||||
end
|
||||
|
||||
it "matches when executing the proc results in the expected output to $stderr" do
|
||||
proc = Proc.new { $stderr.write "boom!" }
|
||||
OutputMatcher.new(nil, "boom!").matches?(proc).should == true
|
||||
OutputMatcher.new(nil, "fizzle").matches?(proc).should == false
|
||||
OutputMatcher.new(nil, /boom/).matches?(proc).should == true
|
||||
OutputMatcher.new(nil, /fizzl/).matches?(proc).should == false
|
||||
expect(OutputMatcher.new(nil, "boom!").matches?(proc)).to eq(true)
|
||||
expect(OutputMatcher.new(nil, "fizzle").matches?(proc)).to eq(false)
|
||||
expect(OutputMatcher.new(nil, /boom/).matches?(proc)).to eq(true)
|
||||
expect(OutputMatcher.new(nil, /fizzl/).matches?(proc)).to eq(false)
|
||||
end
|
||||
|
||||
it "provides a useful failure message" do
|
||||
proc = Proc.new { print "unexpected"; $stderr.print "unerror" }
|
||||
matcher = OutputMatcher.new("expected", "error")
|
||||
matcher.matches?(proc)
|
||||
matcher.failure_message.should ==
|
||||
expect(matcher.failure_message).to eq(
|
||||
["Expected:\n $stdout: \"expected\"\n $stderr: \"error\"\n",
|
||||
" got:\n $stdout: \"unexpected\"\n $stderr: \"unerror\"\n"]
|
||||
)
|
||||
matcher = OutputMatcher.new("expected", nil)
|
||||
matcher.matches?(proc)
|
||||
matcher.failure_message.should ==
|
||||
expect(matcher.failure_message).to eq(
|
||||
["Expected:\n $stdout: \"expected\"\n",
|
||||
" got:\n $stdout: \"unexpected\"\n"]
|
||||
)
|
||||
matcher = OutputMatcher.new(nil, "error")
|
||||
matcher.matches?(proc)
|
||||
matcher.failure_message.should ==
|
||||
expect(matcher.failure_message).to eq(
|
||||
["Expected:\n $stderr: \"error\"\n",
|
||||
" got:\n $stderr: \"unerror\"\n"]
|
||||
)
|
||||
matcher = OutputMatcher.new(/base/, nil)
|
||||
matcher.matches?(proc)
|
||||
matcher.failure_message.should ==
|
||||
expect(matcher.failure_message).to eq(
|
||||
["Expected:\n $stdout: /base/\n",
|
||||
" got:\n $stdout: \"unexpected\"\n"]
|
||||
)
|
||||
matcher = OutputMatcher.new(nil, /octave/)
|
||||
matcher.matches?(proc)
|
||||
matcher.failure_message.should ==
|
||||
expect(matcher.failure_message).to eq(
|
||||
["Expected:\n $stderr: /octave/\n",
|
||||
" got:\n $stderr: \"unerror\"\n"]
|
||||
)
|
||||
end
|
||||
|
||||
it "provides a useful negative failure message" do
|
||||
proc = Proc.new { puts "expected"; $stderr.puts "error" }
|
||||
matcher = OutputMatcher.new("expected", "error")
|
||||
matcher.matches?(proc)
|
||||
matcher.negative_failure_message.should ==
|
||||
expect(matcher.negative_failure_message).to eq(
|
||||
["Expected output not to be:\n", " $stdout: \"expected\"\n $stderr: \"error\"\n"]
|
||||
)
|
||||
matcher = OutputMatcher.new("expected", nil)
|
||||
matcher.matches?(proc)
|
||||
matcher.negative_failure_message.should ==
|
||||
expect(matcher.negative_failure_message).to eq(
|
||||
["Expected output not to be:\n", " $stdout: \"expected\"\n"]
|
||||
)
|
||||
matcher = OutputMatcher.new(nil, "error")
|
||||
matcher.matches?(proc)
|
||||
matcher.negative_failure_message.should ==
|
||||
expect(matcher.negative_failure_message).to eq(
|
||||
["Expected output not to be:\n", " $stderr: \"error\"\n"]
|
||||
)
|
||||
matcher = OutputMatcher.new(/expect/, nil)
|
||||
matcher.matches?(proc)
|
||||
matcher.negative_failure_message.should ==
|
||||
expect(matcher.negative_failure_message).to eq(
|
||||
["Expected output not to be:\n", " $stdout: \"expected\"\n"]
|
||||
)
|
||||
matcher = OutputMatcher.new(nil, /err/)
|
||||
matcher.matches?(proc)
|
||||
matcher.negative_failure_message.should ==
|
||||
expect(matcher.negative_failure_message).to eq(
|
||||
["Expected output not to be:\n", " $stderr: \"error\"\n"]
|
||||
)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -2,43 +2,43 @@ require 'spec_helper'
|
|||
require 'mspec/expectations/expectations'
|
||||
require 'mspec/matchers'
|
||||
|
||||
describe OutputToFDMatcher do
|
||||
RSpec.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
|
||||
OutputToFDMatcher.new("Hi\n", STDERR).matches?(lambda { $stderr.print "Hi\n" }).should == true
|
||||
expect(OutputToFDMatcher.new("Hi\n", STDERR).matches?(lambda { $stderr.print "Hi\n" })).to eq(true)
|
||||
end
|
||||
|
||||
it "does not match if running the block does not produce the expected output to the FD" do
|
||||
OutputToFDMatcher.new("Hi\n", STDERR).matches?(lambda { $stderr.puts("Hello\n") }).should == false
|
||||
expect(OutputToFDMatcher.new("Hi\n", STDERR).matches?(lambda { $stderr.puts("Hello\n") })).to eq(false)
|
||||
end
|
||||
|
||||
it "propagate the exception if one is thrown while matching" do
|
||||
exc = RuntimeError.new("propagates")
|
||||
lambda {
|
||||
OutputToFDMatcher.new("Hi\n", STDERR).matches?(lambda {
|
||||
expect {
|
||||
expect(OutputToFDMatcher.new("Hi\n", STDERR).matches?(lambda {
|
||||
raise exc
|
||||
}).should == false
|
||||
}.should raise_error(exc)
|
||||
})).to eq(false)
|
||||
}.to raise_error(exc)
|
||||
end
|
||||
|
||||
it "defaults to matching against STDOUT" do
|
||||
object = Object.new
|
||||
object.extend MSpecMatchers
|
||||
object.send(:output_to_fd, "Hi\n").matches?(lambda { $stdout.print "Hi\n" }).should == true
|
||||
expect(object.send(:output_to_fd, "Hi\n").matches?(lambda { $stdout.print "Hi\n" })).to eq(true)
|
||||
end
|
||||
|
||||
it "accepts any IO instance" do
|
||||
io = IO.new STDOUT.fileno
|
||||
OutputToFDMatcher.new("Hi\n", io).matches?(lambda { io.print "Hi\n" }).should == true
|
||||
expect(OutputToFDMatcher.new("Hi\n", io).matches?(lambda { io.print "Hi\n" })).to eq(true)
|
||||
end
|
||||
|
||||
it "allows matching with a Regexp" do
|
||||
s = "Hi there\n"
|
||||
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
|
||||
expect(OutputToFDMatcher.new(/Hi/, STDERR).matches?(lambda { $stderr.print s })).to eq(true)
|
||||
expect(OutputToFDMatcher.new(/Hi?/, STDERR).matches?(lambda { $stderr.print s })).to eq(true)
|
||||
expect(OutputToFDMatcher.new(/[hH]i?/, STDERR).matches?(lambda { $stderr.print s })).to eq(true)
|
||||
expect(OutputToFDMatcher.new(/.*/, STDERR).matches?(lambda { $stderr.print s })).to eq(true)
|
||||
expect(OutputToFDMatcher.new(/H.*?here/, STDERR).matches?(lambda { $stderr.print s })).to eq(true)
|
||||
expect(OutputToFDMatcher.new(/Ahoy/, STDERR).matches?(lambda { $stderr.print s })).to eq(false)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,79 +1,94 @@
|
|||
require 'spec_helper'
|
||||
require 'mspec/expectations/expectations'
|
||||
require 'mspec/matchers'
|
||||
|
||||
class ExpectedException < Exception; end
|
||||
class UnexpectedException < Exception; end
|
||||
|
||||
describe RaiseErrorMatcher do
|
||||
RSpec.describe RaiseErrorMatcher do
|
||||
before :each do
|
||||
state = double("run state").as_null_object
|
||||
allow(MSpec).to receive(:current).and_return(state)
|
||||
end
|
||||
|
||||
it "matches when the proc raises the expected exception" do
|
||||
proc = Proc.new { raise ExpectedException }
|
||||
matcher = RaiseErrorMatcher.new(ExpectedException, nil)
|
||||
matcher.matches?(proc).should == true
|
||||
expect(matcher.matches?(proc)).to eq(true)
|
||||
end
|
||||
|
||||
it "executes its optional block if matched" do
|
||||
run = false
|
||||
proc = Proc.new { raise ExpectedException }
|
||||
matcher = RaiseErrorMatcher.new(ExpectedException, nil) { |error|
|
||||
run = true
|
||||
error.class.should == ExpectedException
|
||||
}
|
||||
it "executes its optional {/} block if matched" do
|
||||
ensure_mspec_method(-> {}.method(:should))
|
||||
|
||||
matcher.matches?(proc).should == true
|
||||
run.should == true
|
||||
run = false
|
||||
-> { raise ExpectedException }.should PublicMSpecMatchers.raise_error { |error|
|
||||
expect(error.class).to eq(ExpectedException)
|
||||
run = true
|
||||
}
|
||||
expect(run).to eq(true)
|
||||
end
|
||||
|
||||
it "executes its optional do/end block if matched" do
|
||||
ensure_mspec_method(-> {}.method(:should))
|
||||
|
||||
run = false
|
||||
-> { raise ExpectedException }.should PublicMSpecMatchers.raise_error do |error|
|
||||
expect(error.class).to eq(ExpectedException)
|
||||
run = true
|
||||
end
|
||||
expect(run).to eq(true)
|
||||
end
|
||||
|
||||
it "matches when the proc raises the expected exception with the expected message" do
|
||||
proc = Proc.new { raise ExpectedException, "message" }
|
||||
matcher = RaiseErrorMatcher.new(ExpectedException, "message")
|
||||
matcher.matches?(proc).should == true
|
||||
expect(matcher.matches?(proc)).to eq(true)
|
||||
end
|
||||
|
||||
it "matches when the proc raises the expected exception with a matching message" do
|
||||
proc = Proc.new { raise ExpectedException, "some message" }
|
||||
matcher = RaiseErrorMatcher.new(ExpectedException, /some/)
|
||||
matcher.matches?(proc).should == true
|
||||
expect(matcher.matches?(proc)).to eq(true)
|
||||
end
|
||||
|
||||
it "does not match when the proc does not raise the expected exception" do
|
||||
exc = UnexpectedException.new
|
||||
matcher = RaiseErrorMatcher.new(ExpectedException, nil)
|
||||
|
||||
matcher.matching_exception?(exc).should == false
|
||||
lambda {
|
||||
expect(matcher.matching_exception?(exc)).to eq(false)
|
||||
expect {
|
||||
matcher.matches?(Proc.new { raise exc })
|
||||
}.should raise_error(UnexpectedException)
|
||||
}.to raise_error(UnexpectedException)
|
||||
end
|
||||
|
||||
it "does not match when the proc raises the expected exception with an unexpected message" do
|
||||
exc = ExpectedException.new("unexpected")
|
||||
matcher = RaiseErrorMatcher.new(ExpectedException, "expected")
|
||||
|
||||
matcher.matching_exception?(exc).should == false
|
||||
lambda {
|
||||
expect(matcher.matching_exception?(exc)).to eq(false)
|
||||
expect {
|
||||
matcher.matches?(Proc.new { raise exc })
|
||||
}.should raise_error(ExpectedException)
|
||||
}.to raise_error(ExpectedException)
|
||||
end
|
||||
|
||||
it "does not match when the proc does not raise an exception" do
|
||||
proc = Proc.new {}
|
||||
matcher = RaiseErrorMatcher.new(ExpectedException, "expected")
|
||||
matcher.matches?(proc).should == false
|
||||
expect(matcher.matches?(proc)).to eq(false)
|
||||
end
|
||||
|
||||
it "provides a useful failure message when the exception class differs" do
|
||||
exc = UnexpectedException.new("message")
|
||||
matcher = RaiseErrorMatcher.new(ExpectedException, "message")
|
||||
|
||||
matcher.matching_exception?(exc).should == false
|
||||
expect(matcher.matching_exception?(exc)).to eq(false)
|
||||
begin
|
||||
matcher.matches?(Proc.new { raise exc })
|
||||
rescue UnexpectedException => e
|
||||
matcher.failure_message.should ==
|
||||
expect(matcher.failure_message).to eq(
|
||||
["Expected ExpectedException (message)", "but got: UnexpectedException (message)"]
|
||||
ExceptionState.new(nil, nil, e).message.should ==
|
||||
)
|
||||
expect(ExceptionState.new(nil, nil, e).message).to eq(
|
||||
"Expected ExpectedException (message)\nbut got: UnexpectedException (message)"
|
||||
)
|
||||
else
|
||||
raise "no exception"
|
||||
end
|
||||
|
@ -83,14 +98,16 @@ describe RaiseErrorMatcher do
|
|||
exc = ExpectedException.new("unexpected")
|
||||
matcher = RaiseErrorMatcher.new(ExpectedException, "expected")
|
||||
|
||||
matcher.matching_exception?(exc).should == false
|
||||
expect(matcher.matching_exception?(exc)).to eq(false)
|
||||
begin
|
||||
matcher.matches?(Proc.new { raise exc })
|
||||
rescue ExpectedException => e
|
||||
matcher.failure_message.should ==
|
||||
expect(matcher.failure_message).to eq(
|
||||
["Expected ExpectedException (expected)", "but got: ExpectedException (unexpected)"]
|
||||
ExceptionState.new(nil, nil, e).message.should ==
|
||||
)
|
||||
expect(ExceptionState.new(nil, nil, e).message).to eq(
|
||||
"Expected ExpectedException (expected)\nbut got: ExpectedException (unexpected)"
|
||||
)
|
||||
else
|
||||
raise "no exception"
|
||||
end
|
||||
|
@ -100,14 +117,16 @@ describe RaiseErrorMatcher do
|
|||
exc = UnexpectedException.new("unexpected")
|
||||
matcher = RaiseErrorMatcher.new(ExpectedException, "expected")
|
||||
|
||||
matcher.matching_exception?(exc).should == false
|
||||
expect(matcher.matching_exception?(exc)).to eq(false)
|
||||
begin
|
||||
matcher.matches?(Proc.new { raise exc })
|
||||
rescue UnexpectedException => e
|
||||
matcher.failure_message.should ==
|
||||
expect(matcher.failure_message).to eq(
|
||||
["Expected ExpectedException (expected)", "but got: UnexpectedException (unexpected)"]
|
||||
ExceptionState.new(nil, nil, e).message.should ==
|
||||
)
|
||||
expect(ExceptionState.new(nil, nil, e).message).to eq(
|
||||
"Expected ExpectedException (expected)\nbut got: UnexpectedException (unexpected)"
|
||||
)
|
||||
else
|
||||
raise "no exception"
|
||||
end
|
||||
|
@ -117,16 +136,18 @@ describe RaiseErrorMatcher do
|
|||
proc = Proc.new { 120 }
|
||||
matcher = RaiseErrorMatcher.new(ExpectedException, "expected")
|
||||
matcher.matches?(proc)
|
||||
matcher.failure_message.should ==
|
||||
expect(matcher.failure_message).to eq(
|
||||
["Expected ExpectedException (expected)", "but no exception was raised (120 was returned)"]
|
||||
)
|
||||
end
|
||||
|
||||
it "provides a useful failure message when no exception is raised and nil is returned" do
|
||||
proc = Proc.new { nil }
|
||||
matcher = RaiseErrorMatcher.new(ExpectedException, "expected")
|
||||
matcher.matches?(proc)
|
||||
matcher.failure_message.should ==
|
||||
expect(matcher.failure_message).to eq(
|
||||
["Expected ExpectedException (expected)", "but no exception was raised (nil was returned)"]
|
||||
)
|
||||
end
|
||||
|
||||
it "provides a useful failure message when no exception is raised and the result raises in #pretty_inspect" do
|
||||
|
@ -137,23 +158,26 @@ describe RaiseErrorMatcher do
|
|||
proc = Proc.new { result }
|
||||
matcher = RaiseErrorMatcher.new(ExpectedException, "expected")
|
||||
matcher.matches?(proc)
|
||||
matcher.failure_message.should ==
|
||||
expect(matcher.failure_message).to eq(
|
||||
["Expected ExpectedException (expected)", "but no exception was raised (#<Object>(#pretty_inspect raised #<ArgumentError: bad>) was returned)"]
|
||||
)
|
||||
end
|
||||
|
||||
it "provides a useful negative failure message" do
|
||||
proc = Proc.new { raise ExpectedException, "expected" }
|
||||
matcher = RaiseErrorMatcher.new(ExpectedException, "expected")
|
||||
matcher.matches?(proc)
|
||||
matcher.negative_failure_message.should ==
|
||||
expect(matcher.negative_failure_message).to eq(
|
||||
["Expected to not get ExpectedException (expected)", ""]
|
||||
)
|
||||
end
|
||||
|
||||
it "provides a useful negative failure message for strict subclasses of the matched exception class" do
|
||||
proc = Proc.new { raise UnexpectedException, "unexpected" }
|
||||
matcher = RaiseErrorMatcher.new(Exception, nil)
|
||||
matcher.matches?(proc)
|
||||
matcher.negative_failure_message.should ==
|
||||
expect(matcher.negative_failure_message).to eq(
|
||||
["Expected to not get Exception", "but got: UnexpectedException (unexpected)"]
|
||||
)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -2,32 +2,32 @@ require 'spec_helper'
|
|||
require 'mspec/expectations/expectations'
|
||||
require 'mspec/matchers'
|
||||
|
||||
describe RespondToMatcher do
|
||||
RSpec.describe RespondToMatcher do
|
||||
it "matches when actual does respond_to? expected" do
|
||||
RespondToMatcher.new(:to_s).matches?(Object.new).should == true
|
||||
RespondToMatcher.new(:inject).matches?([]).should == true
|
||||
RespondToMatcher.new(:[]).matches?(1).should == true
|
||||
RespondToMatcher.new(:[]=).matches?("string").should == true
|
||||
expect(RespondToMatcher.new(:to_s).matches?(Object.new)).to eq(true)
|
||||
expect(RespondToMatcher.new(:inject).matches?([])).to eq(true)
|
||||
expect(RespondToMatcher.new(:[]).matches?(1)).to eq(true)
|
||||
expect(RespondToMatcher.new(:[]=).matches?("string")).to eq(true)
|
||||
end
|
||||
|
||||
it "does not match when actual does not respond_to? expected" do
|
||||
RespondToMatcher.new(:to_i).matches?(Object.new).should == false
|
||||
RespondToMatcher.new(:inject).matches?(1).should == false
|
||||
RespondToMatcher.new(:non_existent_method).matches?([]).should == false
|
||||
RespondToMatcher.new(:[]=).matches?(1).should == false
|
||||
expect(RespondToMatcher.new(:to_i).matches?(Object.new)).to eq(false)
|
||||
expect(RespondToMatcher.new(:inject).matches?(1)).to eq(false)
|
||||
expect(RespondToMatcher.new(:non_existent_method).matches?([])).to eq(false)
|
||||
expect(RespondToMatcher.new(:[]=).matches?(1)).to eq(false)
|
||||
end
|
||||
|
||||
it "provides a useful failure message" do
|
||||
matcher = RespondToMatcher.new(:non_existent_method)
|
||||
matcher.matches?('string')
|
||||
matcher.failure_message.should == [
|
||||
"Expected \"string\" (String)", "to respond to non_existent_method"]
|
||||
expect(matcher.failure_message).to eq([
|
||||
"Expected \"string\" (String)", "to respond to non_existent_method"])
|
||||
end
|
||||
|
||||
it "provides a useful negative failure message" do
|
||||
matcher = RespondToMatcher.new(:to_i)
|
||||
matcher.matches?(4.0)
|
||||
matcher.negative_failure_message.should == [
|
||||
"Expected 4.0 (Float)", "not to respond to to_i"]
|
||||
expect(matcher.negative_failure_message).to eq([
|
||||
"Expected 4.0 (Float)", "not to respond to to_i"])
|
||||
end
|
||||
end
|
||||
|
|
|
@ -2,31 +2,31 @@ require 'spec_helper'
|
|||
require 'mspec/expectations/expectations'
|
||||
require 'mspec/matchers'
|
||||
|
||||
describe SignedZeroMatcher do
|
||||
RSpec.describe SignedZeroMatcher do
|
||||
it "matches when actual is zero and has the correct sign" do
|
||||
SignedZeroMatcher.new(1).matches?(0.0).should == true
|
||||
SignedZeroMatcher.new(-1).matches?(-0.0).should == true
|
||||
expect(SignedZeroMatcher.new(1).matches?(0.0)).to eq(true)
|
||||
expect(SignedZeroMatcher.new(-1).matches?(-0.0)).to eq(true)
|
||||
end
|
||||
|
||||
it "does not match when actual is non-zero" do
|
||||
SignedZeroMatcher.new(1).matches?(1.0).should == false
|
||||
SignedZeroMatcher.new(-1).matches?(-1.0).should == false
|
||||
expect(SignedZeroMatcher.new(1).matches?(1.0)).to eq(false)
|
||||
expect(SignedZeroMatcher.new(-1).matches?(-1.0)).to eq(false)
|
||||
end
|
||||
|
||||
it "does not match when actual is zero but has the incorrect sign" do
|
||||
SignedZeroMatcher.new(1).matches?(-0.0).should == false
|
||||
SignedZeroMatcher.new(-1).matches?(0.0).should == false
|
||||
expect(SignedZeroMatcher.new(1).matches?(-0.0)).to eq(false)
|
||||
expect(SignedZeroMatcher.new(-1).matches?(0.0)).to eq(false)
|
||||
end
|
||||
|
||||
it "provides a useful failure message" do
|
||||
matcher = SignedZeroMatcher.new(-1)
|
||||
matcher.matches?(0.0)
|
||||
matcher.failure_message.should == ["Expected 0.0", "to be -0.0"]
|
||||
expect(matcher.failure_message).to eq(["Expected 0.0", "to be -0.0"])
|
||||
end
|
||||
|
||||
it "provides a useful negative failure message" do
|
||||
matcher = SignedZeroMatcher.new(-1)
|
||||
matcher.matches?(-0.0)
|
||||
matcher.negative_failure_message.should == ["Expected -0.0", "not to be -0.0"]
|
||||
expect(matcher.negative_failure_message).to eq(["Expected -0.0", "not to be -0.0"])
|
||||
end
|
||||
end
|
||||
|
|
|
@ -7,78 +7,78 @@ require 'mspec/runner/mspec'
|
|||
require 'mspec/mocks/mock'
|
||||
require 'mspec/mocks/proxy'
|
||||
|
||||
describe Mock, ".mocks" do
|
||||
RSpec.describe Mock, ".mocks" do
|
||||
it "returns a Hash" do
|
||||
Mock.mocks.should be_kind_of(Hash)
|
||||
expect(Mock.mocks).to be_kind_of(Hash)
|
||||
end
|
||||
end
|
||||
|
||||
describe Mock, ".stubs" do
|
||||
RSpec.describe Mock, ".stubs" do
|
||||
it "returns a Hash" do
|
||||
Mock.stubs.should be_kind_of(Hash)
|
||||
expect(Mock.stubs).to be_kind_of(Hash)
|
||||
end
|
||||
end
|
||||
|
||||
describe Mock, ".replaced_name" do
|
||||
RSpec.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')
|
||||
Mock.replaced_name(m, :method_call).should == :"__mspec_#{m.object_id}_method_call__"
|
||||
expect(Mock.replaced_name(m, :method_call)).to eq(:"__mspec_#{m.object_id}_method_call__")
|
||||
end
|
||||
end
|
||||
|
||||
describe Mock, ".replaced_key" do
|
||||
RSpec.describe Mock, ".replaced_key" do
|
||||
it "returns a key used internally by Mock" do
|
||||
m = double('a fake id')
|
||||
Mock.replaced_key(m, :method_call).should == [:"__mspec_#{m.object_id}_method_call__", :method_call]
|
||||
expect(Mock.replaced_key(m, :method_call)).to eq([:"__mspec_#{m.object_id}_method_call__", :method_call])
|
||||
end
|
||||
end
|
||||
|
||||
describe Mock, ".replaced?" do
|
||||
RSpec.describe Mock, ".replaced?" do
|
||||
before :each do
|
||||
@mock = double('install_method')
|
||||
MSpec.stub(:actions)
|
||||
MSpec.stub(:current).and_return(double("spec state").as_null_object)
|
||||
allow(MSpec).to receive(:actions)
|
||||
allow(MSpec).to receive(:current).and_return(double("spec state").as_null_object)
|
||||
end
|
||||
|
||||
it "returns true if a method has been stubbed on an object" do
|
||||
Mock.install_method @mock, :method_call
|
||||
Mock.replaced?(Mock.replaced_name(@mock, :method_call)).should be_true
|
||||
expect(Mock.replaced?(Mock.replaced_name(@mock, :method_call))).to be_truthy
|
||||
end
|
||||
|
||||
it "returns true if a method has been mocked on an object" do
|
||||
Mock.install_method @mock, :method_call, :stub
|
||||
Mock.replaced?(Mock.replaced_name(@mock, :method_call)).should be_true
|
||||
expect(Mock.replaced?(Mock.replaced_name(@mock, :method_call))).to be_truthy
|
||||
end
|
||||
|
||||
it "returns false if a method has not been stubbed or mocked" do
|
||||
Mock.replaced?(Mock.replaced_name(@mock, :method_call)).should be_false
|
||||
expect(Mock.replaced?(Mock.replaced_name(@mock, :method_call))).to be_falsey
|
||||
end
|
||||
end
|
||||
|
||||
describe Mock, ".name_or_inspect" do
|
||||
RSpec.describe Mock, ".name_or_inspect" do
|
||||
before :each do
|
||||
@mock = double("I have a #name")
|
||||
end
|
||||
|
||||
it "returns the value of @name if set" do
|
||||
@mock.instance_variable_set(:@name, "Myself")
|
||||
Mock.name_or_inspect(@mock).should == "Myself"
|
||||
expect(Mock.name_or_inspect(@mock)).to eq("Myself")
|
||||
end
|
||||
end
|
||||
|
||||
describe Mock, ".install_method for mocks" do
|
||||
RSpec.describe Mock, ".install_method for mocks" do
|
||||
before :each do
|
||||
@mock = double('install_method')
|
||||
MSpec.stub(:actions)
|
||||
MSpec.stub(:current).and_return(double("spec state").as_null_object)
|
||||
allow(MSpec).to receive(:actions)
|
||||
allow(MSpec).to receive(:current).and_return(double("spec state").as_null_object)
|
||||
end
|
||||
|
||||
after :each do
|
||||
Mock.cleanup
|
||||
Mock.reset
|
||||
end
|
||||
|
||||
it "returns a MockProxy instance" do
|
||||
Mock.install_method(@mock, :method_call).should be_an_instance_of(MockProxy)
|
||||
expect(Mock.install_method(@mock, :method_call)).to be_an_instance_of(MockProxy)
|
||||
end
|
||||
|
||||
it "does not override a previously mocked method with the same name" do
|
||||
|
@ -86,7 +86,7 @@ describe Mock, ".install_method for mocks" do
|
|||
Mock.install_method(@mock, :method_call).with(:c).and_return(2)
|
||||
@mock.method_call(:a, :b)
|
||||
@mock.method_call(:c)
|
||||
lambda { @mock.method_call(:d) }.should raise_error(SpecExpectationNotMetError)
|
||||
expect { @mock.method_call(:d) }.to raise_error(SpecExpectationNotMetError)
|
||||
end
|
||||
|
||||
# This illustrates RSpec's behavior. This spec fails in mock call count verification
|
||||
|
@ -105,44 +105,44 @@ describe Mock, ".install_method for mocks" do
|
|||
#
|
||||
it "does not override a previously mocked method having the same arguments" do
|
||||
Mock.install_method(@mock, :method_call).with(:a).and_return(true)
|
||||
@mock.method_call(:a).should == true
|
||||
expect(@mock.method_call(:a)).to eq(true)
|
||||
Mock.install_method(@mock, :method_call).with(:a).and_return(false)
|
||||
@mock.method_call(:a).should == true
|
||||
lambda { Mock.verify_count }.should raise_error(SpecExpectationNotMetError)
|
||||
expect(@mock.method_call(:a)).to eq(true)
|
||||
expect { Mock.verify_count }.to raise_error(SpecExpectationNotMetError)
|
||||
end
|
||||
|
||||
it "properly sends #respond_to? calls to the aliased respond_to? method when not matching mock expectations" do
|
||||
Mock.install_method(@mock, :respond_to?).with(:to_str).and_return('mock to_str')
|
||||
Mock.install_method(@mock, :respond_to?).with(:to_int).and_return('mock to_int')
|
||||
@mock.respond_to?(:to_str).should == 'mock to_str'
|
||||
@mock.respond_to?(:to_int).should == 'mock to_int'
|
||||
@mock.respond_to?(:to_s).should == true
|
||||
@mock.respond_to?(:not_really_a_real_method_seriously).should == false
|
||||
expect(@mock.respond_to?(:to_str)).to eq('mock to_str')
|
||||
expect(@mock.respond_to?(:to_int)).to eq('mock to_int')
|
||||
expect(@mock.respond_to?(:to_s)).to eq(true)
|
||||
expect(@mock.respond_to?(:not_really_a_real_method_seriously)).to eq(false)
|
||||
end
|
||||
|
||||
it "adds to the expectation tally" do
|
||||
state = double("run state").as_null_object
|
||||
state.stub(:state).and_return(double("spec state"))
|
||||
MSpec.should_receive(:current).and_return(state)
|
||||
MSpec.should_receive(:actions).with(:expectation, state.state)
|
||||
allow(state).to receive(:state).and_return(double("spec state"))
|
||||
expect(MSpec).to receive(:current).and_return(state)
|
||||
expect(MSpec).to receive(:actions).with(:expectation, state.state)
|
||||
Mock.install_method(@mock, :method_call).and_return(1)
|
||||
@mock.method_call.should == 1
|
||||
expect(@mock.method_call).to eq(1)
|
||||
end
|
||||
|
||||
it "registers that an expectation has been encountered" do
|
||||
state = double("run state").as_null_object
|
||||
state.stub(:state).and_return(double("spec state"))
|
||||
MSpec.should_receive(:expectation)
|
||||
allow(state).to receive(:state).and_return(double("spec state"))
|
||||
expect(MSpec).to receive(:expectation)
|
||||
Mock.install_method(@mock, :method_call).and_return(1)
|
||||
@mock.method_call.should == 1
|
||||
expect(@mock.method_call).to eq(1)
|
||||
end
|
||||
end
|
||||
|
||||
describe Mock, ".install_method for stubs" do
|
||||
RSpec.describe Mock, ".install_method for stubs" do
|
||||
before :each do
|
||||
@mock = double('install_method')
|
||||
MSpec.stub(:actions)
|
||||
MSpec.stub(:current).and_return(double("spec state").as_null_object)
|
||||
allow(MSpec).to receive(:actions)
|
||||
allow(MSpec).to receive(:current).and_return(double("spec state").as_null_object)
|
||||
end
|
||||
|
||||
after :each do
|
||||
|
@ -150,7 +150,7 @@ describe Mock, ".install_method for stubs" do
|
|||
end
|
||||
|
||||
it "returns a MockProxy instance" do
|
||||
Mock.install_method(@mock, :method_call, :stub).should be_an_instance_of(MockProxy)
|
||||
expect(Mock.install_method(@mock, :method_call, :stub)).to be_an_instance_of(MockProxy)
|
||||
end
|
||||
|
||||
# This illustrates RSpec's behavior. This spec passes on RSpec and we mimic it
|
||||
|
@ -166,26 +166,26 @@ describe Mock, ".install_method for stubs" do
|
|||
# end
|
||||
it "inserts new stubs before old stubs" do
|
||||
Mock.install_method(@mock, :method_call, :stub).with(:a).and_return(true)
|
||||
@mock.method_call(:a).should == true
|
||||
expect(@mock.method_call(:a)).to eq(true)
|
||||
Mock.install_method(@mock, :method_call, :stub).with(:a).and_return(false)
|
||||
@mock.method_call(:a).should == false
|
||||
expect(@mock.method_call(:a)).to eq(false)
|
||||
Mock.verify_count
|
||||
end
|
||||
|
||||
it "does not add to the expectation tally" do
|
||||
state = double("run state").as_null_object
|
||||
state.stub(:state).and_return(double("spec state"))
|
||||
MSpec.should_not_receive(:actions)
|
||||
allow(state).to receive(:state).and_return(double("spec state"))
|
||||
expect(MSpec).not_to receive(:actions)
|
||||
Mock.install_method(@mock, :method_call, :stub).and_return(1)
|
||||
@mock.method_call.should == 1
|
||||
expect(@mock.method_call).to eq(1)
|
||||
end
|
||||
end
|
||||
|
||||
describe Mock, ".install_method" do
|
||||
RSpec.describe Mock, ".install_method" do
|
||||
before :each do
|
||||
@mock = double('install_method')
|
||||
MSpec.stub(:actions)
|
||||
MSpec.stub(:current).and_return(double("spec state").as_null_object)
|
||||
allow(MSpec).to receive(:actions)
|
||||
allow(MSpec).to receive(:current).and_return(double("spec state").as_null_object)
|
||||
end
|
||||
|
||||
after :each do
|
||||
|
@ -193,24 +193,24 @@ describe Mock, ".install_method" do
|
|||
end
|
||||
|
||||
it "does not alias a mocked or stubbed method when installing a new mock or stub" do
|
||||
@mock.should_not respond_to(:method_call)
|
||||
expect(@mock).not_to respond_to(:method_call)
|
||||
|
||||
Mock.install_method @mock, :method_call
|
||||
@mock.should respond_to(:method_call)
|
||||
@mock.should_not respond_to(Mock.replaced_name(@mock, :method_call))
|
||||
expect(@mock).to respond_to(:method_call)
|
||||
expect(@mock).not_to respond_to(Mock.replaced_name(@mock, :method_call))
|
||||
|
||||
Mock.install_method @mock, :method_call, :stub
|
||||
@mock.should respond_to(:method_call)
|
||||
@mock.should_not respond_to(Mock.replaced_name(@mock, :method_call))
|
||||
expect(@mock).to respond_to(:method_call)
|
||||
expect(@mock).not_to respond_to(Mock.replaced_name(@mock, :method_call))
|
||||
end
|
||||
end
|
||||
|
||||
class MockAndRaiseError < Exception; end
|
||||
|
||||
describe Mock, ".verify_call" do
|
||||
RSpec.describe Mock, ".verify_call" do
|
||||
before :each do
|
||||
MSpec.stub(:actions)
|
||||
MSpec.stub(:current).and_return(double("spec state").as_null_object)
|
||||
allow(MSpec).to receive(:actions)
|
||||
allow(MSpec).to receive(:current).and_return(double("spec state").as_null_object)
|
||||
|
||||
@mock = double('verify_call')
|
||||
@proxy = Mock.install_method @mock, :method_call
|
||||
|
@ -228,23 +228,23 @@ describe Mock, ".verify_call" do
|
|||
|
||||
it "raises an SpecExpectationNotMetError when the mock method does not receive the expected arguments" do
|
||||
@proxy.with(4, 2)
|
||||
lambda {
|
||||
expect {
|
||||
Mock.verify_call @mock, :method_call, 42
|
||||
}.should raise_error(SpecExpectationNotMetError)
|
||||
}.to raise_error(SpecExpectationNotMetError)
|
||||
end
|
||||
|
||||
it "raises an SpecExpectationNotMetError when the mock method is called with arguments but expects none" do
|
||||
lambda {
|
||||
expect {
|
||||
@proxy.with(:no_args)
|
||||
Mock.verify_call @mock, :method_call, "hello"
|
||||
}.should raise_error(SpecExpectationNotMetError)
|
||||
}.to raise_error(SpecExpectationNotMetError)
|
||||
end
|
||||
|
||||
it "raises an SpecExpectationNotMetError when the mock method is called with no arguments but expects some" do
|
||||
@proxy.with("hello", "beautiful", "world")
|
||||
lambda {
|
||||
expect {
|
||||
Mock.verify_call @mock, :method_call
|
||||
}.should raise_error(SpecExpectationNotMetError)
|
||||
}.to raise_error(SpecExpectationNotMetError)
|
||||
end
|
||||
|
||||
it "does not raise an exception when the mock method is called with arguments and is expecting :any_args" do
|
||||
|
@ -257,14 +257,14 @@ describe Mock, ".verify_call" do
|
|||
Mock.verify_call @mock, :method_call do
|
||||
ScratchPad.record true
|
||||
end
|
||||
ScratchPad.recorded.should == true
|
||||
expect(ScratchPad.recorded).to eq(true)
|
||||
end
|
||||
|
||||
it "does not yield a passed block when it is not expected to" do
|
||||
Mock.verify_call @mock, :method_call do
|
||||
ScratchPad.record true
|
||||
end
|
||||
ScratchPad.recorded.should == nil
|
||||
expect(ScratchPad.recorded).to eq(nil)
|
||||
end
|
||||
|
||||
it "can yield subsequently" do
|
||||
|
@ -274,28 +274,28 @@ describe Mock, ".verify_call" do
|
|||
Mock.verify_call @mock, :method_call do |arg|
|
||||
ScratchPad << arg
|
||||
end
|
||||
ScratchPad.recorded.should == [1, 2, 3]
|
||||
expect(ScratchPad.recorded).to eq([1, 2, 3])
|
||||
end
|
||||
|
||||
it "can yield and return an expected value" do
|
||||
@proxy.and_yield(1).and_return(3)
|
||||
|
||||
Mock.verify_call(@mock, :method_call) { |arg| ScratchPad.record arg }.should == 3
|
||||
ScratchPad.recorded.should == 1
|
||||
expect(Mock.verify_call(@mock, :method_call) { |arg| ScratchPad.record arg }).to eq(3)
|
||||
expect(ScratchPad.recorded).to eq(1)
|
||||
end
|
||||
|
||||
it "raises an exception when it is expected to yield but no block is given" do
|
||||
@proxy.and_yield(1, 2, 3)
|
||||
lambda {
|
||||
expect {
|
||||
Mock.verify_call(@mock, :method_call)
|
||||
}.should raise_error(SpecExpectationNotMetError)
|
||||
}.to raise_error(SpecExpectationNotMetError)
|
||||
end
|
||||
|
||||
it "raises an exception when it is expected to yield more arguments than the block can take" do
|
||||
@proxy.and_yield(1, 2, 3)
|
||||
lambda {
|
||||
expect {
|
||||
Mock.verify_call(@mock, :method_call) {|a, b|}
|
||||
}.should raise_error(SpecExpectationNotMetError)
|
||||
}.to raise_error(SpecExpectationNotMetError)
|
||||
end
|
||||
|
||||
it "does not raise an exception when it is expected to yield to a block that can take any number of arguments" do
|
||||
|
@ -307,16 +307,16 @@ describe Mock, ".verify_call" do
|
|||
|
||||
it "raises an exception when expected to" do
|
||||
@proxy.and_raise(MockAndRaiseError)
|
||||
lambda {
|
||||
expect {
|
||||
Mock.verify_call @mock, :method_call
|
||||
}.should raise_error(MockAndRaiseError)
|
||||
}.to raise_error(MockAndRaiseError)
|
||||
end
|
||||
end
|
||||
|
||||
describe Mock, ".verify_call mixing mocks and stubs" do
|
||||
RSpec.describe Mock, ".verify_call mixing mocks and stubs" do
|
||||
before :each do
|
||||
MSpec.stub(:actions)
|
||||
MSpec.stub(:current).and_return(double("spec state").as_null_object)
|
||||
allow(MSpec).to receive(:actions)
|
||||
allow(MSpec).to receive(:current).and_return(double("spec state").as_null_object)
|
||||
|
||||
@mock = double('verify_call')
|
||||
end
|
||||
|
@ -330,17 +330,17 @@ describe Mock, ".verify_call mixing mocks and stubs" do
|
|||
Mock.install_method @mock, :method_call, :stub
|
||||
Mock.install_method(@mock, :method_call, :mock).with("arg")
|
||||
|
||||
-> {
|
||||
expect {
|
||||
@mock.method_call
|
||||
}.should raise_error(SpecExpectationNotMetError, /called with unexpected arguments \(\)/)
|
||||
}.to raise_error(SpecExpectationNotMetError, /called with unexpected arguments \(\)/)
|
||||
|
||||
-> {
|
||||
expect {
|
||||
@mock.method_call("a", "b")
|
||||
}.should raise_error(SpecExpectationNotMetError, /called with unexpected arguments \("a", "b"\)/)
|
||||
}.to raise_error(SpecExpectationNotMetError, /called with unexpected arguments \("a", "b"\)/)
|
||||
|
||||
-> {
|
||||
expect {
|
||||
@mock.method_call("foo")
|
||||
}.should raise_error(SpecExpectationNotMetError, /called with unexpected arguments \("foo"\)/)
|
||||
}.to raise_error(SpecExpectationNotMetError, /called with unexpected arguments \("foo"\)/)
|
||||
|
||||
@mock.method_call("arg")
|
||||
end
|
||||
|
@ -349,26 +349,26 @@ describe Mock, ".verify_call mixing mocks and stubs" do
|
|||
Mock.install_method(@mock, :method_call, :mock).with("arg")
|
||||
Mock.install_method @mock, :method_call, :stub
|
||||
|
||||
-> {
|
||||
expect {
|
||||
@mock.method_call
|
||||
}.should raise_error(SpecExpectationNotMetError, /called with unexpected arguments \(\)/)
|
||||
}.to raise_error(SpecExpectationNotMetError, /called with unexpected arguments \(\)/)
|
||||
|
||||
-> {
|
||||
expect {
|
||||
@mock.method_call("a", "b")
|
||||
}.should raise_error(SpecExpectationNotMetError, /called with unexpected arguments \("a", "b"\)/)
|
||||
}.to raise_error(SpecExpectationNotMetError, /called with unexpected arguments \("a", "b"\)/)
|
||||
|
||||
-> {
|
||||
expect {
|
||||
@mock.method_call("foo")
|
||||
}.should raise_error(SpecExpectationNotMetError, /called with unexpected arguments \("foo"\)/)
|
||||
}.to raise_error(SpecExpectationNotMetError, /called with unexpected arguments \("foo"\)/)
|
||||
|
||||
@mock.method_call("arg")
|
||||
end
|
||||
end
|
||||
|
||||
describe Mock, ".verify_count" do
|
||||
RSpec.describe Mock, ".verify_count" do
|
||||
before :each do
|
||||
MSpec.stub(:actions)
|
||||
MSpec.stub(:current).and_return(double("spec state").as_null_object)
|
||||
allow(MSpec).to receive(:actions)
|
||||
allow(MSpec).to receive(:current).and_return(double("spec state").as_null_object)
|
||||
|
||||
@mock = double('verify_count')
|
||||
@proxy = Mock.install_method @mock, :method_call
|
||||
|
@ -388,7 +388,7 @@ describe Mock, ".verify_count" do
|
|||
it "raises an SpecExpectationNotMetError when the mock receives less than at least the expected number of calls" do
|
||||
@proxy.at_least(2)
|
||||
@mock.method_call
|
||||
lambda { Mock.verify_count }.should raise_error(SpecExpectationNotMetError)
|
||||
expect { Mock.verify_count }.to raise_error(SpecExpectationNotMetError)
|
||||
end
|
||||
|
||||
it "does not raise an exception when the mock receives at most the expected number of calls" do
|
||||
|
@ -403,7 +403,7 @@ describe Mock, ".verify_count" do
|
|||
@mock.method_call
|
||||
@mock.method_call
|
||||
@mock.method_call
|
||||
lambda { Mock.verify_count }.should raise_error(SpecExpectationNotMetError)
|
||||
expect { Mock.verify_count }.to raise_error(SpecExpectationNotMetError)
|
||||
end
|
||||
|
||||
it "does not raise an exception when the mock receives exactly the expected number of calls" do
|
||||
|
@ -416,7 +416,7 @@ describe Mock, ".verify_count" do
|
|||
it "raises an SpecExpectationNotMetError when the mock receives less than exactly the expected number of calls" do
|
||||
@proxy.exactly(2)
|
||||
@mock.method_call
|
||||
lambda { Mock.verify_count }.should raise_error(SpecExpectationNotMetError)
|
||||
expect { Mock.verify_count }.to raise_error(SpecExpectationNotMetError)
|
||||
end
|
||||
|
||||
it "raises an SpecExpectationNotMetError when the mock receives more than exactly the expected number of calls" do
|
||||
|
@ -424,14 +424,14 @@ describe Mock, ".verify_count" do
|
|||
@mock.method_call
|
||||
@mock.method_call
|
||||
@mock.method_call
|
||||
lambda { Mock.verify_count }.should raise_error(SpecExpectationNotMetError)
|
||||
expect { Mock.verify_count }.to raise_error(SpecExpectationNotMetError)
|
||||
end
|
||||
end
|
||||
|
||||
describe Mock, ".verify_count mixing mocks and stubs" do
|
||||
RSpec.describe Mock, ".verify_count mixing mocks and stubs" do
|
||||
before :each do
|
||||
MSpec.stub(:actions)
|
||||
MSpec.stub(:current).and_return(double("spec state").as_null_object)
|
||||
allow(MSpec).to receive(:actions)
|
||||
allow(MSpec).to receive(:current).and_return(double("spec state").as_null_object)
|
||||
|
||||
@mock = double('verify_count')
|
||||
end
|
||||
|
@ -449,9 +449,9 @@ describe Mock, ".verify_count mixing mocks and stubs" do
|
|||
Mock.install_method @mock, :method_call, :stub
|
||||
Mock.install_method @mock, :method_call, :mock
|
||||
|
||||
-> {
|
||||
expect {
|
||||
Mock.verify_count
|
||||
}.should raise_error(SpecExpectationNotMetError, /received it 0 times/)
|
||||
}.to raise_error(SpecExpectationNotMetError, /received it 0 times/)
|
||||
|
||||
@mock.method_call
|
||||
Mock.verify_count
|
||||
|
@ -461,19 +461,19 @@ describe Mock, ".verify_count mixing mocks and stubs" do
|
|||
Mock.install_method @mock, :method_call, :mock
|
||||
Mock.install_method @mock, :method_call, :stub
|
||||
|
||||
-> {
|
||||
expect {
|
||||
Mock.verify_count
|
||||
}.should raise_error(SpecExpectationNotMetError, /received it 0 times/)
|
||||
}.to raise_error(SpecExpectationNotMetError, /received it 0 times/)
|
||||
|
||||
@mock.method_call
|
||||
Mock.verify_count
|
||||
end
|
||||
end
|
||||
|
||||
describe Mock, ".cleanup" do
|
||||
RSpec.describe Mock, ".cleanup" do
|
||||
before :each do
|
||||
MSpec.stub(:actions)
|
||||
MSpec.stub(:current).and_return(double("spec state").as_null_object)
|
||||
allow(MSpec).to receive(:actions)
|
||||
allow(MSpec).to receive(:current).and_return(double("spec state").as_null_object)
|
||||
|
||||
@mock = double('cleanup')
|
||||
@proxy = Mock.install_method @mock, :method_call
|
||||
|
@ -484,47 +484,47 @@ describe Mock, ".cleanup" do
|
|||
end
|
||||
|
||||
it "removes the mock method call if it did not override an existing method" do
|
||||
@mock.should respond_to(:method_call)
|
||||
expect(@mock).to respond_to(:method_call)
|
||||
|
||||
Mock.cleanup
|
||||
@mock.should_not respond_to(:method_call)
|
||||
expect(@mock).not_to respond_to(:method_call)
|
||||
end
|
||||
|
||||
it "removes the replaced method if the mock method overrides an existing method" do
|
||||
def @mock.already_here() :hey end
|
||||
@mock.should respond_to(:already_here)
|
||||
expect(@mock).to respond_to(:already_here)
|
||||
replaced_name = Mock.replaced_name(@mock, :already_here)
|
||||
Mock.install_method @mock, :already_here
|
||||
@mock.should respond_to(replaced_name)
|
||||
expect(@mock).to respond_to(replaced_name)
|
||||
|
||||
Mock.cleanup
|
||||
@mock.should_not respond_to(replaced_name)
|
||||
@mock.should respond_to(:already_here)
|
||||
@mock.already_here.should == :hey
|
||||
expect(@mock).not_to respond_to(replaced_name)
|
||||
expect(@mock).to respond_to(:already_here)
|
||||
expect(@mock.already_here).to eq(:hey)
|
||||
end
|
||||
|
||||
it "removes all mock expectations" do
|
||||
Mock.mocks.should == { Mock.replaced_key(@mock, :method_call) => [@proxy] }
|
||||
expect(Mock.mocks).to eq({ Mock.replaced_key(@mock, :method_call) => [@proxy] })
|
||||
Mock.cleanup
|
||||
Mock.mocks.should == {}
|
||||
expect(Mock.mocks).to eq({})
|
||||
end
|
||||
|
||||
it "removes all stubs" do
|
||||
Mock.cleanup # remove @proxy
|
||||
@stub = Mock.install_method @mock, :method_call, :stub
|
||||
Mock.stubs.should == { Mock.replaced_key(@mock, :method_call) => [@stub] }
|
||||
expect(Mock.stubs).to eq({ Mock.replaced_key(@mock, :method_call) => [@stub] })
|
||||
Mock.cleanup
|
||||
Mock.stubs.should == {}
|
||||
expect(Mock.stubs).to eq({})
|
||||
end
|
||||
|
||||
it "removes the replaced name for mocks" do
|
||||
replaced_key = Mock.replaced_key(@mock, :method_call)
|
||||
Mock.should_receive(:clear_replaced).with(replaced_key)
|
||||
expect(Mock).to receive(:clear_replaced).with(replaced_key)
|
||||
|
||||
replaced_name = Mock.replaced_name(@mock, :method_call)
|
||||
Mock.replaced?(replaced_name).should be_true
|
||||
expect(Mock.replaced?(replaced_name)).to be_truthy
|
||||
|
||||
Mock.cleanup
|
||||
Mock.replaced?(replaced_name).should be_false
|
||||
expect(Mock.replaced?(replaced_name)).to be_falsey
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,276 +1,276 @@
|
|||
require 'spec_helper'
|
||||
require 'mspec/mocks/proxy'
|
||||
|
||||
describe MockObject, ".new" do
|
||||
RSpec.describe MockObject, ".new" do
|
||||
it "creates a new mock object" do
|
||||
m = MockObject.new('not a null object')
|
||||
lambda { m.not_a_method }.should raise_error(NoMethodError)
|
||||
expect { m.not_a_method }.to raise_error(NoMethodError)
|
||||
end
|
||||
|
||||
it "creates a new mock object that follows the NullObject pattern" do
|
||||
m = MockObject.new('null object', :null_object => true)
|
||||
m.not_really_a_method.should equal(m)
|
||||
expect(m.not_really_a_method).to equal(m)
|
||||
end
|
||||
end
|
||||
|
||||
describe MockProxy, ".new" do
|
||||
RSpec.describe MockProxy, ".new" do
|
||||
it "creates a mock proxy by default" do
|
||||
MockProxy.new.mock?.should be_true
|
||||
expect(MockProxy.new.mock?).to be_truthy
|
||||
end
|
||||
|
||||
it "creates a stub proxy by request" do
|
||||
MockProxy.new(:stub).stub?.should be_true
|
||||
expect(MockProxy.new(:stub).stub?).to be_truthy
|
||||
end
|
||||
|
||||
it "sets the call expectation to 1 call for a mock" do
|
||||
MockProxy.new.count.should == [:exactly, 1]
|
||||
expect(MockProxy.new.count).to eq([:exactly, 1])
|
||||
end
|
||||
|
||||
it "sets the call expectation to any number of times for a stub" do
|
||||
MockProxy.new(:stub).count.should == [:any_number_of_times, 0]
|
||||
expect(MockProxy.new(:stub).count).to eq([:any_number_of_times, 0])
|
||||
end
|
||||
end
|
||||
|
||||
describe MockProxy, "#count" do
|
||||
RSpec.describe MockProxy, "#count" do
|
||||
before :each do
|
||||
@proxy = MockProxy.new
|
||||
end
|
||||
|
||||
it "returns the expected number of calls the mock should receive" do
|
||||
@proxy.count.should == [:exactly, 1]
|
||||
@proxy.at_least(3).count.should == [:at_least, 3]
|
||||
expect(@proxy.count).to eq([:exactly, 1])
|
||||
expect(@proxy.at_least(3).count).to eq([:at_least, 3])
|
||||
end
|
||||
end
|
||||
|
||||
describe MockProxy, "#arguments" do
|
||||
RSpec.describe MockProxy, "#arguments" do
|
||||
before :each do
|
||||
@proxy = MockProxy.new
|
||||
end
|
||||
|
||||
it "returns the expected arguments" do
|
||||
@proxy.arguments.should == :any_args
|
||||
expect(@proxy.arguments).to eq(:any_args)
|
||||
end
|
||||
end
|
||||
|
||||
describe MockProxy, "#with" do
|
||||
RSpec.describe MockProxy, "#with" do
|
||||
before :each do
|
||||
@proxy = MockProxy.new
|
||||
end
|
||||
|
||||
it "returns self" do
|
||||
@proxy.with(:a).should be_equal(@proxy)
|
||||
expect(@proxy.with(:a)).to be_equal(@proxy)
|
||||
end
|
||||
|
||||
it "raises an ArgumentError if no arguments are given" do
|
||||
lambda { @proxy.with }.should raise_error(ArgumentError)
|
||||
expect { @proxy.with }.to raise_error(ArgumentError)
|
||||
end
|
||||
|
||||
it "accepts any number of arguments" do
|
||||
@proxy.with(1, 2, 3).should be_an_instance_of(MockProxy)
|
||||
@proxy.arguments.should == [1,2,3]
|
||||
expect(@proxy.with(1, 2, 3)).to be_an_instance_of(MockProxy)
|
||||
expect(@proxy.arguments).to eq([1,2,3])
|
||||
end
|
||||
end
|
||||
|
||||
describe MockProxy, "#once" do
|
||||
RSpec.describe MockProxy, "#once" do
|
||||
before :each do
|
||||
@proxy = MockProxy.new
|
||||
end
|
||||
|
||||
it "returns self" do
|
||||
@proxy.once.should be_equal(@proxy)
|
||||
expect(@proxy.once).to be_equal(@proxy)
|
||||
end
|
||||
|
||||
it "sets the expected calls to 1" do
|
||||
@proxy.once
|
||||
@proxy.count.should == [:exactly, 1]
|
||||
expect(@proxy.count).to eq([:exactly, 1])
|
||||
end
|
||||
|
||||
it "accepts no arguments" do
|
||||
lambda { @proxy.once(:a) }.should raise_error
|
||||
expect { @proxy.once(:a) }.to raise_error
|
||||
end
|
||||
end
|
||||
|
||||
describe MockProxy, "#twice" do
|
||||
RSpec.describe MockProxy, "#twice" do
|
||||
before :each do
|
||||
@proxy = MockProxy.new
|
||||
end
|
||||
|
||||
it "returns self" do
|
||||
@proxy.twice.should be_equal(@proxy)
|
||||
expect(@proxy.twice).to be_equal(@proxy)
|
||||
end
|
||||
|
||||
it "sets the expected calls to 2" do
|
||||
@proxy.twice
|
||||
@proxy.count.should == [:exactly, 2]
|
||||
expect(@proxy.count).to eq([:exactly, 2])
|
||||
end
|
||||
|
||||
it "accepts no arguments" do
|
||||
lambda { @proxy.twice(:b) }.should raise_error
|
||||
expect { @proxy.twice(:b) }.to raise_error
|
||||
end
|
||||
end
|
||||
|
||||
describe MockProxy, "#exactly" do
|
||||
RSpec.describe MockProxy, "#exactly" do
|
||||
before :each do
|
||||
@proxy = MockProxy.new
|
||||
end
|
||||
|
||||
it "returns self" do
|
||||
@proxy.exactly(2).should be_equal(@proxy)
|
||||
expect(@proxy.exactly(2)).to be_equal(@proxy)
|
||||
end
|
||||
|
||||
it "sets the expected calls to exactly n" do
|
||||
@proxy.exactly(5)
|
||||
@proxy.count.should == [:exactly, 5]
|
||||
expect(@proxy.count).to eq([:exactly, 5])
|
||||
end
|
||||
|
||||
it "does not accept an argument that Integer() cannot convert" do
|
||||
lambda { @proxy.exactly('x') }.should raise_error
|
||||
expect { @proxy.exactly('x') }.to raise_error
|
||||
end
|
||||
end
|
||||
|
||||
describe MockProxy, "#at_least" do
|
||||
RSpec.describe MockProxy, "#at_least" do
|
||||
before :each do
|
||||
@proxy = MockProxy.new
|
||||
end
|
||||
|
||||
it "returns self" do
|
||||
@proxy.at_least(3).should be_equal(@proxy)
|
||||
expect(@proxy.at_least(3)).to be_equal(@proxy)
|
||||
end
|
||||
|
||||
it "sets the expected calls to at least n" do
|
||||
@proxy.at_least(3)
|
||||
@proxy.count.should == [:at_least, 3]
|
||||
expect(@proxy.count).to eq([:at_least, 3])
|
||||
end
|
||||
|
||||
it "accepts :once :twice" do
|
||||
@proxy.at_least(:once)
|
||||
@proxy.count.should == [:at_least, 1]
|
||||
expect(@proxy.count).to eq([:at_least, 1])
|
||||
@proxy.at_least(:twice)
|
||||
@proxy.count.should == [:at_least, 2]
|
||||
expect(@proxy.count).to eq([:at_least, 2])
|
||||
end
|
||||
|
||||
it "does not accept an argument that Integer() cannot convert" do
|
||||
lambda { @proxy.at_least('x') }.should raise_error
|
||||
expect { @proxy.at_least('x') }.to raise_error
|
||||
end
|
||||
end
|
||||
|
||||
describe MockProxy, "#at_most" do
|
||||
RSpec.describe MockProxy, "#at_most" do
|
||||
before :each do
|
||||
@proxy = MockProxy.new
|
||||
end
|
||||
|
||||
it "returns self" do
|
||||
@proxy.at_most(2).should be_equal(@proxy)
|
||||
expect(@proxy.at_most(2)).to be_equal(@proxy)
|
||||
end
|
||||
|
||||
it "sets the expected calls to at most n" do
|
||||
@proxy.at_most(2)
|
||||
@proxy.count.should == [:at_most, 2]
|
||||
expect(@proxy.count).to eq([:at_most, 2])
|
||||
end
|
||||
|
||||
it "accepts :once, :twice" do
|
||||
@proxy.at_most(:once)
|
||||
@proxy.count.should == [:at_most, 1]
|
||||
expect(@proxy.count).to eq([:at_most, 1])
|
||||
@proxy.at_most(:twice)
|
||||
@proxy.count.should == [:at_most, 2]
|
||||
expect(@proxy.count).to eq([:at_most, 2])
|
||||
end
|
||||
|
||||
it "does not accept an argument that Integer() cannot convert" do
|
||||
lambda { @proxy.at_most('x') }.should raise_error
|
||||
expect { @proxy.at_most('x') }.to raise_error
|
||||
end
|
||||
end
|
||||
|
||||
describe MockProxy, "#any_number_of_times" do
|
||||
RSpec.describe MockProxy, "#any_number_of_times" do
|
||||
before :each do
|
||||
@proxy = MockProxy.new
|
||||
end
|
||||
|
||||
it "returns self" do
|
||||
@proxy.any_number_of_times.should be_equal(@proxy)
|
||||
expect(@proxy.any_number_of_times).to be_equal(@proxy)
|
||||
end
|
||||
|
||||
it "sets the expected calls to any number of times" do
|
||||
@proxy.any_number_of_times
|
||||
@proxy.count.should == [:any_number_of_times, 0]
|
||||
expect(@proxy.count).to eq([:any_number_of_times, 0])
|
||||
end
|
||||
|
||||
it "does not accept an argument" do
|
||||
lambda { @proxy.any_number_of_times(2) }.should raise_error
|
||||
expect { @proxy.any_number_of_times(2) }.to raise_error
|
||||
end
|
||||
end
|
||||
|
||||
describe MockProxy, "#and_return" do
|
||||
RSpec.describe MockProxy, "#and_return" do
|
||||
before :each do
|
||||
@proxy = MockProxy.new
|
||||
end
|
||||
|
||||
it "returns self" do
|
||||
@proxy.and_return(false).should equal(@proxy)
|
||||
expect(@proxy.and_return(false)).to equal(@proxy)
|
||||
end
|
||||
|
||||
it "sets the expected return value" do
|
||||
@proxy.and_return(false)
|
||||
@proxy.returning.should == false
|
||||
expect(@proxy.returning).to eq(false)
|
||||
end
|
||||
|
||||
it "accepts any number of return values" do
|
||||
@proxy.and_return(1, 2, 3)
|
||||
@proxy.returning.should == 1
|
||||
@proxy.returning.should == 2
|
||||
@proxy.returning.should == 3
|
||||
expect(@proxy.returning).to eq(1)
|
||||
expect(@proxy.returning).to eq(2)
|
||||
expect(@proxy.returning).to eq(3)
|
||||
end
|
||||
|
||||
it "implicitly sets the expected number of calls" do
|
||||
@proxy.and_return(1, 2, 3)
|
||||
@proxy.count.should == [:exactly, 3]
|
||||
expect(@proxy.count).to eq([:exactly, 3])
|
||||
end
|
||||
|
||||
it "only sets the expected number of calls if it is higher than what is already set" do
|
||||
@proxy.at_least(5).times.and_return(1, 2, 3)
|
||||
@proxy.count.should == [:at_least, 5]
|
||||
expect(@proxy.count).to eq([:at_least, 5])
|
||||
|
||||
@proxy.at_least(2).times.and_return(1, 2, 3)
|
||||
@proxy.count.should == [:at_least, 3]
|
||||
expect(@proxy.count).to eq([:at_least, 3])
|
||||
end
|
||||
end
|
||||
|
||||
describe MockProxy, "#returning" do
|
||||
RSpec.describe MockProxy, "#returning" do
|
||||
before :each do
|
||||
@proxy = MockProxy.new
|
||||
end
|
||||
|
||||
it "returns nil by default" do
|
||||
@proxy.returning.should be_nil
|
||||
expect(@proxy.returning).to be_nil
|
||||
end
|
||||
|
||||
it "returns the value set by #and_return" do
|
||||
@proxy.and_return(2)
|
||||
@proxy.returning.should == 2
|
||||
@proxy.returning.should == 2
|
||||
expect(@proxy.returning).to eq(2)
|
||||
expect(@proxy.returning).to eq(2)
|
||||
end
|
||||
|
||||
it "returns a sequence of values set by #and_return" do
|
||||
@proxy.and_return(1,2,3,4)
|
||||
@proxy.returning.should == 1
|
||||
@proxy.returning.should == 2
|
||||
@proxy.returning.should == 3
|
||||
@proxy.returning.should == 4
|
||||
@proxy.returning.should == 4
|
||||
@proxy.returning.should == 4
|
||||
expect(@proxy.returning).to eq(1)
|
||||
expect(@proxy.returning).to eq(2)
|
||||
expect(@proxy.returning).to eq(3)
|
||||
expect(@proxy.returning).to eq(4)
|
||||
expect(@proxy.returning).to eq(4)
|
||||
expect(@proxy.returning).to eq(4)
|
||||
end
|
||||
end
|
||||
|
||||
describe MockProxy, "#calls" do
|
||||
RSpec.describe MockProxy, "#calls" do
|
||||
before :each do
|
||||
@proxy = MockProxy.new
|
||||
end
|
||||
|
||||
it "returns the number of times the proxy is called" do
|
||||
@proxy.calls.should == 0
|
||||
expect(@proxy.calls).to eq(0)
|
||||
end
|
||||
end
|
||||
|
||||
describe MockProxy, "#called" do
|
||||
RSpec.describe MockProxy, "#called" do
|
||||
before :each do
|
||||
@proxy = MockProxy.new
|
||||
end
|
||||
|
@ -278,128 +278,128 @@ describe MockProxy, "#called" do
|
|||
it "increments the number of times the proxy is called" do
|
||||
@proxy.called
|
||||
@proxy.called
|
||||
@proxy.calls.should == 2
|
||||
expect(@proxy.calls).to eq(2)
|
||||
end
|
||||
end
|
||||
|
||||
describe MockProxy, "#times" do
|
||||
RSpec.describe MockProxy, "#times" do
|
||||
before :each do
|
||||
@proxy = MockProxy.new
|
||||
end
|
||||
|
||||
it "is a no-op" do
|
||||
@proxy.times.should == @proxy
|
||||
expect(@proxy.times).to eq(@proxy)
|
||||
end
|
||||
end
|
||||
|
||||
describe MockProxy, "#stub?" do
|
||||
RSpec.describe MockProxy, "#stub?" do
|
||||
it "returns true if the proxy is created as a stub" do
|
||||
MockProxy.new(:stub).stub?.should be_true
|
||||
expect(MockProxy.new(:stub).stub?).to be_truthy
|
||||
end
|
||||
|
||||
it "returns false if the proxy is created as a mock" do
|
||||
MockProxy.new(:mock).stub?.should be_false
|
||||
expect(MockProxy.new(:mock).stub?).to be_falsey
|
||||
end
|
||||
end
|
||||
|
||||
describe MockProxy, "#mock?" do
|
||||
RSpec.describe MockProxy, "#mock?" do
|
||||
it "returns true if the proxy is created as a mock" do
|
||||
MockProxy.new(:mock).mock?.should be_true
|
||||
expect(MockProxy.new(:mock).mock?).to be_truthy
|
||||
end
|
||||
|
||||
it "returns false if the proxy is created as a stub" do
|
||||
MockProxy.new(:stub).mock?.should be_false
|
||||
expect(MockProxy.new(:stub).mock?).to be_falsey
|
||||
end
|
||||
end
|
||||
|
||||
describe MockProxy, "#and_yield" do
|
||||
RSpec.describe MockProxy, "#and_yield" do
|
||||
before :each do
|
||||
@proxy = MockProxy.new
|
||||
end
|
||||
|
||||
it "returns self" do
|
||||
@proxy.and_yield(false).should equal(@proxy)
|
||||
expect(@proxy.and_yield(false)).to equal(@proxy)
|
||||
end
|
||||
|
||||
it "sets the expected values to yield" do
|
||||
@proxy.and_yield(1).yielding.should == [[1]]
|
||||
expect(@proxy.and_yield(1).yielding).to eq([[1]])
|
||||
end
|
||||
|
||||
it "accepts multiple values to yield" do
|
||||
@proxy.and_yield(1, 2, 3).yielding.should == [[1, 2, 3]]
|
||||
expect(@proxy.and_yield(1, 2, 3).yielding).to eq([[1, 2, 3]])
|
||||
end
|
||||
end
|
||||
|
||||
describe MockProxy, "#raising" do
|
||||
RSpec.describe MockProxy, "#raising" do
|
||||
before :each do
|
||||
@proxy = MockProxy.new
|
||||
end
|
||||
|
||||
it "returns nil by default" do
|
||||
@proxy.raising.should be_nil
|
||||
expect(@proxy.raising).to be_nil
|
||||
end
|
||||
|
||||
it "returns the exception object passed to #and_raise" do
|
||||
exc = double("exception")
|
||||
@proxy.and_raise(exc)
|
||||
@proxy.raising.should equal(exc)
|
||||
expect(@proxy.raising).to equal(exc)
|
||||
end
|
||||
|
||||
it "returns an instance of RuntimeError when a String is passed to #and_raise" do
|
||||
@proxy.and_raise("an error")
|
||||
exc = @proxy.raising
|
||||
exc.should be_an_instance_of(RuntimeError)
|
||||
exc.message.should == "an error"
|
||||
expect(exc).to be_an_instance_of(RuntimeError)
|
||||
expect(exc.message).to eq("an error")
|
||||
end
|
||||
end
|
||||
|
||||
describe MockProxy, "#yielding" do
|
||||
RSpec.describe MockProxy, "#yielding" do
|
||||
before :each do
|
||||
@proxy = MockProxy.new
|
||||
end
|
||||
|
||||
it "returns an empty array by default" do
|
||||
@proxy.yielding.should == []
|
||||
expect(@proxy.yielding).to eq([])
|
||||
end
|
||||
|
||||
it "returns an array of arrays of values the proxy should yield" do
|
||||
@proxy.and_yield(3)
|
||||
@proxy.yielding.should == [[3]]
|
||||
expect(@proxy.yielding).to eq([[3]])
|
||||
end
|
||||
|
||||
it "returns an accumulation of arrays of values the proxy should yield" do
|
||||
@proxy.and_yield(1).and_yield(2, 3)
|
||||
@proxy.yielding.should == [[1], [2, 3]]
|
||||
expect(@proxy.yielding).to eq([[1], [2, 3]])
|
||||
end
|
||||
end
|
||||
|
||||
describe MockProxy, "#yielding?" do
|
||||
RSpec.describe MockProxy, "#yielding?" do
|
||||
before :each do
|
||||
@proxy = MockProxy.new
|
||||
end
|
||||
|
||||
it "returns false if the proxy is not yielding" do
|
||||
@proxy.yielding?.should be_false
|
||||
expect(@proxy.yielding?).to be_falsey
|
||||
end
|
||||
|
||||
it "returns true if the proxy is yielding" do
|
||||
@proxy.and_yield(1)
|
||||
@proxy.yielding?.should be_true
|
||||
expect(@proxy.yielding?).to be_truthy
|
||||
end
|
||||
end
|
||||
|
||||
describe MockIntObject, "#to_int" do
|
||||
RSpec.describe MockIntObject, "#to_int" do
|
||||
before :each do
|
||||
@int = MockIntObject.new(10)
|
||||
end
|
||||
|
||||
it "returns the number if to_int is called" do
|
||||
@int.to_int.should == 10
|
||||
@int.count.should == [:at_least, 1]
|
||||
expect(@int.to_int).to eq(10)
|
||||
expect(@int.count).to eq([:at_least, 1])
|
||||
end
|
||||
|
||||
it "tries to convert the target to int if to_int is called" do
|
||||
MockIntObject.new(@int).to_int.should == 10
|
||||
@int.count.should == [:at_least, 1]
|
||||
expect(MockIntObject.new(@int).to_int).to eq(10)
|
||||
expect(@int.count).to eq([:at_least, 1])
|
||||
end
|
||||
end
|
||||
|
|
|
@ -3,82 +3,82 @@ require 'mspec/runner/actions/filter'
|
|||
require 'mspec/runner/mspec'
|
||||
require 'mspec/runner/tag'
|
||||
|
||||
describe ActionFilter do
|
||||
RSpec.describe ActionFilter do
|
||||
it "creates a filter when not passed a description" do
|
||||
MatchFilter.should_not_receive(:new)
|
||||
expect(MatchFilter).not_to receive(:new)
|
||||
ActionFilter.new(nil, nil)
|
||||
end
|
||||
|
||||
it "creates a filter from a single description" do
|
||||
MatchFilter.should_receive(:new).with(nil, "match me")
|
||||
expect(MatchFilter).to receive(:new).with(nil, "match me")
|
||||
ActionFilter.new(nil, "match me")
|
||||
end
|
||||
|
||||
it "creates a filter from an array of descriptions" do
|
||||
MatchFilter.should_receive(:new).with(nil, "match me", "again")
|
||||
expect(MatchFilter).to receive(:new).with(nil, "match me", "again")
|
||||
ActionFilter.new(nil, ["match me", "again"])
|
||||
end
|
||||
end
|
||||
|
||||
describe ActionFilter, "#===" do
|
||||
RSpec.describe ActionFilter, "#===" do
|
||||
before :each do
|
||||
MSpec.stub(:read_tags).and_return(["match"])
|
||||
allow(MSpec).to receive(:read_tags).and_return(["match"])
|
||||
@action = ActionFilter.new(nil, ["catch", "if you"])
|
||||
end
|
||||
|
||||
it "returns false if there are no filters" do
|
||||
action = ActionFilter.new
|
||||
action.===("anything").should == false
|
||||
expect(action.===("anything")).to eq(false)
|
||||
end
|
||||
|
||||
it "returns true if the argument matches any of the descriptions" do
|
||||
@action.===("catch").should == true
|
||||
@action.===("if you can").should == true
|
||||
expect(@action.===("catch")).to eq(true)
|
||||
expect(@action.===("if you can")).to eq(true)
|
||||
end
|
||||
|
||||
it "returns false if the argument does not match any of the descriptions" do
|
||||
@action.===("patch me").should == false
|
||||
@action.===("if I can").should == false
|
||||
expect(@action.===("patch me")).to eq(false)
|
||||
expect(@action.===("if I can")).to eq(false)
|
||||
end
|
||||
end
|
||||
|
||||
describe ActionFilter, "#load" do
|
||||
RSpec.describe ActionFilter, "#load" do
|
||||
before :each do
|
||||
@tag = SpecTag.new "tag(comment):description"
|
||||
end
|
||||
|
||||
it "creates a filter from a single tag" do
|
||||
MSpec.should_receive(:read_tags).with(["tag"]).and_return([@tag])
|
||||
MatchFilter.should_receive(:new).with(nil, "description")
|
||||
expect(MSpec).to receive(:read_tags).with(["tag"]).and_return([@tag])
|
||||
expect(MatchFilter).to receive(:new).with(nil, "description")
|
||||
ActionFilter.new("tag", nil).load
|
||||
end
|
||||
|
||||
it "creates a filter from an array of tags" do
|
||||
MSpec.should_receive(:read_tags).with(["tag", "key"]).and_return([@tag])
|
||||
MatchFilter.should_receive(:new).with(nil, "description")
|
||||
expect(MSpec).to receive(:read_tags).with(["tag", "key"]).and_return([@tag])
|
||||
expect(MatchFilter).to receive(:new).with(nil, "description")
|
||||
ActionFilter.new(["tag", "key"], nil).load
|
||||
end
|
||||
|
||||
it "creates a filter from both tags and descriptions" do
|
||||
MSpec.should_receive(:read_tags).and_return([@tag])
|
||||
expect(MSpec).to receive(:read_tags).and_return([@tag])
|
||||
filter = ActionFilter.new("tag", ["match me", "again"])
|
||||
MatchFilter.should_receive(:new).with(nil, "description")
|
||||
expect(MatchFilter).to receive(:new).with(nil, "description")
|
||||
filter.load
|
||||
end
|
||||
end
|
||||
|
||||
describe ActionFilter, "#register" do
|
||||
RSpec.describe ActionFilter, "#register" do
|
||||
it "registers itself with MSpec for the :load actions" do
|
||||
filter = ActionFilter.new
|
||||
MSpec.should_receive(:register).with(:load, filter)
|
||||
expect(MSpec).to receive(:register).with(:load, filter)
|
||||
filter.register
|
||||
end
|
||||
end
|
||||
|
||||
describe ActionFilter, "#unregister" do
|
||||
RSpec.describe ActionFilter, "#unregister" do
|
||||
it "unregisters itself with MSpec for the :load actions" do
|
||||
filter = ActionFilter.new
|
||||
MSpec.should_receive(:unregister).with(:load, filter)
|
||||
expect(MSpec).to receive(:unregister).with(:load, filter)
|
||||
filter.unregister
|
||||
end
|
||||
end
|
||||
|
|
|
@ -4,211 +4,211 @@ require 'mspec/runner/mspec'
|
|||
require 'mspec/runner/example'
|
||||
require 'mspec/runner/tag'
|
||||
|
||||
describe TagAction, ".new" do
|
||||
RSpec.describe TagAction, ".new" do
|
||||
it "creates an MatchFilter with its tag and desc arguments" do
|
||||
filter = double('action filter').as_null_object
|
||||
MatchFilter.should_receive(:new).with(nil, "some", "thing").and_return(filter)
|
||||
expect(MatchFilter).to receive(:new).with(nil, "some", "thing").and_return(filter)
|
||||
TagAction.new :add, :all, nil, nil, ["tag", "key"], ["some", "thing"]
|
||||
end
|
||||
end
|
||||
|
||||
describe TagAction, "#===" do
|
||||
RSpec.describe TagAction, "#===" do
|
||||
before :each do
|
||||
MSpec.stub(:read_tags).and_return(["match"])
|
||||
allow(MSpec).to receive(:read_tags).and_return(["match"])
|
||||
@action = TagAction.new :add, :fail, nil, nil, nil, ["catch", "if you"]
|
||||
end
|
||||
|
||||
it "returns true if there are no filters" do
|
||||
action = TagAction.new :add, :all, nil, nil
|
||||
action.===("anything").should == true
|
||||
expect(action.===("anything")).to eq(true)
|
||||
end
|
||||
|
||||
it "returns true if the argument matches any of the descriptions" do
|
||||
@action.===("catch").should == true
|
||||
@action.===("if you can").should == true
|
||||
expect(@action.===("catch")).to eq(true)
|
||||
expect(@action.===("if you can")).to eq(true)
|
||||
end
|
||||
|
||||
it "returns false if the argument does not match any of the descriptions" do
|
||||
@action.===("patch me").should == false
|
||||
@action.===("if I can").should == false
|
||||
expect(@action.===("patch me")).to eq(false)
|
||||
expect(@action.===("if I can")).to eq(false)
|
||||
end
|
||||
end
|
||||
|
||||
describe TagAction, "#exception?" do
|
||||
RSpec.describe TagAction, "#exception?" do
|
||||
before :each do
|
||||
@action = TagAction.new :add, :fail, nil, nil, nil, nil
|
||||
end
|
||||
|
||||
it "returns false if no exception has been raised while evaluating an example" do
|
||||
@action.exception?.should be_false
|
||||
expect(@action.exception?).to be_falsey
|
||||
end
|
||||
|
||||
it "returns true if an exception was raised while evaluating an example" do
|
||||
@action.exception ExceptionState.new nil, nil, Exception.new("failed")
|
||||
@action.exception?.should be_true
|
||||
expect(@action.exception?).to be_truthy
|
||||
end
|
||||
end
|
||||
|
||||
describe TagAction, "#outcome?" do
|
||||
RSpec.describe TagAction, "#outcome?" do
|
||||
before :each do
|
||||
MSpec.stub(:read_tags).and_return([])
|
||||
allow(MSpec).to receive(:read_tags).and_return([])
|
||||
@exception = ExceptionState.new nil, nil, Exception.new("failed")
|
||||
end
|
||||
|
||||
it "returns true if outcome is :fail and the spec fails" do
|
||||
action = TagAction.new :add, :fail, nil, nil, nil, nil
|
||||
action.exception @exception
|
||||
action.outcome?.should == true
|
||||
expect(action.outcome?).to eq(true)
|
||||
end
|
||||
|
||||
it "returns false if the outcome is :fail and the spec passes" do
|
||||
action = TagAction.new :add, :fail, nil, nil, nil, nil
|
||||
action.outcome?.should == false
|
||||
expect(action.outcome?).to eq(false)
|
||||
end
|
||||
|
||||
it "returns true if the outcome is :pass and the spec passes" do
|
||||
action = TagAction.new :del, :pass, nil, nil, nil, nil
|
||||
action.outcome?.should == true
|
||||
expect(action.outcome?).to eq(true)
|
||||
end
|
||||
|
||||
it "returns false if the outcome is :pass and the spec fails" do
|
||||
action = TagAction.new :del, :pass, nil, nil, nil, nil
|
||||
action.exception @exception
|
||||
action.outcome?.should == false
|
||||
expect(action.outcome?).to eq(false)
|
||||
end
|
||||
|
||||
it "returns true if the outcome is :all" do
|
||||
action = TagAction.new :add, :all, nil, nil, nil, nil
|
||||
action.exception @exception
|
||||
action.outcome?.should == true
|
||||
expect(action.outcome?).to eq(true)
|
||||
end
|
||||
end
|
||||
|
||||
describe TagAction, "#before" do
|
||||
RSpec.describe TagAction, "#before" do
|
||||
it "resets the #exception? flag to false" do
|
||||
action = TagAction.new :add, :fail, nil, nil, nil, nil
|
||||
action.exception?.should be_false
|
||||
expect(action.exception?).to be_falsey
|
||||
action.exception ExceptionState.new(nil, nil, Exception.new("Fail!"))
|
||||
action.exception?.should be_true
|
||||
expect(action.exception?).to be_truthy
|
||||
action.before(ExampleState.new(ContextState.new("describe"), "it"))
|
||||
action.exception?.should be_false
|
||||
expect(action.exception?).to be_falsey
|
||||
end
|
||||
end
|
||||
|
||||
describe TagAction, "#exception" do
|
||||
RSpec.describe TagAction, "#exception" do
|
||||
it "sets the #exception? flag" do
|
||||
action = TagAction.new :add, :fail, nil, nil, nil, nil
|
||||
action.exception?.should be_false
|
||||
expect(action.exception?).to be_falsey
|
||||
action.exception ExceptionState.new(nil, nil, Exception.new("Fail!"))
|
||||
action.exception?.should be_true
|
||||
expect(action.exception?).to be_truthy
|
||||
end
|
||||
end
|
||||
|
||||
describe TagAction, "#after when action is :add" do
|
||||
RSpec.describe TagAction, "#after when action is :add" do
|
||||
before :each do
|
||||
MSpec.stub(:read_tags).and_return([])
|
||||
allow(MSpec).to receive(:read_tags).and_return([])
|
||||
context = ContextState.new "Catch#me"
|
||||
@state = ExampleState.new context, "if you can"
|
||||
@tag = SpecTag.new "tag(comment):Catch#me if you can"
|
||||
SpecTag.stub(:new).and_return(@tag)
|
||||
allow(SpecTag).to receive(:new).and_return(@tag)
|
||||
@exception = ExceptionState.new nil, nil, Exception.new("failed")
|
||||
end
|
||||
|
||||
it "does not write a tag if the description does not match" do
|
||||
MSpec.should_not_receive(:write_tag)
|
||||
expect(MSpec).not_to receive(:write_tag)
|
||||
action = TagAction.new :add, :all, "tag", "comment", nil, "match"
|
||||
action.after @state
|
||||
end
|
||||
|
||||
it "does not write a tag if outcome is :fail and the spec passed" do
|
||||
MSpec.should_not_receive(:write_tag)
|
||||
expect(MSpec).not_to receive(:write_tag)
|
||||
action = TagAction.new :add, :fail, "tag", "comment", nil, "can"
|
||||
action.after @state
|
||||
end
|
||||
|
||||
it "writes a tag if the outcome is :fail and the spec failed" do
|
||||
MSpec.should_receive(:write_tag).with(@tag)
|
||||
expect(MSpec).to receive(:write_tag).with(@tag)
|
||||
action = TagAction.new :add, :fail, "tag", "comment", nil, "can"
|
||||
action.exception @exception
|
||||
action.after @state
|
||||
end
|
||||
|
||||
it "does not write a tag if outcome is :pass and the spec failed" do
|
||||
MSpec.should_not_receive(:write_tag)
|
||||
expect(MSpec).not_to receive(:write_tag)
|
||||
action = TagAction.new :add, :pass, "tag", "comment", nil, "can"
|
||||
action.exception @exception
|
||||
action.after @state
|
||||
end
|
||||
|
||||
it "writes a tag if the outcome is :pass and the spec passed" do
|
||||
MSpec.should_receive(:write_tag).with(@tag)
|
||||
expect(MSpec).to receive(:write_tag).with(@tag)
|
||||
action = TagAction.new :add, :pass, "tag", "comment", nil, "can"
|
||||
action.after @state
|
||||
end
|
||||
|
||||
it "writes a tag if the outcome is :all" do
|
||||
MSpec.should_receive(:write_tag).with(@tag)
|
||||
expect(MSpec).to receive(:write_tag).with(@tag)
|
||||
action = TagAction.new :add, :all, "tag", "comment", nil, "can"
|
||||
action.after @state
|
||||
end
|
||||
end
|
||||
|
||||
describe TagAction, "#after when action is :del" do
|
||||
RSpec.describe TagAction, "#after when action is :del" do
|
||||
before :each do
|
||||
MSpec.stub(:read_tags).and_return([])
|
||||
allow(MSpec).to receive(:read_tags).and_return([])
|
||||
context = ContextState.new "Catch#me"
|
||||
@state = ExampleState.new context, "if you can"
|
||||
@tag = SpecTag.new "tag(comment):Catch#me if you can"
|
||||
SpecTag.stub(:new).and_return(@tag)
|
||||
allow(SpecTag).to receive(:new).and_return(@tag)
|
||||
@exception = ExceptionState.new nil, nil, Exception.new("failed")
|
||||
end
|
||||
|
||||
it "does not delete a tag if the description does not match" do
|
||||
MSpec.should_not_receive(:delete_tag)
|
||||
expect(MSpec).not_to receive(:delete_tag)
|
||||
action = TagAction.new :del, :all, "tag", "comment", nil, "match"
|
||||
action.after @state
|
||||
end
|
||||
|
||||
it "does not delete a tag if outcome is :fail and the spec passed" do
|
||||
MSpec.should_not_receive(:delete_tag)
|
||||
expect(MSpec).not_to receive(:delete_tag)
|
||||
action = TagAction.new :del, :fail, "tag", "comment", nil, "can"
|
||||
action.after @state
|
||||
end
|
||||
|
||||
it "deletes a tag if the outcome is :fail and the spec failed" do
|
||||
MSpec.should_receive(:delete_tag).with(@tag)
|
||||
expect(MSpec).to receive(:delete_tag).with(@tag)
|
||||
action = TagAction.new :del, :fail, "tag", "comment", nil, "can"
|
||||
action.exception @exception
|
||||
action.after @state
|
||||
end
|
||||
|
||||
it "does not delete a tag if outcome is :pass and the spec failed" do
|
||||
MSpec.should_not_receive(:delete_tag)
|
||||
expect(MSpec).not_to receive(:delete_tag)
|
||||
action = TagAction.new :del, :pass, "tag", "comment", nil, "can"
|
||||
action.exception @exception
|
||||
action.after @state
|
||||
end
|
||||
|
||||
it "deletes a tag if the outcome is :pass and the spec passed" do
|
||||
MSpec.should_receive(:delete_tag).with(@tag)
|
||||
expect(MSpec).to receive(:delete_tag).with(@tag)
|
||||
action = TagAction.new :del, :pass, "tag", "comment", nil, "can"
|
||||
action.after @state
|
||||
end
|
||||
|
||||
it "deletes a tag if the outcome is :all" do
|
||||
MSpec.should_receive(:delete_tag).with(@tag)
|
||||
expect(MSpec).to receive(:delete_tag).with(@tag)
|
||||
action = TagAction.new :del, :all, "tag", "comment", nil, "can"
|
||||
action.after @state
|
||||
end
|
||||
end
|
||||
|
||||
describe TagAction, "#finish" do
|
||||
RSpec.describe TagAction, "#finish" do
|
||||
before :each do
|
||||
$stdout = @out = IOStub.new
|
||||
context = ContextState.new "Catch#me"
|
||||
@state = ExampleState.new context, "if you can"
|
||||
MSpec.stub(:write_tag).and_return(true)
|
||||
MSpec.stub(:delete_tag).and_return(true)
|
||||
allow(MSpec).to receive(:write_tag).and_return(true)
|
||||
allow(MSpec).to receive(:delete_tag).and_return(true)
|
||||
end
|
||||
|
||||
after :each do
|
||||
|
@ -217,99 +217,97 @@ describe TagAction, "#finish" do
|
|||
|
||||
it "reports no specs tagged if none where tagged" do
|
||||
action = TagAction.new :add, :fail, "tag", "comment", nil, "can"
|
||||
action.stub(:outcome?).and_return(false)
|
||||
allow(action).to receive(:outcome?).and_return(false)
|
||||
action.after @state
|
||||
action.finish
|
||||
@out.should == "\nTagAction: no specs were tagged with 'tag'\n"
|
||||
expect(@out).to eq("\nTagAction: no specs were tagged with 'tag'\n")
|
||||
end
|
||||
|
||||
it "reports no specs tagged if none where tagged" do
|
||||
action = TagAction.new :del, :fail, "tag", "comment", nil, "can"
|
||||
action.stub(:outcome?).and_return(false)
|
||||
allow(action).to receive(:outcome?).and_return(false)
|
||||
action.after @state
|
||||
action.finish
|
||||
@out.should == "\nTagAction: no tags 'tag' were deleted\n"
|
||||
expect(@out).to eq("\nTagAction: no tags 'tag' were deleted\n")
|
||||
end
|
||||
|
||||
it "reports the spec descriptions that were tagged" do
|
||||
action = TagAction.new :add, :fail, "tag", "comment", nil, "can"
|
||||
action.stub(:outcome?).and_return(true)
|
||||
allow(action).to receive(:outcome?).and_return(true)
|
||||
action.after @state
|
||||
action.finish
|
||||
@out.should ==
|
||||
%[
|
||||
expect(@out).to eq(%[
|
||||
TagAction: specs tagged with 'tag':
|
||||
|
||||
Catch#me if you can
|
||||
]
|
||||
])
|
||||
end
|
||||
|
||||
it "reports the spec descriptions for the tags that were deleted" do
|
||||
action = TagAction.new :del, :fail, "tag", "comment", nil, "can"
|
||||
action.stub(:outcome?).and_return(true)
|
||||
allow(action).to receive(:outcome?).and_return(true)
|
||||
action.after @state
|
||||
action.finish
|
||||
@out.should ==
|
||||
%[
|
||||
expect(@out).to eq(%[
|
||||
TagAction: tag 'tag' deleted for specs:
|
||||
|
||||
Catch#me if you can
|
||||
]
|
||||
])
|
||||
end
|
||||
end
|
||||
|
||||
describe TagAction, "#register" do
|
||||
RSpec.describe TagAction, "#register" do
|
||||
before :each do
|
||||
MSpec.stub(:register)
|
||||
MSpec.stub(:read_tags).and_return([])
|
||||
allow(MSpec).to receive(:register)
|
||||
allow(MSpec).to receive(:read_tags).and_return([])
|
||||
@action = TagAction.new :add, :all, nil, nil, nil, nil
|
||||
end
|
||||
|
||||
it "registers itself with MSpec for the :before event" do
|
||||
MSpec.should_receive(:register).with(:before, @action)
|
||||
expect(MSpec).to receive(:register).with(:before, @action)
|
||||
@action.register
|
||||
end
|
||||
|
||||
it "registers itself with MSpec for the :after event" do
|
||||
MSpec.should_receive(:register).with(:after, @action)
|
||||
expect(MSpec).to receive(:register).with(:after, @action)
|
||||
@action.register
|
||||
end
|
||||
|
||||
it "registers itself with MSpec for the :exception event" do
|
||||
MSpec.should_receive(:register).with(:exception, @action)
|
||||
expect(MSpec).to receive(:register).with(:exception, @action)
|
||||
@action.register
|
||||
end
|
||||
|
||||
it "registers itself with MSpec for the :finish event" do
|
||||
MSpec.should_receive(:register).with(:finish, @action)
|
||||
expect(MSpec).to receive(:register).with(:finish, @action)
|
||||
@action.register
|
||||
end
|
||||
end
|
||||
|
||||
describe TagAction, "#unregister" do
|
||||
RSpec.describe TagAction, "#unregister" do
|
||||
before :each do
|
||||
MSpec.stub(:unregister)
|
||||
MSpec.stub(:read_tags).and_return([])
|
||||
allow(MSpec).to receive(:unregister)
|
||||
allow(MSpec).to receive(:read_tags).and_return([])
|
||||
@action = TagAction.new :add, :all, nil, nil, nil, nil
|
||||
end
|
||||
|
||||
it "unregisters itself with MSpec for the :before event" do
|
||||
MSpec.should_receive(:unregister).with(:before, @action)
|
||||
expect(MSpec).to receive(:unregister).with(:before, @action)
|
||||
@action.unregister
|
||||
end
|
||||
|
||||
it "unregisters itself with MSpec for the :after event" do
|
||||
MSpec.should_receive(:unregister).with(:after, @action)
|
||||
expect(MSpec).to receive(:unregister).with(:after, @action)
|
||||
@action.unregister
|
||||
end
|
||||
|
||||
it "unregisters itself with MSpec for the :exception event" do
|
||||
MSpec.should_receive(:unregister).with(:exception, @action)
|
||||
expect(MSpec).to receive(:unregister).with(:exception, @action)
|
||||
@action.unregister
|
||||
end
|
||||
|
||||
it "unregisters itself with MSpec for the :finish event" do
|
||||
MSpec.should_receive(:unregister).with(:finish, @action)
|
||||
expect(MSpec).to receive(:unregister).with(:finish, @action)
|
||||
@action.unregister
|
||||
end
|
||||
end
|
||||
|
|
|
@ -4,34 +4,34 @@ require 'mspec/runner/mspec'
|
|||
require 'mspec/runner/example'
|
||||
require 'mspec/runner/tag'
|
||||
|
||||
describe TagListAction, "#include?" do
|
||||
RSpec.describe TagListAction, "#include?" do
|
||||
it "returns true" do
|
||||
TagListAction.new.include?(:anything).should be_true
|
||||
expect(TagListAction.new.include?(:anything)).to be_truthy
|
||||
end
|
||||
end
|
||||
|
||||
describe TagListAction, "#===" do
|
||||
RSpec.describe TagListAction, "#===" do
|
||||
before :each do
|
||||
tag = SpecTag.new "fails:description"
|
||||
MSpec.stub(:read_tags).and_return([tag])
|
||||
allow(MSpec).to receive(:read_tags).and_return([tag])
|
||||
@filter = double("MatchFilter").as_null_object
|
||||
MatchFilter.stub(:new).and_return(@filter)
|
||||
allow(MatchFilter).to receive(:new).and_return(@filter)
|
||||
@action = TagListAction.new
|
||||
@action.load
|
||||
end
|
||||
|
||||
it "returns true if filter === string returns true" do
|
||||
@filter.should_receive(:===).with("str").and_return(true)
|
||||
@action.===("str").should be_true
|
||||
expect(@filter).to receive(:===).with("str").and_return(true)
|
||||
expect(@action.===("str")).to be_truthy
|
||||
end
|
||||
|
||||
it "returns false if filter === string returns false" do
|
||||
@filter.should_receive(:===).with("str").and_return(false)
|
||||
@action.===("str").should be_false
|
||||
expect(@filter).to receive(:===).with("str").and_return(false)
|
||||
expect(@action.===("str")).to be_falsey
|
||||
end
|
||||
end
|
||||
|
||||
describe TagListAction, "#start" do
|
||||
RSpec.describe TagListAction, "#start" do
|
||||
before :each do
|
||||
@stdout = $stdout
|
||||
$stdout = IOStub.new
|
||||
|
@ -44,48 +44,48 @@ describe TagListAction, "#start" do
|
|||
it "prints a banner for specific tags" do
|
||||
action = TagListAction.new ["fails", "unstable"]
|
||||
action.start
|
||||
$stdout.should == "\nListing specs tagged with 'fails', 'unstable'\n\n"
|
||||
expect($stdout).to eq("\nListing specs tagged with 'fails', 'unstable'\n\n")
|
||||
end
|
||||
|
||||
it "prints a banner for all tags" do
|
||||
action = TagListAction.new
|
||||
action.start
|
||||
$stdout.should == "\nListing all tagged specs\n\n"
|
||||
expect($stdout).to eq("\nListing all tagged specs\n\n")
|
||||
end
|
||||
end
|
||||
|
||||
describe TagListAction, "#load" do
|
||||
RSpec.describe TagListAction, "#load" do
|
||||
before :each do
|
||||
@t1 = SpecTag.new "fails:I fail"
|
||||
@t2 = SpecTag.new "unstable:I'm unstable"
|
||||
end
|
||||
|
||||
it "creates a MatchFilter for matching tags" do
|
||||
MSpec.should_receive(:read_tags).with(["fails"]).and_return([@t1])
|
||||
MatchFilter.should_receive(:new).with(nil, "I fail")
|
||||
expect(MSpec).to receive(:read_tags).with(["fails"]).and_return([@t1])
|
||||
expect(MatchFilter).to receive(:new).with(nil, "I fail")
|
||||
TagListAction.new(["fails"]).load
|
||||
end
|
||||
|
||||
it "creates a MatchFilter for all tags" do
|
||||
MSpec.should_receive(:read_tags).and_return([@t1, @t2])
|
||||
MatchFilter.should_receive(:new).with(nil, "I fail", "I'm unstable")
|
||||
expect(MSpec).to receive(:read_tags).and_return([@t1, @t2])
|
||||
expect(MatchFilter).to receive(:new).with(nil, "I fail", "I'm unstable")
|
||||
TagListAction.new.load
|
||||
end
|
||||
|
||||
it "does not create a MatchFilter if there are no matching tags" do
|
||||
MSpec.stub(:read_tags).and_return([])
|
||||
MatchFilter.should_not_receive(:new)
|
||||
allow(MSpec).to receive(:read_tags).and_return([])
|
||||
expect(MatchFilter).not_to receive(:new)
|
||||
TagListAction.new(["fails"]).load
|
||||
end
|
||||
end
|
||||
|
||||
describe TagListAction, "#after" do
|
||||
RSpec.describe TagListAction, "#after" do
|
||||
before :each do
|
||||
@stdout = $stdout
|
||||
$stdout = IOStub.new
|
||||
|
||||
@state = double("ExampleState")
|
||||
@state.stub(:description).and_return("str")
|
||||
allow(@state).to receive(:description).and_return("str")
|
||||
|
||||
@action = TagListAction.new
|
||||
end
|
||||
|
@ -95,58 +95,58 @@ describe TagListAction, "#after" do
|
|||
end
|
||||
|
||||
it "prints nothing if the filter does not match" do
|
||||
@action.should_receive(:===).with("str").and_return(false)
|
||||
expect(@action).to receive(:===).with("str").and_return(false)
|
||||
@action.after(@state)
|
||||
$stdout.should == ""
|
||||
expect($stdout).to eq("")
|
||||
end
|
||||
|
||||
it "prints the example description if the filter matches" do
|
||||
@action.should_receive(:===).with("str").and_return(true)
|
||||
expect(@action).to receive(:===).with("str").and_return(true)
|
||||
@action.after(@state)
|
||||
$stdout.should == "str\n"
|
||||
expect($stdout).to eq("str\n")
|
||||
end
|
||||
end
|
||||
|
||||
describe TagListAction, "#register" do
|
||||
RSpec.describe TagListAction, "#register" do
|
||||
before :each do
|
||||
MSpec.stub(:register)
|
||||
allow(MSpec).to receive(:register)
|
||||
@action = TagListAction.new
|
||||
end
|
||||
|
||||
it "registers itself with MSpec for the :start event" do
|
||||
MSpec.should_receive(:register).with(:start, @action)
|
||||
expect(MSpec).to receive(:register).with(:start, @action)
|
||||
@action.register
|
||||
end
|
||||
|
||||
it "registers itself with MSpec for the :load event" do
|
||||
MSpec.should_receive(:register).with(:load, @action)
|
||||
expect(MSpec).to receive(:register).with(:load, @action)
|
||||
@action.register
|
||||
end
|
||||
|
||||
it "registers itself with MSpec for the :after event" do
|
||||
MSpec.should_receive(:register).with(:after, @action)
|
||||
expect(MSpec).to receive(:register).with(:after, @action)
|
||||
@action.register
|
||||
end
|
||||
end
|
||||
|
||||
describe TagListAction, "#unregister" do
|
||||
RSpec.describe TagListAction, "#unregister" do
|
||||
before :each do
|
||||
MSpec.stub(:unregister)
|
||||
allow(MSpec).to receive(:unregister)
|
||||
@action = TagListAction.new
|
||||
end
|
||||
|
||||
it "unregisters itself with MSpec for the :start event" do
|
||||
MSpec.should_receive(:unregister).with(:start, @action)
|
||||
expect(MSpec).to receive(:unregister).with(:start, @action)
|
||||
@action.unregister
|
||||
end
|
||||
|
||||
it "unregisters itself with MSpec for the :load event" do
|
||||
MSpec.should_receive(:unregister).with(:load, @action)
|
||||
expect(MSpec).to receive(:unregister).with(:load, @action)
|
||||
@action.unregister
|
||||
end
|
||||
|
||||
it "unregisters itself with MSpec for the :after event" do
|
||||
MSpec.should_receive(:unregister).with(:after, @action)
|
||||
expect(MSpec).to receive(:unregister).with(:after, @action)
|
||||
@action.unregister
|
||||
end
|
||||
end
|
||||
|
|
|
@ -4,7 +4,7 @@ require 'mspec/runner/mspec'
|
|||
require 'mspec/runner/example'
|
||||
require 'mspec/runner/tag'
|
||||
|
||||
describe TagPurgeAction, "#start" do
|
||||
RSpec.describe TagPurgeAction, "#start" do
|
||||
before :each do
|
||||
@stdout = $stdout
|
||||
$stdout = IOStub.new
|
||||
|
@ -17,45 +17,45 @@ describe TagPurgeAction, "#start" do
|
|||
it "prints a banner" do
|
||||
action = TagPurgeAction.new
|
||||
action.start
|
||||
$stdout.should == "\nRemoving tags not matching any specs\n\n"
|
||||
expect($stdout).to eq("\nRemoving tags not matching any specs\n\n")
|
||||
end
|
||||
end
|
||||
|
||||
describe TagPurgeAction, "#load" do
|
||||
RSpec.describe TagPurgeAction, "#load" do
|
||||
before :each do
|
||||
@t1 = SpecTag.new "fails:I fail"
|
||||
@t2 = SpecTag.new "unstable:I'm unstable"
|
||||
end
|
||||
|
||||
it "creates a MatchFilter for all tags" do
|
||||
MSpec.should_receive(:read_tags).and_return([@t1, @t2])
|
||||
MatchFilter.should_receive(:new).with(nil, "I fail", "I'm unstable")
|
||||
expect(MSpec).to receive(:read_tags).and_return([@t1, @t2])
|
||||
expect(MatchFilter).to receive(:new).with(nil, "I fail", "I'm unstable")
|
||||
TagPurgeAction.new.load
|
||||
end
|
||||
end
|
||||
|
||||
describe TagPurgeAction, "#after" do
|
||||
RSpec.describe TagPurgeAction, "#after" do
|
||||
before :each do
|
||||
@state = double("ExampleState")
|
||||
@state.stub(:description).and_return("str")
|
||||
allow(@state).to receive(:description).and_return("str")
|
||||
|
||||
@action = TagPurgeAction.new
|
||||
end
|
||||
|
||||
it "does not save the description if the filter does not match" do
|
||||
@action.should_receive(:===).with("str").and_return(false)
|
||||
expect(@action).to receive(:===).with("str").and_return(false)
|
||||
@action.after @state
|
||||
@action.matching.should == []
|
||||
expect(@action.matching).to eq([])
|
||||
end
|
||||
|
||||
it "saves the description if the filter matches" do
|
||||
@action.should_receive(:===).with("str").and_return(true)
|
||||
expect(@action).to receive(:===).with("str").and_return(true)
|
||||
@action.after @state
|
||||
@action.matching.should == ["str"]
|
||||
expect(@action.matching).to eq(["str"])
|
||||
end
|
||||
end
|
||||
|
||||
describe TagPurgeAction, "#unload" do
|
||||
RSpec.describe TagPurgeAction, "#unload" do
|
||||
before :each do
|
||||
@stdout = $stdout
|
||||
$stdout = IOStub.new
|
||||
|
@ -64,11 +64,11 @@ describe TagPurgeAction, "#unload" do
|
|||
@t2 = SpecTag.new "unstable:I'm unstable"
|
||||
@t3 = SpecTag.new "fails:I'm unstable"
|
||||
|
||||
MSpec.stub(:read_tags).and_return([@t1, @t2, @t3])
|
||||
MSpec.stub(:write_tags)
|
||||
allow(MSpec).to receive(:read_tags).and_return([@t1, @t2, @t3])
|
||||
allow(MSpec).to receive(:write_tags)
|
||||
|
||||
@state = double("ExampleState")
|
||||
@state.stub(:description).and_return("I'm unstable")
|
||||
allow(@state).to receive(:description).and_return("I'm unstable")
|
||||
|
||||
@action = TagPurgeAction.new
|
||||
@action.load
|
||||
|
@ -80,37 +80,37 @@ describe TagPurgeAction, "#unload" do
|
|||
end
|
||||
|
||||
it "does not rewrite any tags if there were no tags for the specs" do
|
||||
MSpec.should_receive(:read_tags).and_return([])
|
||||
MSpec.should_receive(:delete_tags)
|
||||
MSpec.should_not_receive(:write_tags)
|
||||
expect(MSpec).to receive(:read_tags).and_return([])
|
||||
expect(MSpec).to receive(:delete_tags)
|
||||
expect(MSpec).not_to receive(:write_tags)
|
||||
|
||||
@action.load
|
||||
@action.after @state
|
||||
@action.unload
|
||||
|
||||
$stdout.should == ""
|
||||
expect($stdout).to eq("")
|
||||
end
|
||||
|
||||
it "rewrites tags that were matched" do
|
||||
MSpec.should_receive(:write_tags).with([@t2, @t3])
|
||||
expect(MSpec).to receive(:write_tags).with([@t2, @t3])
|
||||
@action.unload
|
||||
end
|
||||
|
||||
it "prints tags that were not matched" do
|
||||
@action.unload
|
||||
$stdout.should == "I fail\n"
|
||||
expect($stdout).to eq("I fail\n")
|
||||
end
|
||||
end
|
||||
|
||||
describe TagPurgeAction, "#unload" do
|
||||
RSpec.describe TagPurgeAction, "#unload" do
|
||||
before :each do
|
||||
@stdout = $stdout
|
||||
$stdout = IOStub.new
|
||||
|
||||
MSpec.stub(:read_tags).and_return([])
|
||||
allow(MSpec).to receive(:read_tags).and_return([])
|
||||
|
||||
@state = double("ExampleState")
|
||||
@state.stub(:description).and_return("I'm unstable")
|
||||
allow(@state).to receive(:description).and_return("I'm unstable")
|
||||
|
||||
@action = TagPurgeAction.new
|
||||
@action.load
|
||||
|
@ -122,33 +122,33 @@ describe TagPurgeAction, "#unload" do
|
|||
end
|
||||
|
||||
it "deletes the tag file if no tags were found" do
|
||||
MSpec.should_not_receive(:write_tags)
|
||||
MSpec.should_receive(:delete_tags)
|
||||
expect(MSpec).not_to receive(:write_tags)
|
||||
expect(MSpec).to receive(:delete_tags)
|
||||
@action.unload
|
||||
$stdout.should == ""
|
||||
expect($stdout).to eq("")
|
||||
end
|
||||
end
|
||||
|
||||
describe TagPurgeAction, "#register" do
|
||||
RSpec.describe TagPurgeAction, "#register" do
|
||||
before :each do
|
||||
MSpec.stub(:register)
|
||||
allow(MSpec).to receive(:register)
|
||||
@action = TagPurgeAction.new
|
||||
end
|
||||
|
||||
it "registers itself with MSpec for the :unload event" do
|
||||
MSpec.should_receive(:register).with(:unload, @action)
|
||||
expect(MSpec).to receive(:register).with(:unload, @action)
|
||||
@action.register
|
||||
end
|
||||
end
|
||||
|
||||
describe TagPurgeAction, "#unregister" do
|
||||
RSpec.describe TagPurgeAction, "#unregister" do
|
||||
before :each do
|
||||
MSpec.stub(:unregister)
|
||||
allow(MSpec).to receive(:unregister)
|
||||
@action = TagPurgeAction.new
|
||||
end
|
||||
|
||||
it "unregisters itself with MSpec for the :unload event" do
|
||||
MSpec.should_receive(:unregister).with(:unload, @action)
|
||||
expect(MSpec).to receive(:unregister).with(:unload, @action)
|
||||
@action.unregister
|
||||
end
|
||||
end
|
||||
|
|
|
@ -4,169 +4,169 @@ require 'mspec/runner/actions/tally'
|
|||
require 'mspec/runner/mspec'
|
||||
require 'mspec/runner/example'
|
||||
|
||||
describe Tally, "#files!" do
|
||||
RSpec.describe Tally, "#files!" do
|
||||
before :each do
|
||||
@tally = Tally.new
|
||||
end
|
||||
|
||||
it "increments the count returned by #files" do
|
||||
@tally.files! 3
|
||||
@tally.files.should == 3
|
||||
expect(@tally.files).to eq(3)
|
||||
@tally.files!
|
||||
@tally.files.should == 4
|
||||
expect(@tally.files).to eq(4)
|
||||
end
|
||||
end
|
||||
|
||||
describe Tally, "#examples!" do
|
||||
RSpec.describe Tally, "#examples!" do
|
||||
before :each do
|
||||
@tally = Tally.new
|
||||
end
|
||||
|
||||
it "increments the count returned by #examples" do
|
||||
@tally.examples! 2
|
||||
@tally.examples.should == 2
|
||||
expect(@tally.examples).to eq(2)
|
||||
@tally.examples! 2
|
||||
@tally.examples.should == 4
|
||||
expect(@tally.examples).to eq(4)
|
||||
end
|
||||
end
|
||||
|
||||
describe Tally, "#expectations!" do
|
||||
RSpec.describe Tally, "#expectations!" do
|
||||
before :each do
|
||||
@tally = Tally.new
|
||||
end
|
||||
|
||||
it "increments the count returned by #expectations" do
|
||||
@tally.expectations!
|
||||
@tally.expectations.should == 1
|
||||
expect(@tally.expectations).to eq(1)
|
||||
@tally.expectations! 3
|
||||
@tally.expectations.should == 4
|
||||
expect(@tally.expectations).to eq(4)
|
||||
end
|
||||
end
|
||||
|
||||
describe Tally, "#failures!" do
|
||||
RSpec.describe Tally, "#failures!" do
|
||||
before :each do
|
||||
@tally = Tally.new
|
||||
end
|
||||
|
||||
it "increments the count returned by #failures" do
|
||||
@tally.failures! 1
|
||||
@tally.failures.should == 1
|
||||
expect(@tally.failures).to eq(1)
|
||||
@tally.failures!
|
||||
@tally.failures.should == 2
|
||||
expect(@tally.failures).to eq(2)
|
||||
end
|
||||
end
|
||||
|
||||
describe Tally, "#errors!" do
|
||||
RSpec.describe Tally, "#errors!" do
|
||||
before :each do
|
||||
@tally = Tally.new
|
||||
end
|
||||
|
||||
it "increments the count returned by #errors" do
|
||||
@tally.errors!
|
||||
@tally.errors.should == 1
|
||||
expect(@tally.errors).to eq(1)
|
||||
@tally.errors! 2
|
||||
@tally.errors.should == 3
|
||||
expect(@tally.errors).to eq(3)
|
||||
end
|
||||
end
|
||||
|
||||
describe Tally, "#guards!" do
|
||||
RSpec.describe Tally, "#guards!" do
|
||||
before :each do
|
||||
@tally = Tally.new
|
||||
end
|
||||
|
||||
it "increments the count returned by #guards" do
|
||||
@tally.guards!
|
||||
@tally.guards.should == 1
|
||||
expect(@tally.guards).to eq(1)
|
||||
@tally.guards! 2
|
||||
@tally.guards.should == 3
|
||||
expect(@tally.guards).to eq(3)
|
||||
end
|
||||
end
|
||||
|
||||
describe Tally, "#file" do
|
||||
RSpec.describe Tally, "#file" do
|
||||
before :each do
|
||||
@tally = Tally.new
|
||||
end
|
||||
|
||||
it "returns a formatted string of the number of #files" do
|
||||
@tally.file.should == "0 files"
|
||||
expect(@tally.file).to eq("0 files")
|
||||
@tally.files!
|
||||
@tally.file.should == "1 file"
|
||||
expect(@tally.file).to eq("1 file")
|
||||
@tally.files!
|
||||
@tally.file.should == "2 files"
|
||||
expect(@tally.file).to eq("2 files")
|
||||
end
|
||||
end
|
||||
|
||||
describe Tally, "#example" do
|
||||
RSpec.describe Tally, "#example" do
|
||||
before :each do
|
||||
@tally = Tally.new
|
||||
end
|
||||
|
||||
it "returns a formatted string of the number of #examples" do
|
||||
@tally.example.should == "0 examples"
|
||||
expect(@tally.example).to eq("0 examples")
|
||||
@tally.examples!
|
||||
@tally.example.should == "1 example"
|
||||
expect(@tally.example).to eq("1 example")
|
||||
@tally.examples!
|
||||
@tally.example.should == "2 examples"
|
||||
expect(@tally.example).to eq("2 examples")
|
||||
end
|
||||
end
|
||||
|
||||
describe Tally, "#expectation" do
|
||||
RSpec.describe Tally, "#expectation" do
|
||||
before :each do
|
||||
@tally = Tally.new
|
||||
end
|
||||
|
||||
it "returns a formatted string of the number of #expectations" do
|
||||
@tally.expectation.should == "0 expectations"
|
||||
expect(@tally.expectation).to eq("0 expectations")
|
||||
@tally.expectations!
|
||||
@tally.expectation.should == "1 expectation"
|
||||
expect(@tally.expectation).to eq("1 expectation")
|
||||
@tally.expectations!
|
||||
@tally.expectation.should == "2 expectations"
|
||||
expect(@tally.expectation).to eq("2 expectations")
|
||||
end
|
||||
end
|
||||
|
||||
describe Tally, "#failure" do
|
||||
RSpec.describe Tally, "#failure" do
|
||||
before :each do
|
||||
@tally = Tally.new
|
||||
end
|
||||
|
||||
it "returns a formatted string of the number of #failures" do
|
||||
@tally.failure.should == "0 failures"
|
||||
expect(@tally.failure).to eq("0 failures")
|
||||
@tally.failures!
|
||||
@tally.failure.should == "1 failure"
|
||||
expect(@tally.failure).to eq("1 failure")
|
||||
@tally.failures!
|
||||
@tally.failure.should == "2 failures"
|
||||
expect(@tally.failure).to eq("2 failures")
|
||||
end
|
||||
end
|
||||
|
||||
describe Tally, "#error" do
|
||||
RSpec.describe Tally, "#error" do
|
||||
before :each do
|
||||
@tally = Tally.new
|
||||
end
|
||||
|
||||
it "returns a formatted string of the number of #errors" do
|
||||
@tally.error.should == "0 errors"
|
||||
expect(@tally.error).to eq("0 errors")
|
||||
@tally.errors!
|
||||
@tally.error.should == "1 error"
|
||||
expect(@tally.error).to eq("1 error")
|
||||
@tally.errors!
|
||||
@tally.error.should == "2 errors"
|
||||
expect(@tally.error).to eq("2 errors")
|
||||
end
|
||||
end
|
||||
|
||||
describe Tally, "#guard" do
|
||||
RSpec.describe Tally, "#guard" do
|
||||
before :each do
|
||||
@tally = Tally.new
|
||||
end
|
||||
|
||||
it "returns a formatted string of the number of #guards" do
|
||||
@tally.guard.should == "0 guards"
|
||||
expect(@tally.guard).to eq("0 guards")
|
||||
@tally.guards!
|
||||
@tally.guard.should == "1 guard"
|
||||
expect(@tally.guard).to eq("1 guard")
|
||||
@tally.guards!
|
||||
@tally.guard.should == "2 guards"
|
||||
expect(@tally.guard).to eq("2 guards")
|
||||
end
|
||||
end
|
||||
|
||||
describe Tally, "#format" do
|
||||
RSpec.describe Tally, "#format" do
|
||||
before :each do
|
||||
@tally = Tally.new
|
||||
end
|
||||
|
@ -181,7 +181,7 @@ describe Tally, "#format" do
|
|||
@tally.expectations! 4
|
||||
@tally.errors!
|
||||
@tally.tagged!
|
||||
@tally.format.should == "1 file, 2 examples, 4 expectations, 0 failures, 1 error, 1 tagged"
|
||||
expect(@tally.format).to eq("1 file, 2 examples, 4 expectations, 0 failures, 1 error, 1 tagged")
|
||||
end
|
||||
|
||||
it "includes guards if MSpec is in verify mode" do
|
||||
|
@ -192,8 +192,9 @@ describe Tally, "#format" do
|
|||
@tally.errors!
|
||||
@tally.tagged!
|
||||
@tally.guards!
|
||||
@tally.format.should ==
|
||||
expect(@tally.format).to eq(
|
||||
"1 file, 2 examples, 4 expectations, 0 failures, 1 error, 1 tagged, 1 guard"
|
||||
)
|
||||
end
|
||||
|
||||
it "includes guards if MSpec is in report mode" do
|
||||
|
@ -204,8 +205,9 @@ describe Tally, "#format" do
|
|||
@tally.errors!
|
||||
@tally.tagged!
|
||||
@tally.guards! 2
|
||||
@tally.format.should ==
|
||||
expect(@tally.format).to eq(
|
||||
"1 file, 2 examples, 4 expectations, 0 failures, 1 error, 1 tagged, 2 guards"
|
||||
)
|
||||
end
|
||||
|
||||
it "includes guards if MSpec is in report_on mode" do
|
||||
|
@ -215,23 +217,24 @@ describe Tally, "#format" do
|
|||
@tally.expectations! 4
|
||||
@tally.errors!
|
||||
@tally.guards! 2
|
||||
@tally.format.should ==
|
||||
expect(@tally.format).to eq(
|
||||
"1 file, 2 examples, 4 expectations, 0 failures, 1 error, 0 tagged, 2 guards"
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
describe TallyAction, "#counter" do
|
||||
RSpec.describe TallyAction, "#counter" do
|
||||
before :each do
|
||||
@tally = TallyAction.new
|
||||
@state = ExampleState.new("describe", "it")
|
||||
end
|
||||
|
||||
it "returns the Tally object" do
|
||||
@tally.counter.should be_kind_of(Tally)
|
||||
expect(@tally.counter).to be_kind_of(Tally)
|
||||
end
|
||||
end
|
||||
|
||||
describe TallyAction, "#load" do
|
||||
RSpec.describe TallyAction, "#load" do
|
||||
before :each do
|
||||
@tally = TallyAction.new
|
||||
@state = ExampleState.new("describe", "it")
|
||||
|
@ -239,11 +242,11 @@ describe TallyAction, "#load" do
|
|||
|
||||
it "increments the count returned by Tally#files" do
|
||||
@tally.load
|
||||
@tally.counter.files.should == 1
|
||||
expect(@tally.counter.files).to eq(1)
|
||||
end
|
||||
end
|
||||
|
||||
describe TallyAction, "#expectation" do
|
||||
RSpec.describe TallyAction, "#expectation" do
|
||||
before :each do
|
||||
@tally = TallyAction.new
|
||||
@state = ExampleState.new("describe", "it")
|
||||
|
@ -251,11 +254,11 @@ describe TallyAction, "#expectation" do
|
|||
|
||||
it "increments the count returned by Tally#expectations" do
|
||||
@tally.expectation @state
|
||||
@tally.counter.expectations.should == 1
|
||||
expect(@tally.counter.expectations).to eq(1)
|
||||
end
|
||||
end
|
||||
|
||||
describe TallyAction, "#example" do
|
||||
RSpec.describe TallyAction, "#example" do
|
||||
before :each do
|
||||
@tally = TallyAction.new
|
||||
@state = ExampleState.new("describe", "it")
|
||||
|
@ -263,14 +266,14 @@ describe TallyAction, "#example" do
|
|||
|
||||
it "increments counts returned by Tally#examples" do
|
||||
@tally.example @state, nil
|
||||
@tally.counter.examples.should == 1
|
||||
@tally.counter.expectations.should == 0
|
||||
@tally.counter.failures.should == 0
|
||||
@tally.counter.errors.should == 0
|
||||
expect(@tally.counter.examples).to eq(1)
|
||||
expect(@tally.counter.expectations).to eq(0)
|
||||
expect(@tally.counter.failures).to eq(0)
|
||||
expect(@tally.counter.errors).to eq(0)
|
||||
end
|
||||
end
|
||||
|
||||
describe TallyAction, "#exception" do
|
||||
RSpec.describe TallyAction, "#exception" do
|
||||
before :each do
|
||||
@tally = TallyAction.new
|
||||
@state = ExampleState.new("describe", "it")
|
||||
|
@ -279,14 +282,14 @@ describe TallyAction, "#exception" do
|
|||
it "increments counts returned by Tally#failures" do
|
||||
exc = ExceptionState.new nil, nil, SpecExpectationNotMetError.new("Failed!")
|
||||
@tally.exception exc
|
||||
@tally.counter.examples.should == 0
|
||||
@tally.counter.expectations.should == 0
|
||||
@tally.counter.failures.should == 1
|
||||
@tally.counter.errors.should == 0
|
||||
expect(@tally.counter.examples).to eq(0)
|
||||
expect(@tally.counter.expectations).to eq(0)
|
||||
expect(@tally.counter.failures).to eq(1)
|
||||
expect(@tally.counter.errors).to eq(0)
|
||||
end
|
||||
end
|
||||
|
||||
describe TallyAction, "#exception" do
|
||||
RSpec.describe TallyAction, "#exception" do
|
||||
before :each do
|
||||
@tally = TallyAction.new
|
||||
@state = ExampleState.new("describe", "it")
|
||||
|
@ -295,14 +298,14 @@ describe TallyAction, "#exception" do
|
|||
it "increments counts returned by Tally#errors" do
|
||||
exc = ExceptionState.new nil, nil, Exception.new("Error!")
|
||||
@tally.exception exc
|
||||
@tally.counter.examples.should == 0
|
||||
@tally.counter.expectations.should == 0
|
||||
@tally.counter.failures.should == 0
|
||||
@tally.counter.errors.should == 1
|
||||
expect(@tally.counter.examples).to eq(0)
|
||||
expect(@tally.counter.expectations).to eq(0)
|
||||
expect(@tally.counter.failures).to eq(0)
|
||||
expect(@tally.counter.errors).to eq(1)
|
||||
end
|
||||
end
|
||||
|
||||
describe TallyAction, "#format" do
|
||||
RSpec.describe TallyAction, "#format" do
|
||||
before :each do
|
||||
@tally = TallyAction.new
|
||||
@state = ExampleState.new("describe", "it")
|
||||
|
@ -315,38 +318,38 @@ describe TallyAction, "#format" do
|
|||
@tally.expectation @state
|
||||
exc = ExceptionState.new nil, nil, SpecExpectationNotMetError.new("Failed!")
|
||||
@tally.exception exc
|
||||
@tally.format.should == "1 file, 1 example, 2 expectations, 1 failure, 0 errors, 0 tagged"
|
||||
expect(@tally.format).to eq("1 file, 1 example, 2 expectations, 1 failure, 0 errors, 0 tagged")
|
||||
end
|
||||
end
|
||||
|
||||
describe TallyAction, "#register" do
|
||||
RSpec.describe TallyAction, "#register" do
|
||||
before :each do
|
||||
@tally = TallyAction.new
|
||||
@state = ExampleState.new("describe", "it")
|
||||
end
|
||||
|
||||
it "registers itself with MSpec for appropriate actions" do
|
||||
MSpec.should_receive(:register).with(:load, @tally)
|
||||
MSpec.should_receive(:register).with(:exception, @tally)
|
||||
MSpec.should_receive(:register).with(:example, @tally)
|
||||
MSpec.should_receive(:register).with(:tagged, @tally)
|
||||
MSpec.should_receive(:register).with(:expectation, @tally)
|
||||
expect(MSpec).to receive(:register).with(:load, @tally)
|
||||
expect(MSpec).to receive(:register).with(:exception, @tally)
|
||||
expect(MSpec).to receive(:register).with(:example, @tally)
|
||||
expect(MSpec).to receive(:register).with(:tagged, @tally)
|
||||
expect(MSpec).to receive(:register).with(:expectation, @tally)
|
||||
@tally.register
|
||||
end
|
||||
end
|
||||
|
||||
describe TallyAction, "#unregister" do
|
||||
RSpec.describe TallyAction, "#unregister" do
|
||||
before :each do
|
||||
@tally = TallyAction.new
|
||||
@state = ExampleState.new("describe", "it")
|
||||
end
|
||||
|
||||
it "unregisters itself with MSpec for appropriate actions" do
|
||||
MSpec.should_receive(:unregister).with(:load, @tally)
|
||||
MSpec.should_receive(:unregister).with(:exception, @tally)
|
||||
MSpec.should_receive(:unregister).with(:example, @tally)
|
||||
MSpec.should_receive(:unregister).with(:tagged, @tally)
|
||||
MSpec.should_receive(:unregister).with(:expectation, @tally)
|
||||
expect(MSpec).to receive(:unregister).with(:load, @tally)
|
||||
expect(MSpec).to receive(:unregister).with(:exception, @tally)
|
||||
expect(MSpec).to receive(:unregister).with(:example, @tally)
|
||||
expect(MSpec).to receive(:unregister).with(:tagged, @tally)
|
||||
expect(MSpec).to receive(:unregister).with(:expectation, @tally)
|
||||
@tally.unregister
|
||||
end
|
||||
end
|
||||
|
|
|
@ -3,7 +3,7 @@ require 'mspec/runner/actions/timer'
|
|||
require 'mspec/runner/mspec'
|
||||
require 'time'
|
||||
|
||||
describe TimerAction do
|
||||
RSpec.describe TimerAction do
|
||||
before :each do
|
||||
@timer = TimerAction.new
|
||||
@start_time = Time.utc(2009, 3, 30, 14, 5, 19)
|
||||
|
@ -11,34 +11,34 @@ describe TimerAction do
|
|||
end
|
||||
|
||||
it "responds to #start by recording the current time" do
|
||||
Time.should_receive(:now)
|
||||
expect(Time).to receive(:now)
|
||||
@timer.start
|
||||
end
|
||||
|
||||
it "responds to #finish by recording the current time" do
|
||||
Time.should_receive(:now)
|
||||
expect(Time).to receive(:now)
|
||||
@timer.finish
|
||||
end
|
||||
|
||||
it "responds to #elapsed by returning the difference between stop and start" do
|
||||
Time.stub(:now).and_return(@start_time)
|
||||
allow(Time).to receive(:now).and_return(@start_time)
|
||||
@timer.start
|
||||
Time.stub(:now).and_return(@stop_time)
|
||||
allow(Time).to receive(:now).and_return(@stop_time)
|
||||
@timer.finish
|
||||
@timer.elapsed.should == 33
|
||||
expect(@timer.elapsed).to eq(33)
|
||||
end
|
||||
|
||||
it "responds to #format by returning a readable string of elapsed time" do
|
||||
Time.stub(:now).and_return(@start_time)
|
||||
allow(Time).to receive(:now).and_return(@start_time)
|
||||
@timer.start
|
||||
Time.stub(:now).and_return(@stop_time)
|
||||
allow(Time).to receive(:now).and_return(@stop_time)
|
||||
@timer.finish
|
||||
@timer.format.should == "Finished in 33.000000 seconds"
|
||||
expect(@timer.format).to eq("Finished in 33.000000 seconds")
|
||||
end
|
||||
|
||||
it "responds to #register by registering itself with MSpec for appropriate actions" do
|
||||
MSpec.should_receive(:register).with(:start, @timer)
|
||||
MSpec.should_receive(:register).with(:finish, @timer)
|
||||
expect(MSpec).to receive(:register).with(:start, @timer)
|
||||
expect(MSpec).to receive(:register).with(:finish, @timer)
|
||||
@timer.register
|
||||
end
|
||||
end
|
||||
|
|
|
@ -6,7 +6,7 @@ require 'mspec/mocks/mock'
|
|||
require 'mspec/runner/context'
|
||||
require 'mspec/runner/example'
|
||||
|
||||
describe ContextState, "#describe" do
|
||||
RSpec.describe ContextState, "#describe" do
|
||||
before :each do
|
||||
@state = ContextState.new "C#m"
|
||||
@proc = proc { ScratchPad.record :a }
|
||||
|
@ -15,63 +15,63 @@ describe ContextState, "#describe" do
|
|||
|
||||
it "evaluates the passed block" do
|
||||
@state.describe(&@proc)
|
||||
ScratchPad.recorded.should == :a
|
||||
expect(ScratchPad.recorded).to eq(:a)
|
||||
end
|
||||
|
||||
it "evaluates the passed block via #protect" do
|
||||
@state.should_receive(:protect).with("C#m", @proc, false)
|
||||
expect(@state).to receive(:protect).with("C#m", @proc, false)
|
||||
@state.describe(&@proc)
|
||||
end
|
||||
|
||||
it "registers #parent as the current MSpec ContextState" do
|
||||
parent = ContextState.new ""
|
||||
@state.parent = parent
|
||||
MSpec.should_receive(:register_current).with(parent)
|
||||
expect(MSpec).to receive(:register_current).with(parent)
|
||||
@state.describe { }
|
||||
end
|
||||
|
||||
it "registers self with MSpec when #shared? is true" do
|
||||
state = ContextState.new "something shared", :shared => true
|
||||
MSpec.should_receive(:register_shared).with(state)
|
||||
expect(MSpec).to receive(:register_shared).with(state)
|
||||
state.describe { }
|
||||
end
|
||||
end
|
||||
|
||||
describe ContextState, "#shared?" do
|
||||
RSpec.describe ContextState, "#shared?" do
|
||||
it "returns false when the ContextState is not shared" do
|
||||
ContextState.new("").shared?.should be_false
|
||||
expect(ContextState.new("").shared?).to be_falsey
|
||||
end
|
||||
|
||||
it "returns true when the ContextState is shared" do
|
||||
ContextState.new("", {:shared => true}).shared?.should be_true
|
||||
expect(ContextState.new("", {:shared => true}).shared?).to be_truthy
|
||||
end
|
||||
end
|
||||
|
||||
describe ContextState, "#to_s" do
|
||||
RSpec.describe ContextState, "#to_s" do
|
||||
it "returns a description string for self when passed a Module" do
|
||||
ContextState.new(Object).to_s.should == "Object"
|
||||
expect(ContextState.new(Object).to_s).to eq("Object")
|
||||
end
|
||||
|
||||
it "returns a description string for self when passed a String" do
|
||||
ContextState.new("SomeClass").to_s.should == "SomeClass"
|
||||
expect(ContextState.new("SomeClass").to_s).to eq("SomeClass")
|
||||
end
|
||||
end
|
||||
|
||||
describe ContextState, "#description" do
|
||||
RSpec.describe ContextState, "#description" do
|
||||
before :each do
|
||||
@state = ContextState.new "when empty"
|
||||
@parent = ContextState.new "Toplevel"
|
||||
end
|
||||
|
||||
it "returns a composite description string from self and all parents" do
|
||||
@parent.description.should == "Toplevel"
|
||||
@state.description.should == "when empty"
|
||||
expect(@parent.description).to eq("Toplevel")
|
||||
expect(@state.description).to eq("when empty")
|
||||
@state.parent = @parent
|
||||
@state.description.should == "Toplevel when empty"
|
||||
expect(@state.description).to eq("Toplevel when empty")
|
||||
end
|
||||
end
|
||||
|
||||
describe ContextState, "#it" do
|
||||
RSpec.describe ContextState, "#it" do
|
||||
before :each do
|
||||
@state = ContextState.new ""
|
||||
@proc = lambda {|*| }
|
||||
|
@ -80,25 +80,25 @@ describe ContextState, "#it" do
|
|||
end
|
||||
|
||||
it "creates an ExampleState instance for the block" do
|
||||
ExampleState.should_receive(:new).with(@state, "it", @proc).and_return(@ex)
|
||||
expect(ExampleState).to receive(:new).with(@state, "it", @proc).and_return(@ex)
|
||||
@state.describe(&@proc)
|
||||
@state.it("it", &@proc)
|
||||
end
|
||||
|
||||
it "calls registered :add actions" do
|
||||
ExampleState.should_receive(:new).with(@state, "it", @proc).and_return(@ex)
|
||||
expect(ExampleState).to receive(:new).with(@state, "it", @proc).and_return(@ex)
|
||||
|
||||
add_action = double("add")
|
||||
add_action.should_receive(:add).with(@ex).and_return { ScratchPad.record :add }
|
||||
expect(add_action).to receive(:add).with(@ex) { ScratchPad.record :add }
|
||||
MSpec.register :add, add_action
|
||||
|
||||
@state.it("it", &@proc)
|
||||
ScratchPad.recorded.should == :add
|
||||
expect(ScratchPad.recorded).to eq(:add)
|
||||
MSpec.unregister :add, add_action
|
||||
end
|
||||
end
|
||||
|
||||
describe ContextState, "#examples" do
|
||||
RSpec.describe ContextState, "#examples" do
|
||||
before :each do
|
||||
@state = ContextState.new ""
|
||||
end
|
||||
|
@ -106,11 +106,11 @@ describe ContextState, "#examples" do
|
|||
it "returns a list of all examples in this ContextState" do
|
||||
@state.it("first") { }
|
||||
@state.it("second") { }
|
||||
@state.examples.size.should == 2
|
||||
expect(@state.examples.size).to eq(2)
|
||||
end
|
||||
end
|
||||
|
||||
describe ContextState, "#before" do
|
||||
RSpec.describe ContextState, "#before" do
|
||||
before :each do
|
||||
@state = ContextState.new ""
|
||||
@proc = lambda {|*| }
|
||||
|
@ -118,16 +118,16 @@ describe ContextState, "#before" do
|
|||
|
||||
it "records the block for :each" do
|
||||
@state.before(:each, &@proc)
|
||||
@state.before(:each).should == [@proc]
|
||||
expect(@state.before(:each)).to eq([@proc])
|
||||
end
|
||||
|
||||
it "records the block for :all" do
|
||||
@state.before(:all, &@proc)
|
||||
@state.before(:all).should == [@proc]
|
||||
expect(@state.before(:all)).to eq([@proc])
|
||||
end
|
||||
end
|
||||
|
||||
describe ContextState, "#after" do
|
||||
RSpec.describe ContextState, "#after" do
|
||||
before :each do
|
||||
@state = ContextState.new ""
|
||||
@proc = lambda {|*| }
|
||||
|
@ -135,16 +135,16 @@ describe ContextState, "#after" do
|
|||
|
||||
it "records the block for :each" do
|
||||
@state.after(:each, &@proc)
|
||||
@state.after(:each).should == [@proc]
|
||||
expect(@state.after(:each)).to eq([@proc])
|
||||
end
|
||||
|
||||
it "records the block for :all" do
|
||||
@state.after(:all, &@proc)
|
||||
@state.after(:all).should == [@proc]
|
||||
expect(@state.after(:all)).to eq([@proc])
|
||||
end
|
||||
end
|
||||
|
||||
describe ContextState, "#pre" do
|
||||
RSpec.describe ContextState, "#pre" do
|
||||
before :each do
|
||||
@a = lambda {|*| }
|
||||
@b = lambda {|*| }
|
||||
|
@ -161,17 +161,17 @@ describe ContextState, "#pre" do
|
|||
it "returns before(:each) actions in the order they were defined" do
|
||||
@state.before(:each, &@a)
|
||||
@state.before(:each, &@b)
|
||||
@state.pre(:each).should == [@c, @a, @b]
|
||||
expect(@state.pre(:each)).to eq([@c, @a, @b])
|
||||
end
|
||||
|
||||
it "returns before(:all) actions in the order they were defined" do
|
||||
@state.before(:all, &@a)
|
||||
@state.before(:all, &@b)
|
||||
@state.pre(:all).should == [@c, @a, @b]
|
||||
expect(@state.pre(:all)).to eq([@c, @a, @b])
|
||||
end
|
||||
end
|
||||
|
||||
describe ContextState, "#post" do
|
||||
RSpec.describe ContextState, "#post" do
|
||||
before :each do
|
||||
@a = lambda {|*| }
|
||||
@b = lambda {|*| }
|
||||
|
@ -188,17 +188,17 @@ describe ContextState, "#post" do
|
|||
it "returns after(:each) actions in the reverse order they were defined" do
|
||||
@state.after(:each, &@a)
|
||||
@state.after(:each, &@b)
|
||||
@state.post(:each).should == [@b, @a, @c]
|
||||
expect(@state.post(:each)).to eq([@b, @a, @c])
|
||||
end
|
||||
|
||||
it "returns after(:all) actions in the reverse order they were defined" do
|
||||
@state.after(:all, &@a)
|
||||
@state.after(:all, &@b)
|
||||
@state.post(:all).should == [@b, @a, @c]
|
||||
expect(@state.post(:all)).to eq([@b, @a, @c])
|
||||
end
|
||||
end
|
||||
|
||||
describe ContextState, "#protect" do
|
||||
RSpec.describe ContextState, "#protect" do
|
||||
before :each do
|
||||
ScratchPad.record []
|
||||
@a = lambda {|*| ScratchPad << :a }
|
||||
|
@ -207,41 +207,41 @@ describe ContextState, "#protect" do
|
|||
end
|
||||
|
||||
it "returns true and does execute any blocks if check and MSpec.mode?(:pretend) are true" do
|
||||
MSpec.should_receive(:mode?).with(:pretend).and_return(true)
|
||||
ContextState.new("").protect("message", [@a, @b]).should be_true
|
||||
ScratchPad.recorded.should == []
|
||||
expect(MSpec).to receive(:mode?).with(:pretend).and_return(true)
|
||||
expect(ContextState.new("").protect("message", [@a, @b])).to be_truthy
|
||||
expect(ScratchPad.recorded).to eq([])
|
||||
end
|
||||
|
||||
it "executes the blocks if MSpec.mode?(:pretend) is false" do
|
||||
MSpec.should_receive(:mode?).with(:pretend).and_return(false)
|
||||
expect(MSpec).to receive(:mode?).with(:pretend).and_return(false)
|
||||
ContextState.new("").protect("message", [@a, @b])
|
||||
ScratchPad.recorded.should == [:a, :b]
|
||||
expect(ScratchPad.recorded).to eq([:a, :b])
|
||||
end
|
||||
|
||||
it "executes the blocks if check is false" do
|
||||
ContextState.new("").protect("message", [@a, @b], false)
|
||||
ScratchPad.recorded.should == [:a, :b]
|
||||
expect(ScratchPad.recorded).to eq([:a, :b])
|
||||
end
|
||||
|
||||
it "returns true if none of the blocks raise an exception" do
|
||||
ContextState.new("").protect("message", [@a, @b]).should be_true
|
||||
expect(ContextState.new("").protect("message", [@a, @b])).to be_truthy
|
||||
end
|
||||
|
||||
it "returns false if any of the blocks raise an exception" do
|
||||
ContextState.new("").protect("message", [@a, @c, @b]).should be_false
|
||||
expect(ContextState.new("").protect("message", [@a, @c, @b])).to be_falsey
|
||||
end
|
||||
end
|
||||
|
||||
describe ContextState, "#parent=" do
|
||||
RSpec.describe ContextState, "#parent=" do
|
||||
before :each do
|
||||
@state = ContextState.new ""
|
||||
@parent = double("describe")
|
||||
@parent.stub(:parent).and_return(nil)
|
||||
@parent.stub(:child)
|
||||
allow(@parent).to receive(:parent).and_return(nil)
|
||||
allow(@parent).to receive(:child)
|
||||
end
|
||||
|
||||
it "does not set self as a child of parent if shared" do
|
||||
@parent.should_not_receive(:child)
|
||||
expect(@parent).not_to receive(:child)
|
||||
state = ContextState.new "", :shared => true
|
||||
state.parent = @parent
|
||||
end
|
||||
|
@ -249,70 +249,70 @@ describe ContextState, "#parent=" do
|
|||
it "does not set parents if shared" do
|
||||
state = ContextState.new "", :shared => true
|
||||
state.parent = @parent
|
||||
state.parents.should == [state]
|
||||
expect(state.parents).to eq([state])
|
||||
end
|
||||
|
||||
it "sets self as a child of parent" do
|
||||
@parent.should_receive(:child).with(@state)
|
||||
expect(@parent).to receive(:child).with(@state)
|
||||
@state.parent = @parent
|
||||
end
|
||||
|
||||
it "creates the list of parents" do
|
||||
@state.parent = @parent
|
||||
@state.parents.should == [@parent, @state]
|
||||
expect(@state.parents).to eq([@parent, @state])
|
||||
end
|
||||
end
|
||||
|
||||
describe ContextState, "#parent" do
|
||||
RSpec.describe ContextState, "#parent" do
|
||||
before :each do
|
||||
@state = ContextState.new ""
|
||||
@parent = double("describe")
|
||||
@parent.stub(:parent).and_return(nil)
|
||||
@parent.stub(:child)
|
||||
allow(@parent).to receive(:parent).and_return(nil)
|
||||
allow(@parent).to receive(:child)
|
||||
end
|
||||
|
||||
it "returns nil if parent has not been set" do
|
||||
@state.parent.should be_nil
|
||||
expect(@state.parent).to be_nil
|
||||
end
|
||||
|
||||
it "returns the parent" do
|
||||
@state.parent = @parent
|
||||
@state.parent.should == @parent
|
||||
expect(@state.parent).to eq(@parent)
|
||||
end
|
||||
end
|
||||
|
||||
describe ContextState, "#parents" do
|
||||
RSpec.describe ContextState, "#parents" do
|
||||
before :each do
|
||||
@first = ContextState.new ""
|
||||
@second = ContextState.new ""
|
||||
@parent = double("describe")
|
||||
@parent.stub(:parent).and_return(nil)
|
||||
@parent.stub(:child)
|
||||
allow(@parent).to receive(:parent).and_return(nil)
|
||||
allow(@parent).to receive(:child)
|
||||
end
|
||||
|
||||
it "returns a list of all enclosing ContextState instances" do
|
||||
@first.parent = @parent
|
||||
@second.parent = @first
|
||||
@second.parents.should == [@parent, @first, @second]
|
||||
expect(@second.parents).to eq([@parent, @first, @second])
|
||||
end
|
||||
end
|
||||
|
||||
describe ContextState, "#child" do
|
||||
RSpec.describe ContextState, "#child" do
|
||||
before :each do
|
||||
@first = ContextState.new ""
|
||||
@second = ContextState.new ""
|
||||
@parent = double("describe")
|
||||
@parent.stub(:parent).and_return(nil)
|
||||
@parent.stub(:child)
|
||||
allow(@parent).to receive(:parent).and_return(nil)
|
||||
allow(@parent).to receive(:child)
|
||||
end
|
||||
|
||||
it "adds the ContextState to the list of contained ContextStates" do
|
||||
@first.child @second
|
||||
@first.children.should == [@second]
|
||||
expect(@first.children).to eq([@second])
|
||||
end
|
||||
end
|
||||
|
||||
describe ContextState, "#children" do
|
||||
RSpec.describe ContextState, "#children" do
|
||||
before :each do
|
||||
@parent = ContextState.new ""
|
||||
@first = ContextState.new ""
|
||||
|
@ -322,12 +322,12 @@ describe ContextState, "#children" do
|
|||
it "returns the list of directly contained ContextStates" do
|
||||
@first.parent = @parent
|
||||
@second.parent = @first
|
||||
@parent.children.should == [@first]
|
||||
@first.children.should == [@second]
|
||||
expect(@parent.children).to eq([@first])
|
||||
expect(@first.children).to eq([@second])
|
||||
end
|
||||
end
|
||||
|
||||
describe ContextState, "#state" do
|
||||
RSpec.describe ContextState, "#state" do
|
||||
before :each do
|
||||
MSpec.store :before, []
|
||||
MSpec.store :after, []
|
||||
|
@ -336,7 +336,7 @@ describe ContextState, "#state" do
|
|||
end
|
||||
|
||||
it "returns nil if no spec is being executed" do
|
||||
@state.state.should == nil
|
||||
expect(@state.state).to eq(nil)
|
||||
end
|
||||
|
||||
it "returns a ExampleState instance if an example is being executed" do
|
||||
|
@ -344,16 +344,16 @@ describe ContextState, "#state" do
|
|||
@state.describe { }
|
||||
@state.it("") { ScratchPad.record ScratchPad.recorded.state }
|
||||
@state.process
|
||||
@state.state.should == nil
|
||||
ScratchPad.recorded.should be_kind_of(ExampleState)
|
||||
expect(@state.state).to eq(nil)
|
||||
expect(ScratchPad.recorded).to be_kind_of(ExampleState)
|
||||
end
|
||||
end
|
||||
|
||||
describe ContextState, "#process" do
|
||||
RSpec.describe ContextState, "#process" do
|
||||
before :each do
|
||||
MSpec.store :before, []
|
||||
MSpec.store :after, []
|
||||
MSpec.stub(:register_current)
|
||||
allow(MSpec).to receive(:register_current)
|
||||
|
||||
@state = ContextState.new ""
|
||||
@state.describe { }
|
||||
|
@ -368,7 +368,7 @@ describe ContextState, "#process" do
|
|||
@state.before(:all, &@b)
|
||||
@state.it("") { }
|
||||
@state.process
|
||||
ScratchPad.recorded.should == [:a, :b]
|
||||
expect(ScratchPad.recorded).to eq([:a, :b])
|
||||
end
|
||||
|
||||
it "calls each after(:all) block" do
|
||||
|
@ -376,22 +376,22 @@ describe ContextState, "#process" do
|
|||
@state.after(:all, &@b)
|
||||
@state.it("") { }
|
||||
@state.process
|
||||
ScratchPad.recorded.should == [:b, :a]
|
||||
expect(ScratchPad.recorded).to eq([:b, :a])
|
||||
end
|
||||
|
||||
it "calls each it block" do
|
||||
@state.it("one", &@a)
|
||||
@state.it("two", &@b)
|
||||
@state.process
|
||||
ScratchPad.recorded.should == [:a, :b]
|
||||
expect(ScratchPad.recorded).to eq([:a, :b])
|
||||
end
|
||||
|
||||
it "does not call the #it block if #filtered? returns true" do
|
||||
@state.it("one", &@a)
|
||||
@state.it("two", &@b)
|
||||
@state.examples.first.stub(:filtered?).and_return(true)
|
||||
allow(@state.examples.first).to receive(:filtered?).and_return(true)
|
||||
@state.process
|
||||
ScratchPad.recorded.should == [:b]
|
||||
expect(ScratchPad.recorded).to eq([:b])
|
||||
end
|
||||
|
||||
it "calls each before(:each) block" do
|
||||
|
@ -399,7 +399,7 @@ describe ContextState, "#process" do
|
|||
@state.before(:each, &@b)
|
||||
@state.it("") { }
|
||||
@state.process
|
||||
ScratchPad.recorded.should == [:a, :b]
|
||||
expect(ScratchPad.recorded).to eq([:a, :b])
|
||||
end
|
||||
|
||||
it "calls each after(:each) block" do
|
||||
|
@ -407,20 +407,20 @@ describe ContextState, "#process" do
|
|||
@state.after(:each, &@b)
|
||||
@state.it("") { }
|
||||
@state.process
|
||||
ScratchPad.recorded.should == [:b, :a]
|
||||
expect(ScratchPad.recorded).to eq([:b, :a])
|
||||
end
|
||||
|
||||
it "calls Mock.cleanup for each it block" do
|
||||
@state.it("") { }
|
||||
@state.it("") { }
|
||||
Mock.should_receive(:cleanup).twice
|
||||
expect(Mock).to receive(:cleanup).twice
|
||||
@state.process
|
||||
end
|
||||
|
||||
it "calls Mock.verify_count for each it block" do
|
||||
@state.it("") { }
|
||||
@state.it("") { }
|
||||
Mock.should_receive(:verify_count).twice
|
||||
expect(Mock).to receive(:verify_count).twice
|
||||
@state.process
|
||||
end
|
||||
|
||||
|
@ -428,7 +428,7 @@ describe ContextState, "#process" do
|
|||
ScratchPad.record []
|
||||
@state.describe { ScratchPad << :a }
|
||||
@state.process
|
||||
ScratchPad.recorded.should == [:a]
|
||||
expect(ScratchPad.recorded).to eq([:a])
|
||||
end
|
||||
|
||||
it "creates a new ExampleState instance for each example" do
|
||||
|
@ -436,21 +436,21 @@ describe ContextState, "#process" do
|
|||
@state.describe { }
|
||||
@state.it("it") { ScratchPad.record ScratchPad.recorded.state }
|
||||
@state.process
|
||||
ScratchPad.recorded.should be_kind_of(ExampleState)
|
||||
expect(ScratchPad.recorded).to be_kind_of(ExampleState)
|
||||
end
|
||||
|
||||
it "clears the expectations flag before evaluating the #it block" do
|
||||
MSpec.clear_expectations
|
||||
MSpec.should_receive(:clear_expectations)
|
||||
expect(MSpec).to receive(:clear_expectations)
|
||||
@state.it("it") { ScratchPad.record MSpec.expectation? }
|
||||
@state.process
|
||||
ScratchPad.recorded.should be_false
|
||||
expect(ScratchPad.recorded).to be_falsey
|
||||
end
|
||||
|
||||
it "shuffles the spec list if MSpec.randomize? is true" do
|
||||
MSpec.randomize = true
|
||||
begin
|
||||
MSpec.should_receive(:shuffle)
|
||||
expect(MSpec).to receive(:shuffle)
|
||||
@state.it("") { }
|
||||
@state.process
|
||||
ensure
|
||||
|
@ -459,24 +459,24 @@ describe ContextState, "#process" do
|
|||
end
|
||||
|
||||
it "sets the current MSpec ContextState" do
|
||||
MSpec.should_receive(:register_current).with(@state)
|
||||
expect(MSpec).to receive(:register_current).with(@state)
|
||||
@state.process
|
||||
end
|
||||
|
||||
it "resets the current MSpec ContextState to nil when there are examples" do
|
||||
MSpec.should_receive(:register_current).with(nil)
|
||||
expect(MSpec).to receive(:register_current).with(nil)
|
||||
@state.it("") { }
|
||||
@state.process
|
||||
end
|
||||
|
||||
it "resets the current MSpec ContextState to nil when there are no examples" do
|
||||
MSpec.should_receive(:register_current).with(nil)
|
||||
expect(MSpec).to receive(:register_current).with(nil)
|
||||
@state.process
|
||||
end
|
||||
|
||||
it "call #process on children when there are examples" do
|
||||
child = ContextState.new ""
|
||||
child.should_receive(:process)
|
||||
expect(child).to receive(:process)
|
||||
@state.child child
|
||||
@state.it("") { }
|
||||
@state.process
|
||||
|
@ -484,13 +484,13 @@ describe ContextState, "#process" do
|
|||
|
||||
it "call #process on children when there are no examples" do
|
||||
child = ContextState.new ""
|
||||
child.should_receive(:process)
|
||||
expect(child).to receive(:process)
|
||||
@state.child child
|
||||
@state.process
|
||||
end
|
||||
end
|
||||
|
||||
describe ContextState, "#process" do
|
||||
RSpec.describe ContextState, "#process" do
|
||||
before :each do
|
||||
MSpec.store :exception, []
|
||||
|
||||
|
@ -514,23 +514,23 @@ describe ContextState, "#process" do
|
|||
it "raises an SpecExpectationNotFoundError if an #it block does not contain an expectation" do
|
||||
@state.it("it") { }
|
||||
@state.process
|
||||
ScratchPad.recorded.should == :exception
|
||||
expect(ScratchPad.recorded).to eq(:exception)
|
||||
end
|
||||
|
||||
it "does not raise an SpecExpectationNotFoundError if an #it block does contain an expectation" do
|
||||
@state.it("it") { MSpec.expectation }
|
||||
@state.process
|
||||
ScratchPad.recorded.should be_nil
|
||||
expect(ScratchPad.recorded).to be_nil
|
||||
end
|
||||
|
||||
it "does not raise an SpecExpectationNotFoundError if the #it block causes a failure" do
|
||||
@state.it("it") { raise Exception, "Failed!" }
|
||||
@state.process
|
||||
ScratchPad.recorded.should be_nil
|
||||
expect(ScratchPad.recorded).to be_nil
|
||||
end
|
||||
end
|
||||
|
||||
describe ContextState, "#process" do
|
||||
RSpec.describe ContextState, "#process" do
|
||||
before :each do
|
||||
MSpec.store :example, []
|
||||
|
||||
|
@ -554,18 +554,18 @@ describe ContextState, "#process" do
|
|||
@state.it("") { MSpec.expectation }
|
||||
@state.process
|
||||
|
||||
ScratchPad.recorded.first.should be_kind_of(ExampleState)
|
||||
ScratchPad.recorded.last.should be_kind_of(Proc)
|
||||
expect(ScratchPad.recorded.first).to be_kind_of(ExampleState)
|
||||
expect(ScratchPad.recorded.last).to be_kind_of(Proc)
|
||||
end
|
||||
|
||||
it "does not call registered example actions if the example has no block" do
|
||||
@state.it("empty example")
|
||||
@state.process
|
||||
ScratchPad.recorded.should == []
|
||||
expect(ScratchPad.recorded).to eq([])
|
||||
end
|
||||
end
|
||||
|
||||
describe ContextState, "#process" do
|
||||
RSpec.describe ContextState, "#process" do
|
||||
before :each do
|
||||
MSpec.store :before, []
|
||||
MSpec.store :after, []
|
||||
|
@ -582,30 +582,30 @@ describe ContextState, "#process" do
|
|||
|
||||
it "calls registered :before actions with the current ExampleState instance" do
|
||||
before = double("before")
|
||||
before.should_receive(:before).and_return {
|
||||
expect(before).to receive(:before) {
|
||||
ScratchPad.record :before
|
||||
@spec_state = @state.state
|
||||
}
|
||||
MSpec.register :before, before
|
||||
@state.process
|
||||
ScratchPad.recorded.should == :before
|
||||
@spec_state.should be_kind_of(ExampleState)
|
||||
expect(ScratchPad.recorded).to eq(:before)
|
||||
expect(@spec_state).to be_kind_of(ExampleState)
|
||||
end
|
||||
|
||||
it "calls registered :after actions with the current ExampleState instance" do
|
||||
after = double("after")
|
||||
after.should_receive(:after).and_return {
|
||||
expect(after).to receive(:after) {
|
||||
ScratchPad.record :after
|
||||
@spec_state = @state.state
|
||||
}
|
||||
MSpec.register :after, after
|
||||
@state.process
|
||||
ScratchPad.recorded.should == :after
|
||||
@spec_state.should be_kind_of(ExampleState)
|
||||
expect(ScratchPad.recorded).to eq(:after)
|
||||
expect(@spec_state).to be_kind_of(ExampleState)
|
||||
end
|
||||
end
|
||||
|
||||
describe ContextState, "#process" do
|
||||
RSpec.describe ContextState, "#process" do
|
||||
before :each do
|
||||
MSpec.store :enter, []
|
||||
MSpec.store :leave, []
|
||||
|
@ -622,22 +622,22 @@ describe ContextState, "#process" do
|
|||
|
||||
it "calls registered :enter actions with the current #describe string" do
|
||||
enter = double("enter")
|
||||
enter.should_receive(:enter).with("C#m").and_return { ScratchPad.record :enter }
|
||||
expect(enter).to receive(:enter).with("C#m") { ScratchPad.record :enter }
|
||||
MSpec.register :enter, enter
|
||||
@state.process
|
||||
ScratchPad.recorded.should == :enter
|
||||
expect(ScratchPad.recorded).to eq(:enter)
|
||||
end
|
||||
|
||||
it "calls registered :leave actions" do
|
||||
leave = double("leave")
|
||||
leave.should_receive(:leave).and_return { ScratchPad.record :leave }
|
||||
expect(leave).to receive(:leave) { ScratchPad.record :leave }
|
||||
MSpec.register :leave, leave
|
||||
@state.process
|
||||
ScratchPad.recorded.should == :leave
|
||||
expect(ScratchPad.recorded).to eq(:leave)
|
||||
end
|
||||
end
|
||||
|
||||
describe ContextState, "#process when an exception is raised in before(:all)" do
|
||||
RSpec.describe ContextState, "#process when an exception is raised in before(:all)" do
|
||||
before :each do
|
||||
MSpec.store :before, []
|
||||
MSpec.store :after, []
|
||||
|
@ -661,43 +661,43 @@ describe ContextState, "#process when an exception is raised in before(:all)" do
|
|||
@state.before(:each, &@a)
|
||||
@state.it("") { }
|
||||
@state.process
|
||||
ScratchPad.recorded.should == []
|
||||
expect(ScratchPad.recorded).to eq([])
|
||||
end
|
||||
|
||||
it "does not call the it block" do
|
||||
@state.it("one", &@a)
|
||||
@state.process
|
||||
ScratchPad.recorded.should == []
|
||||
expect(ScratchPad.recorded).to eq([])
|
||||
end
|
||||
|
||||
it "does not call after(:each)" do
|
||||
@state.after(:each, &@a)
|
||||
@state.it("") { }
|
||||
@state.process
|
||||
ScratchPad.recorded.should == []
|
||||
expect(ScratchPad.recorded).to eq([])
|
||||
end
|
||||
|
||||
it "does not call after(:each)" do
|
||||
@state.after(:all, &@a)
|
||||
@state.it("") { }
|
||||
@state.process
|
||||
ScratchPad.recorded.should == []
|
||||
expect(ScratchPad.recorded).to eq([])
|
||||
end
|
||||
|
||||
it "does not call Mock.verify_count" do
|
||||
@state.it("") { }
|
||||
Mock.should_not_receive(:verify_count)
|
||||
expect(Mock).not_to receive(:verify_count)
|
||||
@state.process
|
||||
end
|
||||
|
||||
it "calls Mock.cleanup" do
|
||||
@state.it("") { }
|
||||
Mock.should_receive(:cleanup)
|
||||
expect(Mock).to receive(:cleanup)
|
||||
@state.process
|
||||
end
|
||||
end
|
||||
|
||||
describe ContextState, "#process when an exception is raised in before(:each)" do
|
||||
RSpec.describe ContextState, "#process when an exception is raised in before(:each)" do
|
||||
before :each do
|
||||
MSpec.store :before, []
|
||||
MSpec.store :after, []
|
||||
|
@ -720,24 +720,24 @@ describe ContextState, "#process when an exception is raised in before(:each)" d
|
|||
it "does not call the it block" do
|
||||
@state.it("one", &@a)
|
||||
@state.process
|
||||
ScratchPad.recorded.should == []
|
||||
expect(ScratchPad.recorded).to eq([])
|
||||
end
|
||||
|
||||
it "does call after(:each)" do
|
||||
it "calls after(:each)" do
|
||||
@state.after(:each, &@a)
|
||||
@state.it("") { }
|
||||
@state.process
|
||||
ScratchPad.recorded.should == [:a]
|
||||
expect(ScratchPad.recorded).to eq([:a])
|
||||
end
|
||||
|
||||
it "does not call Mock.verify_count" do
|
||||
it "calls Mock.verify_count" do
|
||||
@state.it("") { }
|
||||
Mock.should_not_receive(:verify_count)
|
||||
expect(Mock).to receive(:verify_count)
|
||||
@state.process
|
||||
end
|
||||
end
|
||||
|
||||
describe ContextState, "#process in pretend mode" do
|
||||
RSpec.describe ContextState, "#process in pretend mode" do
|
||||
before :all do
|
||||
MSpec.register_mode :pretend
|
||||
end
|
||||
|
@ -763,30 +763,30 @@ describe ContextState, "#process in pretend mode" do
|
|||
|
||||
it "calls registered :before actions with the current ExampleState instance" do
|
||||
before = double("before")
|
||||
before.should_receive(:before).and_return {
|
||||
expect(before).to receive(:before) {
|
||||
ScratchPad.record :before
|
||||
@spec_state = @state.state
|
||||
}
|
||||
MSpec.register :before, before
|
||||
@state.process
|
||||
ScratchPad.recorded.should == :before
|
||||
@spec_state.should be_kind_of(ExampleState)
|
||||
expect(ScratchPad.recorded).to eq(:before)
|
||||
expect(@spec_state).to be_kind_of(ExampleState)
|
||||
end
|
||||
|
||||
it "calls registered :after actions with the current ExampleState instance" do
|
||||
after = double("after")
|
||||
after.should_receive(:after).and_return {
|
||||
expect(after).to receive(:after) {
|
||||
ScratchPad.record :after
|
||||
@spec_state = @state.state
|
||||
}
|
||||
MSpec.register :after, after
|
||||
@state.process
|
||||
ScratchPad.recorded.should == :after
|
||||
@spec_state.should be_kind_of(ExampleState)
|
||||
expect(ScratchPad.recorded).to eq(:after)
|
||||
expect(@spec_state).to be_kind_of(ExampleState)
|
||||
end
|
||||
end
|
||||
|
||||
describe ContextState, "#process in pretend mode" do
|
||||
RSpec.describe ContextState, "#process in pretend mode" do
|
||||
before :all do
|
||||
MSpec.register_mode :pretend
|
||||
end
|
||||
|
@ -811,7 +811,7 @@ describe ContextState, "#process in pretend mode" do
|
|||
ScratchPad.record []
|
||||
@state.describe { ScratchPad << :a }
|
||||
@state.process
|
||||
ScratchPad.recorded.should == [:a]
|
||||
expect(ScratchPad.recorded).to eq([:a])
|
||||
end
|
||||
|
||||
it "does not call any before(:all) block" do
|
||||
|
@ -819,7 +819,7 @@ describe ContextState, "#process in pretend mode" do
|
|||
@state.before(:all, &@b)
|
||||
@state.it("") { }
|
||||
@state.process
|
||||
ScratchPad.recorded.should == []
|
||||
expect(ScratchPad.recorded).to eq([])
|
||||
end
|
||||
|
||||
it "does not call any after(:all) block" do
|
||||
|
@ -827,14 +827,14 @@ describe ContextState, "#process in pretend mode" do
|
|||
@state.after(:all, &@b)
|
||||
@state.it("") { }
|
||||
@state.process
|
||||
ScratchPad.recorded.should == []
|
||||
expect(ScratchPad.recorded).to eq([])
|
||||
end
|
||||
|
||||
it "does not call any it block" do
|
||||
@state.it("one", &@a)
|
||||
@state.it("two", &@b)
|
||||
@state.process
|
||||
ScratchPad.recorded.should == []
|
||||
expect(ScratchPad.recorded).to eq([])
|
||||
end
|
||||
|
||||
it "does not call any before(:each) block" do
|
||||
|
@ -842,7 +842,7 @@ describe ContextState, "#process in pretend mode" do
|
|||
@state.before(:each, &@b)
|
||||
@state.it("") { }
|
||||
@state.process
|
||||
ScratchPad.recorded.should == []
|
||||
expect(ScratchPad.recorded).to eq([])
|
||||
end
|
||||
|
||||
it "does not call any after(:each) block" do
|
||||
|
@ -850,18 +850,18 @@ describe ContextState, "#process in pretend mode" do
|
|||
@state.after(:each, &@b)
|
||||
@state.it("") { }
|
||||
@state.process
|
||||
ScratchPad.recorded.should == []
|
||||
expect(ScratchPad.recorded).to eq([])
|
||||
end
|
||||
|
||||
it "does not call Mock.cleanup" do
|
||||
@state.it("") { }
|
||||
@state.it("") { }
|
||||
Mock.should_not_receive(:cleanup)
|
||||
expect(Mock).not_to receive(:cleanup)
|
||||
@state.process
|
||||
end
|
||||
end
|
||||
|
||||
describe ContextState, "#process in pretend mode" do
|
||||
RSpec.describe ContextState, "#process in pretend mode" do
|
||||
before :all do
|
||||
MSpec.register_mode :pretend
|
||||
end
|
||||
|
@ -886,26 +886,26 @@ describe ContextState, "#process in pretend mode" do
|
|||
|
||||
it "calls registered :enter actions with the current #describe string" do
|
||||
enter = double("enter")
|
||||
enter.should_receive(:enter).and_return { ScratchPad.record :enter }
|
||||
expect(enter).to receive(:enter) { ScratchPad.record :enter }
|
||||
MSpec.register :enter, enter
|
||||
@state.process
|
||||
ScratchPad.recorded.should == :enter
|
||||
expect(ScratchPad.recorded).to eq(:enter)
|
||||
end
|
||||
|
||||
it "calls registered :leave actions" do
|
||||
leave = double("leave")
|
||||
leave.should_receive(:leave).and_return { ScratchPad.record :leave }
|
||||
expect(leave).to receive(:leave) { ScratchPad.record :leave }
|
||||
MSpec.register :leave, leave
|
||||
@state.process
|
||||
ScratchPad.recorded.should == :leave
|
||||
expect(ScratchPad.recorded).to eq(:leave)
|
||||
end
|
||||
end
|
||||
|
||||
describe ContextState, "#it_should_behave_like" do
|
||||
RSpec.describe ContextState, "#it_should_behave_like" do
|
||||
before :each do
|
||||
@shared_desc = :shared_context
|
||||
@shared = ContextState.new(@shared_desc, :shared => true)
|
||||
MSpec.stub(:retrieve_shared).and_return(@shared)
|
||||
allow(MSpec).to receive(:retrieve_shared).and_return(@shared)
|
||||
|
||||
@state = ContextState.new "Top level"
|
||||
@a = lambda {|*| }
|
||||
|
@ -913,8 +913,8 @@ describe ContextState, "#it_should_behave_like" do
|
|||
end
|
||||
|
||||
it "raises an Exception if unable to find the shared ContextState" do
|
||||
MSpec.should_receive(:retrieve_shared).and_return(nil)
|
||||
lambda { @state.it_should_behave_like "this" }.should raise_error(Exception)
|
||||
expect(MSpec).to receive(:retrieve_shared).and_return(nil)
|
||||
expect { @state.it_should_behave_like "this" }.to raise_error(Exception)
|
||||
end
|
||||
|
||||
describe "for nested ContextState instances" do
|
||||
|
@ -925,24 +925,24 @@ describe ContextState, "#it_should_behave_like" do
|
|||
@shared.children << @nested
|
||||
|
||||
@nested_dup = @nested.dup
|
||||
@nested.stub(:dup).and_return(@nested_dup)
|
||||
allow(@nested).to receive(:dup).and_return(@nested_dup)
|
||||
end
|
||||
|
||||
it "duplicates the nested ContextState" do
|
||||
@state.it_should_behave_like @shared_desc
|
||||
@state.children.first.should equal(@nested_dup)
|
||||
expect(@state.children.first).to equal(@nested_dup)
|
||||
end
|
||||
|
||||
it "sets the parent of the nested ContextState to the containing ContextState" do
|
||||
@state.it_should_behave_like @shared_desc
|
||||
@nested_dup.parent.should equal(@state)
|
||||
expect(@nested_dup.parent).to equal(@state)
|
||||
end
|
||||
|
||||
it "sets the context for nested examples to the nested ContextState's dup" do
|
||||
@shared.it "an example", &@a
|
||||
@shared.it "another example", &@b
|
||||
@state.it_should_behave_like @shared_desc
|
||||
@nested_dup.examples.each { |x| x.context.should equal(@nested_dup) }
|
||||
@nested_dup.examples.each { |x| expect(x.context).to equal(@nested_dup) }
|
||||
end
|
||||
|
||||
it "omits the shored ContextState's description" do
|
||||
|
@ -950,58 +950,58 @@ describe ContextState, "#it_should_behave_like" do
|
|||
@nested.it "another example", &@b
|
||||
@state.it_should_behave_like @shared_desc
|
||||
|
||||
@nested_dup.description.should == "Top level nested context"
|
||||
@nested_dup.examples.first.description.should == "Top level nested context an example"
|
||||
@nested_dup.examples.last.description.should == "Top level nested context another example"
|
||||
expect(@nested_dup.description).to eq("Top level nested context")
|
||||
expect(@nested_dup.examples.first.description).to eq("Top level nested context an example")
|
||||
expect(@nested_dup.examples.last.description).to eq("Top level nested context another example")
|
||||
end
|
||||
end
|
||||
|
||||
it "adds duped examples from the shared ContextState" do
|
||||
@shared.it "some method", &@a
|
||||
ex_dup = @shared.examples.first.dup
|
||||
@shared.examples.first.stub(:dup).and_return(ex_dup)
|
||||
allow(@shared.examples.first).to receive(:dup).and_return(ex_dup)
|
||||
|
||||
@state.it_should_behave_like @shared_desc
|
||||
@state.examples.should == [ex_dup]
|
||||
expect(@state.examples).to eq([ex_dup])
|
||||
end
|
||||
|
||||
it "sets the context for examples to the containing ContextState" do
|
||||
@shared.it "an example", &@a
|
||||
@shared.it "another example", &@b
|
||||
@state.it_should_behave_like @shared_desc
|
||||
@state.examples.each { |x| x.context.should equal(@state) }
|
||||
@state.examples.each { |x| expect(x.context).to equal(@state) }
|
||||
end
|
||||
|
||||
it "adds before(:all) blocks from the shared ContextState" do
|
||||
@shared.before :all, &@a
|
||||
@shared.before :all, &@b
|
||||
@state.it_should_behave_like @shared_desc
|
||||
@state.before(:all).should include(*@shared.before(:all))
|
||||
expect(@state.before(:all)).to include(*@shared.before(:all))
|
||||
end
|
||||
|
||||
it "adds before(:each) blocks from the shared ContextState" do
|
||||
@shared.before :each, &@a
|
||||
@shared.before :each, &@b
|
||||
@state.it_should_behave_like @shared_desc
|
||||
@state.before(:each).should include(*@shared.before(:each))
|
||||
expect(@state.before(:each)).to include(*@shared.before(:each))
|
||||
end
|
||||
|
||||
it "adds after(:each) blocks from the shared ContextState" do
|
||||
@shared.after :each, &@a
|
||||
@shared.after :each, &@b
|
||||
@state.it_should_behave_like @shared_desc
|
||||
@state.after(:each).should include(*@shared.after(:each))
|
||||
expect(@state.after(:each)).to include(*@shared.after(:each))
|
||||
end
|
||||
|
||||
it "adds after(:all) blocks from the shared ContextState" do
|
||||
@shared.after :all, &@a
|
||||
@shared.after :all, &@b
|
||||
@state.it_should_behave_like @shared_desc
|
||||
@state.after(:all).should include(*@shared.after(:all))
|
||||
expect(@state.after(:all)).to include(*@shared.after(:all))
|
||||
end
|
||||
end
|
||||
|
||||
describe ContextState, "#filter_examples" do
|
||||
RSpec.describe ContextState, "#filter_examples" do
|
||||
before :each do
|
||||
@state = ContextState.new ""
|
||||
@state.it("one") { }
|
||||
|
@ -1009,20 +1009,20 @@ describe ContextState, "#filter_examples" do
|
|||
end
|
||||
|
||||
it "removes examples that are filtered" do
|
||||
@state.examples.first.stub(:filtered?).and_return(true)
|
||||
@state.examples.size.should == 2
|
||||
allow(@state.examples.first).to receive(:filtered?).and_return(true)
|
||||
expect(@state.examples.size).to eq(2)
|
||||
@state.filter_examples
|
||||
@state.examples.size.should == 1
|
||||
expect(@state.examples.size).to eq(1)
|
||||
end
|
||||
|
||||
it "returns true if there are remaining examples to evaluate" do
|
||||
@state.examples.first.stub(:filtered?).and_return(true)
|
||||
@state.filter_examples.should be_true
|
||||
allow(@state.examples.first).to receive(:filtered?).and_return(true)
|
||||
expect(@state.filter_examples).to be_truthy
|
||||
end
|
||||
|
||||
it "returns false if there are no remaining examples to evaluate" do
|
||||
@state.examples.first.stub(:filtered?).and_return(true)
|
||||
@state.examples.last.stub(:filtered?).and_return(true)
|
||||
@state.filter_examples.should be_false
|
||||
allow(@state.examples.first).to receive(:filtered?).and_return(true)
|
||||
allow(@state.examples.last).to receive(:filtered?).and_return(true)
|
||||
expect(@state.filter_examples).to be_falsey
|
||||
end
|
||||
end
|
||||
|
|
|
@ -4,36 +4,36 @@ require 'mspec/runner/mspec'
|
|||
require 'mspec/mocks/mock'
|
||||
require 'mspec/runner/example'
|
||||
|
||||
describe ExampleState do
|
||||
RSpec.describe ExampleState do
|
||||
it "is initialized with the ContextState, #it string, and #it block" do
|
||||
prc = lambda { }
|
||||
context = ContextState.new ""
|
||||
ExampleState.new(context, "does", prc).should be_kind_of(ExampleState)
|
||||
expect(ExampleState.new(context, "does", prc)).to be_kind_of(ExampleState)
|
||||
end
|
||||
end
|
||||
|
||||
describe ExampleState, "#describe" do
|
||||
RSpec.describe ExampleState, "#describe" do
|
||||
before :each do
|
||||
@context = ContextState.new "Object#to_s"
|
||||
@state = ExampleState.new @context, "it"
|
||||
end
|
||||
|
||||
it "returns the ContextState#description" do
|
||||
@state.describe.should == @context.description
|
||||
expect(@state.describe).to eq(@context.description)
|
||||
end
|
||||
end
|
||||
|
||||
describe ExampleState, "#it" do
|
||||
RSpec.describe ExampleState, "#it" do
|
||||
before :each do
|
||||
@state = ExampleState.new ContextState.new("describe"), "it"
|
||||
end
|
||||
|
||||
it "returns the argument to the #it block" do
|
||||
@state.it.should == "it"
|
||||
expect(@state.it).to eq("it")
|
||||
end
|
||||
end
|
||||
|
||||
describe ExampleState, "#context=" do
|
||||
RSpec.describe ExampleState, "#context=" do
|
||||
before :each do
|
||||
@state = ExampleState.new ContextState.new("describe"), "it"
|
||||
@context = ContextState.new "New#context"
|
||||
|
@ -41,28 +41,28 @@ describe ExampleState, "#context=" do
|
|||
|
||||
it "sets the containing ContextState" do
|
||||
@state.context = @context
|
||||
@state.context.should == @context
|
||||
expect(@state.context).to eq(@context)
|
||||
end
|
||||
|
||||
it "resets the description" do
|
||||
@state.description.should == "describe it"
|
||||
expect(@state.description).to eq("describe it")
|
||||
@state.context = @context
|
||||
@state.description.should == "New#context it"
|
||||
expect(@state.description).to eq("New#context it")
|
||||
end
|
||||
end
|
||||
|
||||
describe ExampleState, "#example" do
|
||||
RSpec.describe ExampleState, "#example" do
|
||||
before :each do
|
||||
@proc = lambda { }
|
||||
@state = ExampleState.new ContextState.new("describe"), "it", @proc
|
||||
end
|
||||
|
||||
it "returns the #it block" do
|
||||
@state.example.should == @proc
|
||||
expect(@state.example).to eq(@proc)
|
||||
end
|
||||
end
|
||||
|
||||
describe ExampleState, "#filtered?" do
|
||||
RSpec.describe ExampleState, "#filtered?" do
|
||||
before :each do
|
||||
MSpec.store :include, []
|
||||
MSpec.store :exclude, []
|
||||
|
@ -77,41 +77,41 @@ describe ExampleState, "#filtered?" do
|
|||
end
|
||||
|
||||
it "returns false if MSpec include filters list is empty" do
|
||||
@state.filtered?.should == false
|
||||
expect(@state.filtered?).to eq(false)
|
||||
end
|
||||
|
||||
it "returns false if MSpec include filters match this spec" do
|
||||
@filter.should_receive(:===).and_return(true)
|
||||
expect(@filter).to receive(:===).and_return(true)
|
||||
MSpec.register :include, @filter
|
||||
@state.filtered?.should == false
|
||||
expect(@state.filtered?).to eq(false)
|
||||
end
|
||||
|
||||
it "returns true if MSpec include filters do not match this spec" do
|
||||
@filter.should_receive(:===).and_return(false)
|
||||
expect(@filter).to receive(:===).and_return(false)
|
||||
MSpec.register :include, @filter
|
||||
@state.filtered?.should == true
|
||||
expect(@state.filtered?).to eq(true)
|
||||
end
|
||||
|
||||
it "returns false if MSpec exclude filters list is empty" do
|
||||
@state.filtered?.should == false
|
||||
expect(@state.filtered?).to eq(false)
|
||||
end
|
||||
|
||||
it "returns false if MSpec exclude filters do not match this spec" do
|
||||
@filter.should_receive(:===).and_return(false)
|
||||
expect(@filter).to receive(:===).and_return(false)
|
||||
MSpec.register :exclude, @filter
|
||||
@state.filtered?.should == false
|
||||
expect(@state.filtered?).to eq(false)
|
||||
end
|
||||
|
||||
it "returns true if MSpec exclude filters match this spec" do
|
||||
@filter.should_receive(:===).and_return(true)
|
||||
expect(@filter).to receive(:===).and_return(true)
|
||||
MSpec.register :exclude, @filter
|
||||
@state.filtered?.should == true
|
||||
expect(@state.filtered?).to eq(true)
|
||||
end
|
||||
|
||||
it "returns true if MSpec include and exclude filters match this spec" do
|
||||
@filter.should_receive(:===).twice.and_return(true)
|
||||
expect(@filter).to receive(:===).twice.and_return(true)
|
||||
MSpec.register :include, @filter
|
||||
MSpec.register :exclude, @filter
|
||||
@state.filtered?.should == true
|
||||
expect(@state.filtered?).to eq(true)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -4,16 +4,16 @@ require 'mspec/runner/example'
|
|||
require 'mspec/runner/exception'
|
||||
require 'mspec/utils/script'
|
||||
|
||||
describe ExceptionState, "#initialize" do
|
||||
RSpec.describe ExceptionState, "#initialize" do
|
||||
it "takes a state, location (e.g. before :each), and exception" do
|
||||
context = ContextState.new "Class#method"
|
||||
state = ExampleState.new context, "does something"
|
||||
exc = Exception.new "Fail!"
|
||||
ExceptionState.new(state, "location", exc).should be_kind_of(ExceptionState)
|
||||
expect(ExceptionState.new(state, "location", exc)).to be_kind_of(ExceptionState)
|
||||
end
|
||||
end
|
||||
|
||||
describe ExceptionState, "#description" do
|
||||
RSpec.describe ExceptionState, "#description" do
|
||||
before :each do
|
||||
context = ContextState.new "Class#method"
|
||||
@state = ExampleState.new context, "does something"
|
||||
|
@ -21,99 +21,99 @@ describe ExceptionState, "#description" do
|
|||
|
||||
it "returns the state description if state was not nil" do
|
||||
exc = ExceptionState.new(@state, nil, nil)
|
||||
exc.description.should == "Class#method does something"
|
||||
expect(exc.description).to eq("Class#method does something")
|
||||
end
|
||||
|
||||
it "returns the location if it is not nil and description is nil" do
|
||||
exc = ExceptionState.new(nil, "location", nil)
|
||||
exc.description.should == "An exception occurred during: location"
|
||||
expect(exc.description).to eq("An exception occurred during: location")
|
||||
end
|
||||
|
||||
it "returns both description and location if neither are nil" do
|
||||
exc = ExceptionState.new(@state, "location", nil)
|
||||
exc.description.should == "An exception occurred during: location\nClass#method does something"
|
||||
expect(exc.description).to eq("An exception occurred during: location\nClass#method does something")
|
||||
end
|
||||
end
|
||||
|
||||
describe ExceptionState, "#describe" do
|
||||
RSpec.describe ExceptionState, "#describe" do
|
||||
before :each do
|
||||
context = ContextState.new "Class#method"
|
||||
@state = ExampleState.new context, "does something"
|
||||
end
|
||||
|
||||
it "returns the ExampleState#describe string if created with a non-nil state" do
|
||||
ExceptionState.new(@state, nil, nil).describe.should == @state.describe
|
||||
expect(ExceptionState.new(@state, nil, nil).describe).to eq(@state.describe)
|
||||
end
|
||||
|
||||
it "returns an empty string if created with a nil state" do
|
||||
ExceptionState.new(nil, nil, nil).describe.should == ""
|
||||
expect(ExceptionState.new(nil, nil, nil).describe).to eq("")
|
||||
end
|
||||
end
|
||||
|
||||
describe ExceptionState, "#it" do
|
||||
RSpec.describe ExceptionState, "#it" do
|
||||
before :each do
|
||||
context = ContextState.new "Class#method"
|
||||
@state = ExampleState.new context, "does something"
|
||||
end
|
||||
|
||||
it "returns the ExampleState#it string if created with a non-nil state" do
|
||||
ExceptionState.new(@state, nil, nil).it.should == @state.it
|
||||
expect(ExceptionState.new(@state, nil, nil).it).to eq(@state.it)
|
||||
end
|
||||
|
||||
it "returns an empty string if created with a nil state" do
|
||||
ExceptionState.new(nil, nil, nil).it.should == ""
|
||||
expect(ExceptionState.new(nil, nil, nil).it).to eq("")
|
||||
end
|
||||
end
|
||||
|
||||
describe ExceptionState, "#failure?" do
|
||||
RSpec.describe ExceptionState, "#failure?" do
|
||||
before :each do
|
||||
@state = ExampleState.new ContextState.new("C#m"), "works"
|
||||
end
|
||||
|
||||
it "returns true if the exception is an SpecExpectationNotMetError" do
|
||||
exc = ExceptionState.new @state, "", SpecExpectationNotMetError.new("Fail!")
|
||||
exc.failure?.should be_true
|
||||
expect(exc.failure?).to be_truthy
|
||||
end
|
||||
|
||||
it "returns true if the exception is an SpecExpectationNotFoundError" do
|
||||
exc = ExceptionState.new @state, "", SpecExpectationNotFoundError.new("Fail!")
|
||||
exc.failure?.should be_true
|
||||
expect(exc.failure?).to be_truthy
|
||||
end
|
||||
|
||||
it "returns false if the exception is not an SpecExpectationNotMetError or an SpecExpectationNotFoundError" do
|
||||
exc = ExceptionState.new @state, "", Exception.new("Fail!")
|
||||
exc.failure?.should be_false
|
||||
expect(exc.failure?).to be_falsey
|
||||
end
|
||||
end
|
||||
|
||||
describe ExceptionState, "#message" do
|
||||
RSpec.describe ExceptionState, "#message" do
|
||||
before :each do
|
||||
@state = ExampleState.new ContextState.new("C#m"), "works"
|
||||
end
|
||||
|
||||
it "returns <No message> if the exception message is empty" do
|
||||
exc = ExceptionState.new @state, "", Exception.new("")
|
||||
exc.message.should == "Exception: <No message>"
|
||||
expect(exc.message).to eq("Exception: <No message>")
|
||||
end
|
||||
|
||||
it "returns the message without exception class when the exception is an SpecExpectationNotMetError" do
|
||||
exc = ExceptionState.new @state, "", SpecExpectationNotMetError.new("Fail!")
|
||||
exc.message.should == "Fail!"
|
||||
expect(exc.message).to eq("Fail!")
|
||||
end
|
||||
|
||||
it "returns SpecExpectationNotFoundError#message when the exception is an SpecExpectationNotFoundError" do
|
||||
e = SpecExpectationNotFoundError.new
|
||||
exc = ExceptionState.new @state, "", e
|
||||
exc.message.should == e.message
|
||||
expect(exc.message).to eq(e.message)
|
||||
end
|
||||
|
||||
it "returns the message with exception class when the exception is not an SpecExpectationNotMetError or an SpecExpectationNotFoundError" do
|
||||
exc = ExceptionState.new @state, "", Exception.new("Fail!")
|
||||
exc.message.should == "Exception: Fail!"
|
||||
expect(exc.message).to eq("Exception: Fail!")
|
||||
end
|
||||
end
|
||||
|
||||
describe ExceptionState, "#backtrace" do
|
||||
RSpec.describe ExceptionState, "#backtrace" do
|
||||
before :each do
|
||||
@state = ExampleState.new ContextState.new("C#m"), "works"
|
||||
begin
|
||||
|
@ -128,19 +128,19 @@ describe ExceptionState, "#backtrace" do
|
|||
end
|
||||
|
||||
it "returns a string representation of the exception backtrace" do
|
||||
@exc.backtrace.should be_kind_of(String)
|
||||
expect(@exc.backtrace).to be_kind_of(String)
|
||||
end
|
||||
|
||||
it "does not filter files from the backtrace if $MSPEC_DEBUG is true" do
|
||||
$MSPEC_DEBUG = true
|
||||
@exc.backtrace.should == @exception.backtrace.join("\n")
|
||||
expect(@exc.backtrace).to eq(@exception.backtrace.join("\n"))
|
||||
end
|
||||
|
||||
it "filters files matching config[:backtrace_filter]" do
|
||||
MSpecScript.set :backtrace_filter, %r[mspec/lib]
|
||||
$MSPEC_DEBUG = nil
|
||||
@exc.backtrace.split("\n").each do |line|
|
||||
line.should_not =~ %r[mspec/lib]
|
||||
expect(line).not_to match(%r[mspec/lib])
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -2,33 +2,33 @@ require File.dirname(__FILE__) + '/../../spec_helper'
|
|||
require 'mspec/runner/mspec'
|
||||
require 'mspec/runner/filters/match'
|
||||
|
||||
describe MatchFilter, "#===" do
|
||||
RSpec.describe MatchFilter, "#===" do
|
||||
before :each do
|
||||
@filter = MatchFilter.new nil, 'a', 'b', 'c'
|
||||
end
|
||||
|
||||
it "returns true if the argument matches any of the #initialize strings" do
|
||||
@filter.===('aaa').should == true
|
||||
@filter.===('bccb').should == true
|
||||
expect(@filter.===('aaa')).to eq(true)
|
||||
expect(@filter.===('bccb')).to eq(true)
|
||||
end
|
||||
|
||||
it "returns false if the argument matches none of the #initialize strings" do
|
||||
@filter.===('d').should == false
|
||||
expect(@filter.===('d')).to eq(false)
|
||||
end
|
||||
end
|
||||
|
||||
describe MatchFilter, "#register" do
|
||||
RSpec.describe MatchFilter, "#register" do
|
||||
it "registers itself with MSpec for the designated action list" do
|
||||
filter = MatchFilter.new :include
|
||||
MSpec.should_receive(:register).with(:include, filter)
|
||||
expect(MSpec).to receive(:register).with(:include, filter)
|
||||
filter.register
|
||||
end
|
||||
end
|
||||
|
||||
describe MatchFilter, "#unregister" do
|
||||
RSpec.describe MatchFilter, "#unregister" do
|
||||
it "unregisters itself with MSpec for the designated action list" do
|
||||
filter = MatchFilter.new :exclude
|
||||
MSpec.should_receive(:unregister).with(:exclude, filter)
|
||||
expect(MSpec).to receive(:unregister).with(:exclude, filter)
|
||||
filter.unregister
|
||||
end
|
||||
end
|
||||
|
|
|
@ -2,45 +2,45 @@ require File.dirname(__FILE__) + '/../../spec_helper'
|
|||
require 'mspec/runner/mspec'
|
||||
require 'mspec/runner/filters/profile'
|
||||
|
||||
describe ProfileFilter, "#find" do
|
||||
RSpec.describe ProfileFilter, "#find" do
|
||||
before :each do
|
||||
@filter = ProfileFilter.new nil
|
||||
File.stub(:exist?).and_return(false)
|
||||
allow(File).to receive(:exist?).and_return(false)
|
||||
@file = "rails.yaml"
|
||||
end
|
||||
|
||||
it "attempts to locate the file through the expanded path name" do
|
||||
File.should_receive(:expand_path).with(@file).and_return(@file)
|
||||
File.should_receive(:exist?).with(@file).and_return(true)
|
||||
@filter.find(@file).should == @file
|
||||
expect(File).to receive(:expand_path).with(@file).and_return(@file)
|
||||
expect(File).to receive(:exist?).with(@file).and_return(true)
|
||||
expect(@filter.find(@file)).to eq(@file)
|
||||
end
|
||||
|
||||
it "attempts to locate the file in 'spec/profiles'" do
|
||||
path = File.join "spec/profiles", @file
|
||||
File.should_receive(:exist?).with(path).and_return(true)
|
||||
@filter.find(@file).should == path
|
||||
expect(File).to receive(:exist?).with(path).and_return(true)
|
||||
expect(@filter.find(@file)).to eq(path)
|
||||
end
|
||||
|
||||
it "attempts to locate the file in 'spec'" do
|
||||
path = File.join "spec", @file
|
||||
File.should_receive(:exist?).with(path).and_return(true)
|
||||
@filter.find(@file).should == path
|
||||
expect(File).to receive(:exist?).with(path).and_return(true)
|
||||
expect(@filter.find(@file)).to eq(path)
|
||||
end
|
||||
|
||||
it "attempts to locate the file in 'profiles'" do
|
||||
path = File.join "profiles", @file
|
||||
File.should_receive(:exist?).with(path).and_return(true)
|
||||
@filter.find(@file).should == path
|
||||
expect(File).to receive(:exist?).with(path).and_return(true)
|
||||
expect(@filter.find(@file)).to eq(path)
|
||||
end
|
||||
|
||||
it "attempts to locate the file in '.'" do
|
||||
path = File.join ".", @file
|
||||
File.should_receive(:exist?).with(path).and_return(true)
|
||||
@filter.find(@file).should == path
|
||||
expect(File).to receive(:exist?).with(path).and_return(true)
|
||||
expect(@filter.find(@file)).to eq(path)
|
||||
end
|
||||
end
|
||||
|
||||
describe ProfileFilter, "#parse" do
|
||||
RSpec.describe ProfileFilter, "#parse" do
|
||||
before :each do
|
||||
@filter = ProfileFilter.new nil
|
||||
@file = File.open(File.dirname(__FILE__) + "/b.yaml", "r")
|
||||
|
@ -51,14 +51,14 @@ describe ProfileFilter, "#parse" do
|
|||
end
|
||||
|
||||
it "creates a Hash of the contents of the YAML file" do
|
||||
@filter.parse(@file).should == {
|
||||
expect(@filter.parse(@file)).to eq({
|
||||
"B." => ["b", "bb"],
|
||||
"B::C#" => ["b!", "b=", "b?", "-", "[]", "[]="]
|
||||
}
|
||||
})
|
||||
end
|
||||
end
|
||||
|
||||
describe ProfileFilter, "#load" do
|
||||
RSpec.describe ProfileFilter, "#load" do
|
||||
before :each do
|
||||
@filter = ProfileFilter.new nil
|
||||
@files = [
|
||||
|
@ -68,50 +68,50 @@ describe ProfileFilter, "#load" do
|
|||
end
|
||||
|
||||
it "generates a composite hash from multiple YAML files" do
|
||||
@filter.load(*@files).should == {
|
||||
expect(@filter.load(*@files)).to eq({
|
||||
"A#" => ["a", "aa"],
|
||||
"B." => ["b", "bb"],
|
||||
"B::C#" => ["b!", "b=", "b?", "-", "[]", "[]="]
|
||||
}
|
||||
})
|
||||
end
|
||||
end
|
||||
|
||||
describe ProfileFilter, "#===" do
|
||||
RSpec.describe ProfileFilter, "#===" do
|
||||
before :each do
|
||||
@filter = ProfileFilter.new nil
|
||||
@filter.stub(:load).and_return({ "A#" => ["[]=", "a", "a!", "a?", "aa="]})
|
||||
allow(@filter).to receive(:load).and_return({ "A#" => ["[]=", "a", "a!", "a?", "aa="]})
|
||||
@filter.send :initialize, nil
|
||||
end
|
||||
|
||||
it "returns true if the spec description is for a method in the profile" do
|
||||
@filter.===("The A#[]= method").should == true
|
||||
@filter.===("A#a returns").should == true
|
||||
@filter.===("A#a! replaces").should == true
|
||||
@filter.===("A#a? returns").should == true
|
||||
@filter.===("A#aa= raises").should == true
|
||||
expect(@filter.===("The A#[]= method")).to eq(true)
|
||||
expect(@filter.===("A#a returns")).to eq(true)
|
||||
expect(@filter.===("A#a! replaces")).to eq(true)
|
||||
expect(@filter.===("A#a? returns")).to eq(true)
|
||||
expect(@filter.===("A#aa= raises")).to eq(true)
|
||||
end
|
||||
|
||||
it "returns false if the spec description is for a method not in the profile" do
|
||||
@filter.===("The A#[] method").should == false
|
||||
@filter.===("B#a returns").should == false
|
||||
@filter.===("A.a! replaces").should == false
|
||||
@filter.===("AA#a? returns").should == false
|
||||
@filter.===("A#aa raises").should == false
|
||||
expect(@filter.===("The A#[] method")).to eq(false)
|
||||
expect(@filter.===("B#a returns")).to eq(false)
|
||||
expect(@filter.===("A.a! replaces")).to eq(false)
|
||||
expect(@filter.===("AA#a? returns")).to eq(false)
|
||||
expect(@filter.===("A#aa raises")).to eq(false)
|
||||
end
|
||||
end
|
||||
|
||||
describe ProfileFilter, "#register" do
|
||||
RSpec.describe ProfileFilter, "#register" do
|
||||
it "registers itself with MSpec for the designated action list" do
|
||||
filter = ProfileFilter.new :include
|
||||
MSpec.should_receive(:register).with(:include, filter)
|
||||
expect(MSpec).to receive(:register).with(:include, filter)
|
||||
filter.register
|
||||
end
|
||||
end
|
||||
|
||||
describe ProfileFilter, "#unregister" do
|
||||
RSpec.describe ProfileFilter, "#unregister" do
|
||||
it "unregisters itself with MSpec for the designated action list" do
|
||||
filter = ProfileFilter.new :exclude
|
||||
MSpec.should_receive(:unregister).with(:exclude, filter)
|
||||
expect(MSpec).to receive(:unregister).with(:exclude, filter)
|
||||
filter.unregister
|
||||
end
|
||||
end
|
||||
|
|
|
@ -2,30 +2,30 @@ require File.dirname(__FILE__) + '/../../spec_helper'
|
|||
require 'mspec/runner/mspec'
|
||||
require 'mspec/runner/filters/regexp'
|
||||
|
||||
describe MatchFilter, "#===" do
|
||||
RSpec.describe MatchFilter, "#===" do
|
||||
before :each do
|
||||
@filter = RegexpFilter.new nil, 'a(b|c)', 'b[^ab]', 'cc?'
|
||||
end
|
||||
|
||||
it "returns true if the argument matches any of the #initialize strings" do
|
||||
@filter.===('ab').should == true
|
||||
@filter.===('bc suffix').should == true
|
||||
@filter.===('prefix cc').should == true
|
||||
expect(@filter.===('ab')).to eq(true)
|
||||
expect(@filter.===('bc suffix')).to eq(true)
|
||||
expect(@filter.===('prefix cc')).to eq(true)
|
||||
end
|
||||
|
||||
it "returns false if the argument matches none of the #initialize strings" do
|
||||
@filter.===('aa').should == false
|
||||
@filter.===('ba').should == false
|
||||
@filter.===('prefix d suffix').should == false
|
||||
expect(@filter.===('aa')).to eq(false)
|
||||
expect(@filter.===('ba')).to eq(false)
|
||||
expect(@filter.===('prefix d suffix')).to eq(false)
|
||||
end
|
||||
end
|
||||
|
||||
describe RegexpFilter, "#to_regexp" do
|
||||
RSpec.describe RegexpFilter, "#to_regexp" do
|
||||
before :each do
|
||||
@filter = RegexpFilter.new nil
|
||||
end
|
||||
|
||||
it "converts its arguments to Regexp instances" do
|
||||
@filter.send(:to_regexp, 'a(b|c)', 'b[^ab]', 'cc?').should == [/a(b|c)/, /b[^ab]/, /cc?/]
|
||||
expect(@filter.send(:to_regexp, 'a(b|c)', 'b[^ab]', 'cc?')).to eq([/a(b|c)/, /b[^ab]/, /cc?/])
|
||||
end
|
||||
end
|
||||
|
|
|
@ -3,90 +3,90 @@ require 'mspec/runner/mspec'
|
|||
require 'mspec/runner/filters/match'
|
||||
require 'mspec/runner/filters/tag'
|
||||
|
||||
describe TagFilter, "#load" do
|
||||
RSpec.describe TagFilter, "#load" do
|
||||
before :each do
|
||||
@match = double("match filter").as_null_object
|
||||
@filter = TagFilter.new :include, "tag", "key"
|
||||
@tag = SpecTag.new "tag(comment):description"
|
||||
MSpec.stub(:read_tags).and_return([@tag])
|
||||
MSpec.stub(:register)
|
||||
allow(MSpec).to receive(:read_tags).and_return([@tag])
|
||||
allow(MSpec).to receive(:register)
|
||||
end
|
||||
|
||||
it "loads tags from the tag file" do
|
||||
MSpec.should_receive(:read_tags).with(["tag", "key"]).and_return([])
|
||||
expect(MSpec).to receive(:read_tags).with(["tag", "key"]).and_return([])
|
||||
@filter.load
|
||||
end
|
||||
|
||||
|
||||
it "registers itself with MSpec for the :include action" do
|
||||
filter = TagFilter.new(:include)
|
||||
MSpec.should_receive(:register).with(:include, filter)
|
||||
expect(MSpec).to receive(:register).with(:include, filter)
|
||||
filter.load
|
||||
end
|
||||
|
||||
it "registers itself with MSpec for the :exclude action" do
|
||||
filter = TagFilter.new(:exclude)
|
||||
MSpec.should_receive(:register).with(:exclude, filter)
|
||||
expect(MSpec).to receive(:register).with(:exclude, filter)
|
||||
filter.load
|
||||
end
|
||||
end
|
||||
|
||||
describe TagFilter, "#unload" do
|
||||
RSpec.describe TagFilter, "#unload" do
|
||||
before :each do
|
||||
@filter = TagFilter.new :include, "tag", "key"
|
||||
@tag = SpecTag.new "tag(comment):description"
|
||||
MSpec.stub(:read_tags).and_return([@tag])
|
||||
MSpec.stub(:register)
|
||||
allow(MSpec).to receive(:read_tags).and_return([@tag])
|
||||
allow(MSpec).to receive(:register)
|
||||
end
|
||||
|
||||
it "unregisters itself" do
|
||||
@filter.load
|
||||
MSpec.should_receive(:unregister).with(:include, @filter)
|
||||
expect(MSpec).to receive(:unregister).with(:include, @filter)
|
||||
@filter.unload
|
||||
end
|
||||
end
|
||||
|
||||
describe TagFilter, "#register" do
|
||||
RSpec.describe TagFilter, "#register" do
|
||||
before :each do
|
||||
MSpec.stub(:register)
|
||||
allow(MSpec).to receive(:register)
|
||||
end
|
||||
|
||||
it "registers itself with MSpec for the :load, :unload actions" do
|
||||
filter = TagFilter.new(nil)
|
||||
MSpec.should_receive(:register).with(:load, filter)
|
||||
MSpec.should_receive(:register).with(:unload, filter)
|
||||
expect(MSpec).to receive(:register).with(:load, filter)
|
||||
expect(MSpec).to receive(:register).with(:unload, filter)
|
||||
filter.register
|
||||
end
|
||||
end
|
||||
|
||||
describe TagFilter, "#unregister" do
|
||||
RSpec.describe TagFilter, "#unregister" do
|
||||
before :each do
|
||||
MSpec.stub(:unregister)
|
||||
allow(MSpec).to receive(:unregister)
|
||||
end
|
||||
|
||||
it "unregisters itself with MSpec for the :load, :unload actions" do
|
||||
filter = TagFilter.new(nil)
|
||||
MSpec.should_receive(:unregister).with(:load, filter)
|
||||
MSpec.should_receive(:unregister).with(:unload, filter)
|
||||
expect(MSpec).to receive(:unregister).with(:load, filter)
|
||||
expect(MSpec).to receive(:unregister).with(:unload, filter)
|
||||
filter.unregister
|
||||
end
|
||||
end
|
||||
|
||||
describe TagFilter, "#===" do
|
||||
RSpec.describe TagFilter, "#===" do
|
||||
before :each do
|
||||
@filter = TagFilter.new nil, "tag", "key"
|
||||
@tag = SpecTag.new "tag(comment):description"
|
||||
MSpec.stub(:read_tags).and_return([@tag])
|
||||
MSpec.stub(:register)
|
||||
allow(MSpec).to receive(:read_tags).and_return([@tag])
|
||||
allow(MSpec).to receive(:register)
|
||||
@filter.load
|
||||
end
|
||||
|
||||
it "returns true if the argument matches any of the descriptions" do
|
||||
@filter.===('description').should == true
|
||||
expect(@filter.===('description')).to eq(true)
|
||||
end
|
||||
|
||||
it "returns false if the argument matches none of the descriptions" do
|
||||
@filter.===('descriptionA').should == false
|
||||
@filter.===('adescription').should == false
|
||||
expect(@filter.===('descriptionA')).to eq(false)
|
||||
expect(@filter.===('adescription')).to eq(false)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -2,14 +2,14 @@ require File.dirname(__FILE__) + '/../../spec_helper'
|
|||
require 'mspec/runner/formatters/describe'
|
||||
require 'mspec/runner/example'
|
||||
|
||||
describe DescribeFormatter, "#finish" do
|
||||
RSpec.describe DescribeFormatter, "#finish" do
|
||||
before :each do
|
||||
MSpec.stub(:register)
|
||||
MSpec.stub(:unregister)
|
||||
allow(MSpec).to receive(:register)
|
||||
allow(MSpec).to receive(:unregister)
|
||||
|
||||
@timer = double("timer").as_null_object
|
||||
TimerAction.stub(:new).and_return(@timer)
|
||||
@timer.stub(:format).and_return("Finished in 2.0 seconds")
|
||||
allow(TimerAction).to receive(:new).and_return(@timer)
|
||||
allow(@timer).to receive(:format).and_return("Finished in 2.0 seconds")
|
||||
|
||||
$stdout = @out = IOStub.new
|
||||
context = ContextState.new "Class#method"
|
||||
|
@ -32,36 +32,36 @@ describe DescribeFormatter, "#finish" do
|
|||
|
||||
it "prints a summary of elapsed time" do
|
||||
@formatter.finish
|
||||
@out.should =~ /^Finished in 2.0 seconds$/
|
||||
expect(@out).to match(/^Finished in 2.0 seconds$/)
|
||||
end
|
||||
|
||||
it "prints a tally of counts" do
|
||||
@formatter.finish
|
||||
@out.should =~ /^1 file, 1 example, 2 expectations, 0 failures, 0 errors, 0 tagged$/
|
||||
expect(@out).to match(/^1 file, 1 example, 2 expectations, 0 failures, 0 errors, 0 tagged$/)
|
||||
end
|
||||
|
||||
it "does not print exceptions" do
|
||||
@formatter.finish
|
||||
@out.should == %[
|
||||
expect(@out).to eq(%[
|
||||
|
||||
Finished in 2.0 seconds
|
||||
|
||||
1 file, 1 example, 2 expectations, 0 failures, 0 errors, 0 tagged
|
||||
]
|
||||
])
|
||||
end
|
||||
|
||||
it "prints a summary of failures and errors for each describe block" do
|
||||
exc = ExceptionState.new @state, nil, MSpecExampleError.new("broken")
|
||||
exc.stub(:backtrace).and_return("path/to/some/file.rb:35:in method")
|
||||
allow(exc).to receive(:backtrace).and_return("path/to/some/file.rb:35:in method")
|
||||
@formatter.exception exc
|
||||
@formatter.finish
|
||||
@out.should == %[
|
||||
expect(@out).to eq(%[
|
||||
|
||||
Class#method 0 failures, 1 error
|
||||
|
||||
Finished in 2.0 seconds
|
||||
|
||||
1 file, 1 example, 2 expectations, 0 failures, 0 errors, 0 tagged
|
||||
]
|
||||
])
|
||||
end
|
||||
end
|
||||
|
|
|
@ -4,7 +4,7 @@ require 'mspec/runner/mspec'
|
|||
require 'mspec/runner/example'
|
||||
require 'mspec/utils/script'
|
||||
|
||||
describe DottedFormatter, "#initialize" do
|
||||
RSpec.describe DottedFormatter, "#initialize" do
|
||||
it "permits zero arguments" do
|
||||
DottedFormatter.new
|
||||
end
|
||||
|
@ -14,33 +14,33 @@ describe DottedFormatter, "#initialize" do
|
|||
end
|
||||
end
|
||||
|
||||
describe DottedFormatter, "#register" do
|
||||
RSpec.describe DottedFormatter, "#register" do
|
||||
before :each do
|
||||
@formatter = DottedFormatter.new
|
||||
MSpec.stub(:register)
|
||||
allow(MSpec).to receive(:register)
|
||||
end
|
||||
|
||||
it "registers self with MSpec for appropriate actions" do
|
||||
MSpec.should_receive(:register).with(:exception, @formatter)
|
||||
MSpec.should_receive(:register).with(:before, @formatter)
|
||||
MSpec.should_receive(:register).with(:after, @formatter)
|
||||
MSpec.should_receive(:register).with(:finish, @formatter)
|
||||
expect(MSpec).to receive(:register).with(:exception, @formatter)
|
||||
expect(MSpec).to receive(:register).with(:before, @formatter)
|
||||
expect(MSpec).to receive(:register).with(:after, @formatter)
|
||||
expect(MSpec).to receive(:register).with(:finish, @formatter)
|
||||
@formatter.register
|
||||
end
|
||||
|
||||
it "creates TimerAction and TallyAction" do
|
||||
timer = double("timer")
|
||||
tally = double("tally")
|
||||
timer.should_receive(:register)
|
||||
tally.should_receive(:register)
|
||||
tally.should_receive(:counter)
|
||||
TimerAction.should_receive(:new).and_return(timer)
|
||||
TallyAction.should_receive(:new).and_return(tally)
|
||||
expect(timer).to receive(:register)
|
||||
expect(tally).to receive(:register)
|
||||
expect(tally).to receive(:counter)
|
||||
expect(TimerAction).to receive(:new).and_return(timer)
|
||||
expect(TallyAction).to receive(:new).and_return(tally)
|
||||
@formatter.register
|
||||
end
|
||||
end
|
||||
|
||||
describe DottedFormatter, "#print" do
|
||||
RSpec.describe DottedFormatter, "#print" do
|
||||
before :each do
|
||||
$stdout = IOStub.new
|
||||
end
|
||||
|
@ -52,25 +52,25 @@ describe DottedFormatter, "#print" do
|
|||
it "writes to $stdout by default" do
|
||||
formatter = DottedFormatter.new
|
||||
formatter.print "begonias"
|
||||
$stdout.should == "begonias"
|
||||
expect($stdout).to eq("begonias")
|
||||
end
|
||||
|
||||
it "writes to the file specified when the formatter was created" do
|
||||
out = IOStub.new
|
||||
File.should_receive(:open).with("some/file", "w").and_return(out)
|
||||
expect(File).to receive(:open).with("some/file", "w").and_return(out)
|
||||
formatter = DottedFormatter.new "some/file"
|
||||
formatter.print "begonias"
|
||||
out.should == "begonias"
|
||||
expect(out).to eq("begonias")
|
||||
end
|
||||
|
||||
it "flushes the IO output" do
|
||||
$stdout.should_receive(:flush)
|
||||
expect($stdout).to receive(:flush)
|
||||
formatter = DottedFormatter.new
|
||||
formatter.print "begonias"
|
||||
end
|
||||
end
|
||||
|
||||
describe DottedFormatter, "#exception" do
|
||||
RSpec.describe DottedFormatter, "#exception" do
|
||||
before :each do
|
||||
@formatter = DottedFormatter.new
|
||||
@failure = ExceptionState.new nil, nil, SpecExpectationNotMetError.new("failed")
|
||||
|
@ -79,27 +79,27 @@ describe DottedFormatter, "#exception" do
|
|||
|
||||
it "sets the #failure? flag" do
|
||||
@formatter.exception @failure
|
||||
@formatter.failure?.should be_true
|
||||
expect(@formatter.failure?).to be_truthy
|
||||
@formatter.exception @error
|
||||
@formatter.failure?.should be_false
|
||||
expect(@formatter.failure?).to be_falsey
|
||||
end
|
||||
|
||||
it "sets the #exception? flag" do
|
||||
@formatter.exception @error
|
||||
@formatter.exception?.should be_true
|
||||
expect(@formatter.exception?).to be_truthy
|
||||
@formatter.exception @failure
|
||||
@formatter.exception?.should be_true
|
||||
expect(@formatter.exception?).to be_truthy
|
||||
end
|
||||
|
||||
it "adds the exception to the list of exceptions" do
|
||||
@formatter.exceptions.should == []
|
||||
expect(@formatter.exceptions).to eq([])
|
||||
@formatter.exception @error
|
||||
@formatter.exception @failure
|
||||
@formatter.exceptions.should == [@error, @failure]
|
||||
expect(@formatter.exceptions).to eq([@error, @failure])
|
||||
end
|
||||
end
|
||||
|
||||
describe DottedFormatter, "#exception?" do
|
||||
RSpec.describe DottedFormatter, "#exception?" do
|
||||
before :each do
|
||||
@formatter = DottedFormatter.new
|
||||
@failure = ExceptionState.new nil, nil, SpecExpectationNotMetError.new("failed")
|
||||
|
@ -107,29 +107,29 @@ describe DottedFormatter, "#exception?" do
|
|||
end
|
||||
|
||||
it "returns false if there have been no exceptions" do
|
||||
@formatter.exception?.should be_false
|
||||
expect(@formatter.exception?).to be_falsey
|
||||
end
|
||||
|
||||
it "returns true if any exceptions are errors" do
|
||||
@formatter.exception @failure
|
||||
@formatter.exception @error
|
||||
@formatter.exception?.should be_true
|
||||
expect(@formatter.exception?).to be_truthy
|
||||
end
|
||||
|
||||
it "returns true if all exceptions are failures" do
|
||||
@formatter.exception @failure
|
||||
@formatter.exception @failure
|
||||
@formatter.exception?.should be_true
|
||||
expect(@formatter.exception?).to be_truthy
|
||||
end
|
||||
|
||||
it "returns true if all exceptions are errors" do
|
||||
@formatter.exception @error
|
||||
@formatter.exception @error
|
||||
@formatter.exception?.should be_true
|
||||
expect(@formatter.exception?).to be_truthy
|
||||
end
|
||||
end
|
||||
|
||||
describe DottedFormatter, "#failure?" do
|
||||
RSpec.describe DottedFormatter, "#failure?" do
|
||||
before :each do
|
||||
@formatter = DottedFormatter.new
|
||||
@failure = ExceptionState.new nil, nil, SpecExpectationNotMetError.new("failed")
|
||||
|
@ -137,23 +137,23 @@ describe DottedFormatter, "#failure?" do
|
|||
end
|
||||
|
||||
it "returns false if there have been no exceptions" do
|
||||
@formatter.failure?.should be_false
|
||||
expect(@formatter.failure?).to be_falsey
|
||||
end
|
||||
|
||||
it "returns false if any exceptions are errors" do
|
||||
@formatter.exception @failure
|
||||
@formatter.exception @error
|
||||
@formatter.failure?.should be_false
|
||||
expect(@formatter.failure?).to be_falsey
|
||||
end
|
||||
|
||||
it "returns true if all exceptions are failures" do
|
||||
@formatter.exception @failure
|
||||
@formatter.exception @failure
|
||||
@formatter.failure?.should be_true
|
||||
expect(@formatter.failure?).to be_truthy
|
||||
end
|
||||
end
|
||||
|
||||
describe DottedFormatter, "#before" do
|
||||
RSpec.describe DottedFormatter, "#before" do
|
||||
before :each do
|
||||
@state = ExampleState.new ContextState.new("describe"), "it"
|
||||
@formatter = DottedFormatter.new
|
||||
|
@ -161,19 +161,19 @@ describe DottedFormatter, "#before" do
|
|||
end
|
||||
|
||||
it "resets the #failure? flag to false" do
|
||||
@formatter.failure?.should be_true
|
||||
expect(@formatter.failure?).to be_truthy
|
||||
@formatter.before @state
|
||||
@formatter.failure?.should be_false
|
||||
expect(@formatter.failure?).to be_falsey
|
||||
end
|
||||
|
||||
it "resets the #exception? flag to false" do
|
||||
@formatter.exception?.should be_true
|
||||
expect(@formatter.exception?).to be_truthy
|
||||
@formatter.before @state
|
||||
@formatter.exception?.should be_false
|
||||
expect(@formatter.exception?).to be_falsey
|
||||
end
|
||||
end
|
||||
|
||||
describe DottedFormatter, "#after" do
|
||||
RSpec.describe DottedFormatter, "#after" do
|
||||
before :each do
|
||||
$stdout = @out = IOStub.new
|
||||
@formatter = DottedFormatter.new
|
||||
|
@ -186,21 +186,21 @@ describe DottedFormatter, "#after" do
|
|||
|
||||
it "prints a '.' if there was no exception raised" do
|
||||
@formatter.after(@state)
|
||||
@out.should == "."
|
||||
expect(@out).to eq(".")
|
||||
end
|
||||
|
||||
it "prints an 'F' if there was an expectation failure" do
|
||||
exc = SpecExpectationNotMetError.new "failed"
|
||||
@formatter.exception ExceptionState.new(@state, nil, exc)
|
||||
@formatter.after(@state)
|
||||
@out.should == "F"
|
||||
expect(@out).to eq("F")
|
||||
end
|
||||
|
||||
it "prints an 'E' if there was an exception other than expectation failure" do
|
||||
exc = MSpecExampleError.new("boom!")
|
||||
@formatter.exception ExceptionState.new(@state, nil, exc)
|
||||
@formatter.after(@state)
|
||||
@out.should == "E"
|
||||
expect(@out).to eq("E")
|
||||
end
|
||||
|
||||
it "prints an 'E' if there are mixed exceptions and exepctation failures" do
|
||||
|
@ -209,21 +209,21 @@ describe DottedFormatter, "#after" do
|
|||
exc = MSpecExampleError.new("boom!")
|
||||
@formatter.exception ExceptionState.new(@state, nil, exc)
|
||||
@formatter.after(@state)
|
||||
@out.should == "E"
|
||||
expect(@out).to eq("E")
|
||||
end
|
||||
end
|
||||
|
||||
describe DottedFormatter, "#finish" do
|
||||
RSpec.describe DottedFormatter, "#finish" do
|
||||
before :each do
|
||||
@tally = double("tally").as_null_object
|
||||
TallyAction.stub(:new).and_return(@tally)
|
||||
allow(TallyAction).to receive(:new).and_return(@tally)
|
||||
@timer = double("timer").as_null_object
|
||||
TimerAction.stub(:new).and_return(@timer)
|
||||
allow(TimerAction).to receive(:new).and_return(@timer)
|
||||
|
||||
$stdout = @out = IOStub.new
|
||||
context = ContextState.new "Class#method"
|
||||
@state = ExampleState.new(context, "runs")
|
||||
MSpec.stub(:register)
|
||||
allow(MSpec).to receive(:register)
|
||||
@formatter = DottedFormatter.new
|
||||
@formatter.register
|
||||
end
|
||||
|
@ -237,40 +237,39 @@ describe DottedFormatter, "#finish" do
|
|||
@formatter.exception exc
|
||||
@formatter.after @state
|
||||
@formatter.finish
|
||||
@out.should =~ /^1\)\nClass#method runs ERROR$/
|
||||
expect(@out).to match(/^1\)\nClass#method runs ERROR$/)
|
||||
end
|
||||
|
||||
it "prints a backtrace for an exception" do
|
||||
exc = ExceptionState.new @state, nil, MSpecExampleError.new("broken")
|
||||
exc.stub(:backtrace).and_return("path/to/some/file.rb:35:in method")
|
||||
allow(exc).to receive(:backtrace).and_return("path/to/some/file.rb:35:in method")
|
||||
@formatter.exception exc
|
||||
@formatter.after @state
|
||||
@formatter.finish
|
||||
@out.should =~ %r[path/to/some/file.rb:35:in method$]
|
||||
expect(@out).to match(%r[path/to/some/file.rb:35:in method$])
|
||||
end
|
||||
|
||||
it "prints a summary of elapsed time" do
|
||||
@timer.should_receive(:format).and_return("Finished in 2.0 seconds")
|
||||
expect(@timer).to receive(:format).and_return("Finished in 2.0 seconds")
|
||||
@formatter.finish
|
||||
@out.should =~ /^Finished in 2.0 seconds$/
|
||||
expect(@out).to match(/^Finished in 2.0 seconds$/)
|
||||
end
|
||||
|
||||
it "prints a tally of counts" do
|
||||
@tally.should_receive(:format).and_return("1 example, 0 failures")
|
||||
expect(@tally).to receive(:format).and_return("1 example, 0 failures")
|
||||
@formatter.finish
|
||||
@out.should =~ /^1 example, 0 failures$/
|
||||
expect(@out).to match(/^1 example, 0 failures$/)
|
||||
end
|
||||
|
||||
it "prints errors, backtraces, elapsed time, and tallies" do
|
||||
exc = ExceptionState.new @state, nil, MSpecExampleError.new("broken")
|
||||
exc.stub(:backtrace).and_return("path/to/some/file.rb:35:in method")
|
||||
allow(exc).to receive(:backtrace).and_return("path/to/some/file.rb:35:in method")
|
||||
@formatter.exception exc
|
||||
@timer.should_receive(:format).and_return("Finished in 2.0 seconds")
|
||||
@tally.should_receive(:format).and_return("1 example, 1 failure")
|
||||
expect(@timer).to receive(:format).and_return("Finished in 2.0 seconds")
|
||||
expect(@tally).to receive(:format).and_return("1 example, 1 failure")
|
||||
@formatter.after @state
|
||||
@formatter.finish
|
||||
@out.should ==
|
||||
%[E
|
||||
expect(@out).to eq(%[E
|
||||
|
||||
1)
|
||||
Class#method runs ERROR
|
||||
|
@ -280,6 +279,6 @@ path/to/some/file.rb:35:in method
|
|||
Finished in 2.0 seconds
|
||||
|
||||
1 example, 1 failure
|
||||
]
|
||||
])
|
||||
end
|
||||
end
|
||||
|
|
|
@ -3,27 +3,27 @@ require 'mspec/runner/formatters/file'
|
|||
require 'mspec/runner/mspec'
|
||||
require 'mspec/runner/example'
|
||||
|
||||
describe FileFormatter, "#register" do
|
||||
RSpec.describe FileFormatter, "#register" do
|
||||
before :each do
|
||||
@formatter = FileFormatter.new
|
||||
MSpec.stub(:register)
|
||||
MSpec.stub(:unregister)
|
||||
allow(MSpec).to receive(:register)
|
||||
allow(MSpec).to receive(:unregister)
|
||||
end
|
||||
|
||||
it "registers self with MSpec for :load, :unload actions" do
|
||||
MSpec.should_receive(:register).with(:load, @formatter)
|
||||
MSpec.should_receive(:register).with(:unload, @formatter)
|
||||
expect(MSpec).to receive(:register).with(:load, @formatter)
|
||||
expect(MSpec).to receive(:register).with(:unload, @formatter)
|
||||
@formatter.register
|
||||
end
|
||||
|
||||
it "unregisters self with MSpec for :before, :after actions" do
|
||||
MSpec.should_receive(:unregister).with(:before, @formatter)
|
||||
MSpec.should_receive(:unregister).with(:after, @formatter)
|
||||
expect(MSpec).to receive(:unregister).with(:before, @formatter)
|
||||
expect(MSpec).to receive(:unregister).with(:after, @formatter)
|
||||
@formatter.register
|
||||
end
|
||||
end
|
||||
|
||||
describe FileFormatter, "#load" do
|
||||
RSpec.describe FileFormatter, "#load" do
|
||||
before :each do
|
||||
@state = ExampleState.new ContextState.new("describe"), "it"
|
||||
@formatter = FileFormatter.new
|
||||
|
@ -31,19 +31,19 @@ describe FileFormatter, "#load" do
|
|||
end
|
||||
|
||||
it "resets the #failure? flag to false" do
|
||||
@formatter.failure?.should be_true
|
||||
expect(@formatter.failure?).to be_truthy
|
||||
@formatter.load @state
|
||||
@formatter.failure?.should be_false
|
||||
expect(@formatter.failure?).to be_falsey
|
||||
end
|
||||
|
||||
it "resets the #exception? flag to false" do
|
||||
@formatter.exception?.should be_true
|
||||
expect(@formatter.exception?).to be_truthy
|
||||
@formatter.load @state
|
||||
@formatter.exception?.should be_false
|
||||
expect(@formatter.exception?).to be_falsey
|
||||
end
|
||||
end
|
||||
|
||||
describe FileFormatter, "#unload" do
|
||||
RSpec.describe FileFormatter, "#unload" do
|
||||
before :each do
|
||||
$stdout = @out = IOStub.new
|
||||
@formatter = FileFormatter.new
|
||||
|
@ -56,21 +56,21 @@ describe FileFormatter, "#unload" do
|
|||
|
||||
it "prints a '.' if there was no exception raised" do
|
||||
@formatter.unload(@state)
|
||||
@out.should == "."
|
||||
expect(@out).to eq(".")
|
||||
end
|
||||
|
||||
it "prints an 'F' if there was an expectation failure" do
|
||||
exc = SpecExpectationNotMetError.new "failed"
|
||||
@formatter.exception ExceptionState.new(@state, nil, exc)
|
||||
@formatter.unload(@state)
|
||||
@out.should == "F"
|
||||
expect(@out).to eq("F")
|
||||
end
|
||||
|
||||
it "prints an 'E' if there was an exception other than expectation failure" do
|
||||
exc = MSpecExampleError.new("boom!")
|
||||
@formatter.exception ExceptionState.new(@state, nil, exc)
|
||||
@formatter.unload(@state)
|
||||
@out.should == "E"
|
||||
expect(@out).to eq("E")
|
||||
end
|
||||
|
||||
it "prints an 'E' if there are mixed exceptions and exepctation failures" do
|
||||
|
@ -79,6 +79,6 @@ describe FileFormatter, "#unload" do
|
|||
exc = MSpecExampleError.new("boom!")
|
||||
@formatter.exception ExceptionState.new(@state, nil, exc)
|
||||
@formatter.unload(@state)
|
||||
@out.should == "E"
|
||||
expect(@out).to eq("E")
|
||||
end
|
||||
end
|
||||
|
|
|
@ -4,22 +4,23 @@ require 'mspec/runner/formatters/html'
|
|||
require 'mspec/runner/mspec'
|
||||
require 'mspec/runner/example'
|
||||
require 'mspec/utils/script'
|
||||
require 'mspec/helpers'
|
||||
|
||||
describe HtmlFormatter do
|
||||
RSpec.describe HtmlFormatter do
|
||||
before :each do
|
||||
@formatter = HtmlFormatter.new
|
||||
end
|
||||
|
||||
it "responds to #register by registering itself with MSpec for appropriate actions" do
|
||||
MSpec.stub(:register)
|
||||
MSpec.should_receive(:register).with(:start, @formatter)
|
||||
MSpec.should_receive(:register).with(:enter, @formatter)
|
||||
MSpec.should_receive(:register).with(:leave, @formatter)
|
||||
allow(MSpec).to receive(:register)
|
||||
expect(MSpec).to receive(:register).with(:start, @formatter)
|
||||
expect(MSpec).to receive(:register).with(:enter, @formatter)
|
||||
expect(MSpec).to receive(:register).with(:leave, @formatter)
|
||||
@formatter.register
|
||||
end
|
||||
end
|
||||
|
||||
describe HtmlFormatter, "#start" do
|
||||
RSpec.describe HtmlFormatter, "#start" do
|
||||
before :each do
|
||||
$stdout = @out = IOStub.new
|
||||
@formatter = HtmlFormatter.new
|
||||
|
@ -32,9 +33,8 @@ describe HtmlFormatter, "#start" do
|
|||
it "prints the HTML head" do
|
||||
@formatter.start
|
||||
ruby_engine = RUBY_ENGINE
|
||||
ruby_engine.should =~ /^#{ruby_engine}/
|
||||
@out.should ==
|
||||
%[<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
|
||||
expect(ruby_engine).to match(/^#{ruby_engine}/)
|
||||
expect(@out).to eq(%[<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
|
||||
"http://www.w3.org/TR/html4/strict.dtd">
|
||||
<html>
|
||||
<head>
|
||||
|
@ -55,11 +55,11 @@ ul {
|
|||
</style>
|
||||
</head>
|
||||
<body>
|
||||
]
|
||||
])
|
||||
end
|
||||
end
|
||||
|
||||
describe HtmlFormatter, "#enter" do
|
||||
RSpec.describe HtmlFormatter, "#enter" do
|
||||
before :each do
|
||||
$stdout = @out = IOStub.new
|
||||
@formatter = HtmlFormatter.new
|
||||
|
@ -71,11 +71,11 @@ describe HtmlFormatter, "#enter" do
|
|||
|
||||
it "prints the #describe string" do
|
||||
@formatter.enter "describe"
|
||||
@out.should == "<div><p>describe</p>\n<ul>\n"
|
||||
expect(@out).to eq("<div><p>describe</p>\n<ul>\n")
|
||||
end
|
||||
end
|
||||
|
||||
describe HtmlFormatter, "#leave" do
|
||||
RSpec.describe HtmlFormatter, "#leave" do
|
||||
before :each do
|
||||
$stdout = @out = IOStub.new
|
||||
@formatter = HtmlFormatter.new
|
||||
|
@ -87,11 +87,11 @@ describe HtmlFormatter, "#leave" do
|
|||
|
||||
it "prints the closing tags for the #describe string" do
|
||||
@formatter.leave
|
||||
@out.should == "</ul>\n</div>\n"
|
||||
expect(@out).to eq("</ul>\n</div>\n")
|
||||
end
|
||||
end
|
||||
|
||||
describe HtmlFormatter, "#exception" do
|
||||
RSpec.describe HtmlFormatter, "#exception" do
|
||||
before :each do
|
||||
$stdout = @out = IOStub.new
|
||||
@formatter = HtmlFormatter.new
|
||||
|
@ -108,14 +108,13 @@ describe HtmlFormatter, "#exception" do
|
|||
@formatter.exception exc
|
||||
exc = ExceptionState.new @state, nil, MSpecExampleError.new("painful")
|
||||
@formatter.exception exc
|
||||
@out.should ==
|
||||
%[<li class="fail">- it (<a href="#details-1">FAILED - 1</a>)</li>
|
||||
expect(@out).to eq(%[<li class="fail">- it (<a href="#details-1">FAILED - 1</a>)</li>
|
||||
<li class="fail">- it (<a href="#details-2">ERROR - 2</a>)</li>
|
||||
]
|
||||
])
|
||||
end
|
||||
end
|
||||
|
||||
describe HtmlFormatter, "#after" do
|
||||
RSpec.describe HtmlFormatter, "#after" do
|
||||
before :each do
|
||||
$stdout = @out = IOStub.new
|
||||
@formatter = HtmlFormatter.new
|
||||
|
@ -129,7 +128,7 @@ describe HtmlFormatter, "#after" do
|
|||
|
||||
it "prints the #it once when there are no exceptions raised" do
|
||||
@formatter.after @state
|
||||
@out.should == %[<li class="pass">- it</li>\n]
|
||||
expect(@out).to eq(%[<li class="pass">- it</li>\n])
|
||||
end
|
||||
|
||||
it "does not print any output if an exception is raised" do
|
||||
|
@ -137,68 +136,73 @@ describe HtmlFormatter, "#after" do
|
|||
@formatter.exception exc
|
||||
out = @out.dup
|
||||
@formatter.after @state
|
||||
@out.should == out
|
||||
expect(@out).to eq(out)
|
||||
end
|
||||
end
|
||||
|
||||
describe HtmlFormatter, "#finish" do
|
||||
RSpec.describe HtmlFormatter, "#finish" do
|
||||
before :each do
|
||||
@tally = double("tally").as_null_object
|
||||
TallyAction.stub(:new).and_return(@tally)
|
||||
allow(TallyAction).to receive(:new).and_return(@tally)
|
||||
@timer = double("timer").as_null_object
|
||||
TimerAction.stub(:new).and_return(@timer)
|
||||
allow(TimerAction).to receive(:new).and_return(@timer)
|
||||
|
||||
@out = tmp("HtmlFormatter")
|
||||
|
||||
$stdout = @out = IOStub.new
|
||||
context = ContextState.new "describe"
|
||||
@state = ExampleState.new(context, "it")
|
||||
MSpec.stub(:register)
|
||||
@formatter = HtmlFormatter.new
|
||||
allow(MSpec).to receive(:register)
|
||||
@formatter = HtmlFormatter.new(@out)
|
||||
@formatter.register
|
||||
@exception = MSpecExampleError.new("broken")
|
||||
@exception.stub(:backtrace).and_return(["file.rb:1", "file.rb:2"])
|
||||
allow(@exception).to receive(:backtrace).and_return(["file.rb:1", "file.rb:2"])
|
||||
end
|
||||
|
||||
after :each do
|
||||
$stdout = STDOUT
|
||||
rm_r @out
|
||||
end
|
||||
|
||||
it "prints a failure message for an exception" do
|
||||
exc = ExceptionState.new @state, nil, @exception
|
||||
@formatter.exception exc
|
||||
@formatter.finish
|
||||
@out.should include "<p>describe it ERROR</p>"
|
||||
output = File.read(@out)
|
||||
expect(output).to include "<p>describe it ERROR</p>"
|
||||
end
|
||||
|
||||
it "prints a backtrace for an exception" do
|
||||
exc = ExceptionState.new @state, nil, @exception
|
||||
exc.stub(:backtrace).and_return("path/to/some/file.rb:35:in method")
|
||||
allow(exc).to receive(:backtrace).and_return("path/to/some/file.rb:35:in method")
|
||||
@formatter.exception exc
|
||||
@formatter.finish
|
||||
@out.should =~ %r[<pre>.*path/to/some/file.rb:35:in method.*</pre>]m
|
||||
output = File.read(@out)
|
||||
expect(output).to match(%r[<pre>.*path/to/some/file.rb:35:in method.*</pre>]m)
|
||||
end
|
||||
|
||||
it "prints a summary of elapsed time" do
|
||||
@timer.should_receive(:format).and_return("Finished in 2.0 seconds")
|
||||
expect(@timer).to receive(:format).and_return("Finished in 2.0 seconds")
|
||||
@formatter.finish
|
||||
@out.should include "<p>Finished in 2.0 seconds</p>\n"
|
||||
output = File.read(@out)
|
||||
expect(output).to include "<p>Finished in 2.0 seconds</p>\n"
|
||||
end
|
||||
|
||||
it "prints a tally of counts" do
|
||||
@tally.should_receive(:format).and_return("1 example, 0 failures")
|
||||
expect(@tally).to receive(:format).and_return("1 example, 0 failures")
|
||||
@formatter.finish
|
||||
@out.should include '<p class="pass">1 example, 0 failures</p>'
|
||||
output = File.read(@out)
|
||||
expect(output).to include '<p class="pass">1 example, 0 failures</p>'
|
||||
end
|
||||
|
||||
it "prints errors, backtraces, elapsed time, and tallies" do
|
||||
exc = ExceptionState.new @state, nil, @exception
|
||||
exc.stub(:backtrace).and_return("path/to/some/file.rb:35:in method")
|
||||
allow(exc).to receive(:backtrace).and_return("path/to/some/file.rb:35:in method")
|
||||
@formatter.exception exc
|
||||
|
||||
@timer.should_receive(:format).and_return("Finished in 2.0 seconds")
|
||||
@tally.should_receive(:format).and_return("1 example, 1 failures")
|
||||
expect(@timer).to receive(:format).and_return("Finished in 2.0 seconds")
|
||||
expect(@tally).to receive(:format).and_return("1 example, 1 failures")
|
||||
@formatter.finish
|
||||
@out.should ==
|
||||
%[<li class=\"fail\">- it (<a href=\"#details-1\">ERROR - 1</a>)</li>
|
||||
output = File.read(@out)
|
||||
expect(output).to eq(%[<li class=\"fail\">- it (<a href=\"#details-1\">ERROR - 1</a>)</li>
|
||||
<hr>
|
||||
<ol id="details">
|
||||
<li id="details-1"><p>describe it ERROR</p>
|
||||
|
@ -211,6 +215,6 @@ path/to/some/file.rb:35:in method</pre>
|
|||
<p class="fail">1 example, 1 failures</p>
|
||||
</body>
|
||||
</html>
|
||||
]
|
||||
])
|
||||
end
|
||||
end
|
||||
|
|
|
@ -2,22 +2,23 @@
|
|||
require File.dirname(__FILE__) + '/../../spec_helper'
|
||||
require 'mspec/runner/formatters/junit'
|
||||
require 'mspec/runner/example'
|
||||
require 'mspec/helpers'
|
||||
|
||||
describe JUnitFormatter, "#initialize" do
|
||||
RSpec.describe JUnitFormatter, "#initialize" do
|
||||
it "permits zero arguments" do
|
||||
lambda { JUnitFormatter.new }.should_not raise_error
|
||||
expect { JUnitFormatter.new }.not_to raise_error
|
||||
end
|
||||
|
||||
it "accepts one argument" do
|
||||
lambda { JUnitFormatter.new nil }.should_not raise_error
|
||||
expect { JUnitFormatter.new nil }.not_to raise_error
|
||||
end
|
||||
end
|
||||
|
||||
describe JUnitFormatter, "#print" do
|
||||
RSpec.describe JUnitFormatter, "#print" do
|
||||
before :each do
|
||||
$stdout = IOStub.new
|
||||
@out = IOStub.new
|
||||
File.stub(:open).and_return(@out)
|
||||
allow(File).to receive(:open).and_return(@out)
|
||||
@formatter = JUnitFormatter.new "some/file"
|
||||
end
|
||||
|
||||
|
@ -27,121 +28,132 @@ describe JUnitFormatter, "#print" do
|
|||
|
||||
it "writes to $stdout if #switch has not been called" do
|
||||
@formatter.print "begonias"
|
||||
$stdout.should == "begonias"
|
||||
@out.should == ""
|
||||
expect($stdout).to eq("begonias")
|
||||
expect(@out).to eq("")
|
||||
end
|
||||
|
||||
it "writes to the file passed to #initialize once #switch has been called" do
|
||||
@formatter.switch
|
||||
@formatter.print "begonias"
|
||||
$stdout.should == ""
|
||||
@out.should == "begonias"
|
||||
expect($stdout).to eq("")
|
||||
expect(@out).to eq("begonias")
|
||||
end
|
||||
|
||||
it "writes to $stdout once #switch is called if no file was passed to #initialize" do
|
||||
formatter = JUnitFormatter.new
|
||||
formatter.switch
|
||||
formatter.print "begonias"
|
||||
$stdout.should == "begonias"
|
||||
@out.should == ""
|
||||
expect($stdout).to eq("begonias")
|
||||
expect(@out).to eq("")
|
||||
end
|
||||
end
|
||||
|
||||
describe JUnitFormatter, "#finish" do
|
||||
RSpec.describe JUnitFormatter, "#finish" do
|
||||
before :each do
|
||||
@tally = double("tally").as_null_object
|
||||
@counter = double("counter").as_null_object
|
||||
@tally.stub(:counter).and_return(@counter)
|
||||
TallyAction.stub(:new).and_return(@tally)
|
||||
allow(@tally).to receive(:counter).and_return(@counter)
|
||||
allow(TallyAction).to receive(:new).and_return(@tally)
|
||||
|
||||
@timer = double("timer").as_null_object
|
||||
TimerAction.stub(:new).and_return(@timer)
|
||||
allow(TimerAction).to receive(:new).and_return(@timer)
|
||||
|
||||
@out = tmp("JUnitFormatter")
|
||||
|
||||
$stdout = IOStub.new
|
||||
context = ContextState.new "describe"
|
||||
@state = ExampleState.new(context, "it")
|
||||
|
||||
@formatter = JUnitFormatter.new
|
||||
@formatter.stub(:backtrace).and_return("")
|
||||
MSpec.stub(:register)
|
||||
@formatter = JUnitFormatter.new(@out)
|
||||
allow(@formatter).to receive(:backtrace).and_return("")
|
||||
allow(MSpec).to receive(:register)
|
||||
@formatter.register
|
||||
|
||||
exc = ExceptionState.new @state, nil, MSpecExampleError.new("broken")
|
||||
exc.stub(:backtrace).and_return("path/to/some/file.rb:35:in method")
|
||||
allow(exc).to receive(:backtrace).and_return("path/to/some/file.rb:35:in method")
|
||||
@formatter.exception exc
|
||||
@formatter.after @state
|
||||
end
|
||||
|
||||
after :each do
|
||||
$stdout = STDOUT
|
||||
rm_r @out
|
||||
end
|
||||
|
||||
it "calls #switch" do
|
||||
@formatter.should_receive(:switch)
|
||||
expect(@formatter).to receive(:switch).and_call_original
|
||||
@formatter.finish
|
||||
end
|
||||
|
||||
it "outputs a failure message and backtrace" do
|
||||
@formatter.finish
|
||||
$stdout.should include 'message="error in describe it" type="error"'
|
||||
$stdout.should include "MSpecExampleError: broken\n"
|
||||
$stdout.should include "path/to/some/file.rb:35:in method"
|
||||
output = File.read(@out)
|
||||
expect(output).to include 'message="error in describe it" type="error"'
|
||||
expect(output).to include "MSpecExampleError: broken\n"
|
||||
expect(output).to include "path/to/some/file.rb:35:in method"
|
||||
end
|
||||
|
||||
it "encodes message and backtrace in latin1 for jenkins" do
|
||||
exc = ExceptionState.new @state, nil, MSpecExampleError.new("broken…")
|
||||
exc.stub(:backtrace).and_return("path/to/some/file.rb:35:in methød")
|
||||
allow(exc).to receive(:backtrace).and_return("path/to/some/file.rb:35:in methød")
|
||||
@formatter.exception exc
|
||||
@formatter.finish
|
||||
$stdout.should =~ /MSpecExampleError: broken((\.\.\.)|\?)\n/
|
||||
$stdout.should =~ /path\/to\/some\/file\.rb:35:in meth(\?|o)d/
|
||||
output = File.binread(@out)
|
||||
expect(output).to match(/MSpecExampleError: broken((\.\.\.)|\?)\n/)
|
||||
expect(output).to match(/path\/to\/some\/file\.rb:35:in meth(\?|o)d/)
|
||||
end
|
||||
|
||||
it "outputs an elapsed time" do
|
||||
@timer.should_receive(:elapsed).and_return(4.2)
|
||||
expect(@timer).to receive(:elapsed).and_return(4.2)
|
||||
@formatter.finish
|
||||
$stdout.should include 'time="4.2"'
|
||||
output = File.read(@out)
|
||||
expect(output).to include 'time="4.2"'
|
||||
end
|
||||
|
||||
it "outputs overall elapsed time" do
|
||||
@timer.should_receive(:elapsed).and_return(4.2)
|
||||
expect(@timer).to receive(:elapsed).and_return(4.2)
|
||||
@formatter.finish
|
||||
$stdout.should include 'timeCount="4.2"'
|
||||
output = File.read(@out)
|
||||
expect(output).to include 'timeCount="4.2"'
|
||||
end
|
||||
|
||||
it "outputs the number of examples as test count" do
|
||||
@counter.should_receive(:examples).and_return(9)
|
||||
expect(@counter).to receive(:examples).and_return(9)
|
||||
@formatter.finish
|
||||
$stdout.should include 'tests="9"'
|
||||
output = File.read(@out)
|
||||
expect(output).to include 'tests="9"'
|
||||
end
|
||||
|
||||
it "outputs overall number of examples as test count" do
|
||||
@counter.should_receive(:examples).and_return(9)
|
||||
expect(@counter).to receive(:examples).and_return(9)
|
||||
@formatter.finish
|
||||
$stdout.should include 'testCount="9"'
|
||||
output = File.read(@out)
|
||||
expect(output).to include 'testCount="9"'
|
||||
end
|
||||
|
||||
it "outputs a failure count" do
|
||||
@counter.should_receive(:failures).and_return(2)
|
||||
expect(@counter).to receive(:failures).and_return(2)
|
||||
@formatter.finish
|
||||
$stdout.should include 'failureCount="2"'
|
||||
output = File.read(@out)
|
||||
expect(output).to include 'failureCount="2"'
|
||||
end
|
||||
|
||||
it "outputs overall failure count" do
|
||||
@counter.should_receive(:failures).and_return(2)
|
||||
expect(@counter).to receive(:failures).and_return(2)
|
||||
@formatter.finish
|
||||
$stdout.should include 'failures="2"'
|
||||
output = File.read(@out)
|
||||
expect(output).to include 'failures="2"'
|
||||
end
|
||||
|
||||
it "outputs an error count" do
|
||||
@counter.should_receive(:errors).and_return(1)
|
||||
expect(@counter).to receive(:errors).and_return(1)
|
||||
@formatter.finish
|
||||
$stdout.should include 'errors="1"'
|
||||
output = File.read(@out)
|
||||
expect(output).to include 'errors="1"'
|
||||
end
|
||||
|
||||
it "outputs overall error count" do
|
||||
@counter.should_receive(:errors).and_return(1)
|
||||
expect(@counter).to receive(:errors).and_return(1)
|
||||
@formatter.finish
|
||||
$stdout.should include 'errorCount="1"'
|
||||
output = File.read(@out)
|
||||
expect(output).to include 'errorCount="1"'
|
||||
end
|
||||
end
|
||||
|
|
|
@ -4,29 +4,29 @@ require 'mspec/runner/mspec'
|
|||
require 'mspec/runner/example'
|
||||
require 'mspec/utils/script'
|
||||
|
||||
describe MethodFormatter, "#method_type" do
|
||||
RSpec.describe MethodFormatter, "#method_type" do
|
||||
before :each do
|
||||
@formatter = MethodFormatter.new
|
||||
end
|
||||
|
||||
it "returns 'class' if the separator is '.' or '::'" do
|
||||
@formatter.method_type('.').should == "class"
|
||||
@formatter.method_type('::').should == "class"
|
||||
expect(@formatter.method_type('.')).to eq("class")
|
||||
expect(@formatter.method_type('::')).to eq("class")
|
||||
end
|
||||
|
||||
it "returns 'instance' if the separator is '#'" do
|
||||
@formatter.method_type('#').should == "instance"
|
||||
expect(@formatter.method_type('#')).to eq("instance")
|
||||
end
|
||||
|
||||
it "returns 'unknown' for all other cases" do
|
||||
@formatter.method_type(nil).should == "unknown"
|
||||
expect(@formatter.method_type(nil)).to eq("unknown")
|
||||
end
|
||||
end
|
||||
|
||||
describe MethodFormatter, "#before" do
|
||||
RSpec.describe MethodFormatter, "#before" do
|
||||
before :each do
|
||||
@formatter = MethodFormatter.new
|
||||
MSpec.stub(:register)
|
||||
allow(MSpec).to receive(:register)
|
||||
@formatter.register
|
||||
end
|
||||
|
||||
|
@ -38,32 +38,32 @@ describe MethodFormatter, "#before" do
|
|||
|
||||
state = ExampleState.new ContextState.new("describe"), "it"
|
||||
@formatter.before state
|
||||
@formatter.tally.counter.examples.should == 0
|
||||
@formatter.tally.counter.expectations.should == 0
|
||||
@formatter.tally.counter.failures.should == 0
|
||||
@formatter.tally.counter.errors.should == 0
|
||||
expect(@formatter.tally.counter.examples).to eq(0)
|
||||
expect(@formatter.tally.counter.expectations).to eq(0)
|
||||
expect(@formatter.tally.counter.failures).to eq(0)
|
||||
expect(@formatter.tally.counter.errors).to eq(0)
|
||||
end
|
||||
|
||||
it "records the class, method if available" do
|
||||
state = ExampleState.new ContextState.new("Some#method"), "it"
|
||||
@formatter.before state
|
||||
key = "Some#method"
|
||||
@formatter.methods.keys.should include(key)
|
||||
expect(@formatter.methods.keys).to include(key)
|
||||
h = @formatter.methods[key]
|
||||
h[:class].should == "Some"
|
||||
h[:method].should == "method"
|
||||
h[:description].should == "Some#method it"
|
||||
expect(h[:class]).to eq("Some")
|
||||
expect(h[:method]).to eq("method")
|
||||
expect(h[:description]).to eq("Some#method it")
|
||||
end
|
||||
|
||||
it "does not record class, method unless both are available" do
|
||||
state = ExampleState.new ContextState.new("Some method"), "it"
|
||||
@formatter.before state
|
||||
key = "Some method"
|
||||
@formatter.methods.keys.should include(key)
|
||||
expect(@formatter.methods.keys).to include(key)
|
||||
h = @formatter.methods[key]
|
||||
h[:class].should == ""
|
||||
h[:method].should == ""
|
||||
h[:description].should == "Some method it"
|
||||
expect(h[:class]).to eq("")
|
||||
expect(h[:method]).to eq("")
|
||||
expect(h[:description]).to eq("Some method it")
|
||||
end
|
||||
|
||||
it "sets the method type to unknown if class and method are not available" do
|
||||
|
@ -71,7 +71,7 @@ describe MethodFormatter, "#before" do
|
|||
@formatter.before state
|
||||
key = "Some method"
|
||||
h = @formatter.methods[key]
|
||||
h[:type].should == "unknown"
|
||||
expect(h[:type]).to eq("unknown")
|
||||
end
|
||||
|
||||
it "sets the method type based on the class, method separator" do
|
||||
|
@ -79,7 +79,7 @@ describe MethodFormatter, "#before" do
|
|||
state = ExampleState.new ContextState.new(k), "it"
|
||||
@formatter.before state
|
||||
h = @formatter.methods[k]
|
||||
h[:type].should == t
|
||||
expect(h[:type]).to eq(t)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -87,14 +87,14 @@ describe MethodFormatter, "#before" do
|
|||
state = ExampleState.new ContextState.new("describe"), "it"
|
||||
@formatter.exceptions << "stuff"
|
||||
@formatter.before state
|
||||
@formatter.exceptions.should be_empty
|
||||
expect(@formatter.exceptions).to be_empty
|
||||
end
|
||||
end
|
||||
|
||||
describe MethodFormatter, "#after" do
|
||||
RSpec.describe MethodFormatter, "#after" do
|
||||
before :each do
|
||||
@formatter = MethodFormatter.new
|
||||
MSpec.stub(:register)
|
||||
allow(MSpec).to receive(:register)
|
||||
@formatter.register
|
||||
end
|
||||
|
||||
|
@ -109,10 +109,10 @@ describe MethodFormatter, "#after" do
|
|||
|
||||
@formatter.after state
|
||||
h = @formatter.methods["Some#method"]
|
||||
h[:examples].should == 3
|
||||
h[:expectations].should == 4
|
||||
h[:failures].should == 2
|
||||
h[:errors].should == 1
|
||||
expect(h[:examples]).to eq(3)
|
||||
expect(h[:expectations]).to eq(4)
|
||||
expect(h[:failures]).to eq(2)
|
||||
expect(h[:errors]).to eq(1)
|
||||
end
|
||||
|
||||
it "renders the list of exceptions" do
|
||||
|
@ -125,20 +125,20 @@ describe MethodFormatter, "#after" do
|
|||
|
||||
@formatter.after state
|
||||
h = @formatter.methods["Some#method"]
|
||||
h[:exceptions].should == [
|
||||
expect(h[:exceptions]).to eq([
|
||||
%[failed\n\n],
|
||||
%[failed\n\n]
|
||||
]
|
||||
])
|
||||
end
|
||||
end
|
||||
|
||||
describe MethodFormatter, "#after" do
|
||||
RSpec.describe MethodFormatter, "#after" do
|
||||
before :each do
|
||||
$stdout = IOStub.new
|
||||
context = ContextState.new "Class#method"
|
||||
@state = ExampleState.new(context, "runs")
|
||||
@formatter = MethodFormatter.new
|
||||
MSpec.stub(:register)
|
||||
allow(MSpec).to receive(:register)
|
||||
@formatter.register
|
||||
end
|
||||
|
||||
|
@ -159,8 +159,7 @@ describe MethodFormatter, "#after" do
|
|||
|
||||
@formatter.after @state
|
||||
@formatter.finish
|
||||
$stdout.should ==
|
||||
%[---
|
||||
expect($stdout).to eq(%[---
|
||||
"Class#method":
|
||||
class: "Class"
|
||||
method: "method"
|
||||
|
@ -173,6 +172,6 @@ describe MethodFormatter, "#after" do
|
|||
exceptions:
|
||||
- "failed\\n\\n"
|
||||
- "failed\\n\\n"
|
||||
]
|
||||
])
|
||||
end
|
||||
end
|
||||
|
|
Некоторые файлы не были показаны из-за слишком большого количества измененных файлов Показать больше
Загрузка…
Ссылка в новой задаче