mirror of
https://github.com/TracksApp/tracks.git
synced 2026-03-06 04:40:18 +01:00
Next step in upgrading Tracks to Rails 2.2. Some highlights:
* Ran rake rails:update * Added old actionwebservice framework * Updated RSpec and RSpec-Rails * Removed asset_packager plugin (not compatible, Scott no longer maintaining), and replaced with bundle_fu. See the bundle_fu README for more info. * Hacks to UJS and ARTS plugins, which are no longer supported. Probably should move off both UJS and RJS. * Hack to flashobject_helper plugin (upgrade to Rails 2.2-compatible version if/when it comes out.) * Hack to skinny-spec plugin, for Rails 2.2 compatibility. Should check for official release. * Hacks to resource_feeder plugin, for Rails 2.2 compatibility. Should check for official release (not likely) or move off it. * Addressed some deprecation warnings. More to come. * My mobile mime type hackery is no longer necessary with new Rails features. Yay! * Updated environment.rb.tmpl with changes TODO: * Restore view specs marked pending * Fix failing integration tests. * Try selenium tests. * Investigate OpenID support. * Address deprecation warnings. * Consider moving parts of environment.rb to initializers * Address annoying config.gem warning about highline gem
This commit is contained in:
parent
6d11ebd1b0
commit
35ae5fc431
394 changed files with 15184 additions and 9936 deletions
|
|
@ -1,6 +1,6 @@
|
|||
require "rubygems"
|
||||
require 'autotest'
|
||||
dir = File.dirname(__FILE__)
|
||||
require "#{dir}/spec_helper"
|
||||
require File.expand_path("#{dir}/../lib/autotest/rspec")
|
||||
require "#{dir}/../spec_helper"
|
||||
require File.expand_path("#{dir}/../../lib/autotest/rspec")
|
||||
require "#{dir}/autotest_matchers"
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
require File.dirname(__FILE__) + "/../autotest_helper"
|
||||
require File.dirname(__FILE__) + "/autotest_helper"
|
||||
|
||||
module DiscoveryHelper
|
||||
def load_discovery
|
||||
|
|
|
|||
80
vendor/plugins/rspec/spec/autotest/rspec_spec.rb
vendored
80
vendor/plugins/rspec/spec/autotest/rspec_spec.rb
vendored
|
|
@ -1,4 +1,4 @@
|
|||
require File.dirname(__FILE__) + "/../autotest_helper"
|
||||
require File.dirname(__FILE__) + "/autotest_helper"
|
||||
|
||||
class Autotest
|
||||
|
||||
|
|
@ -37,62 +37,6 @@ HERE
|
|||
end
|
||||
|
||||
describe Rspec do
|
||||
describe "selection of rspec command" do
|
||||
include AutotestHelper
|
||||
|
||||
before(:each) do
|
||||
common_setup
|
||||
@rspec_autotest = Rspec.new
|
||||
end
|
||||
|
||||
it "should try to find the spec command if it exists in ./bin and use it above everything else" do
|
||||
File.stub!(:exists?).and_return true
|
||||
|
||||
spec_path = File.expand_path("#{File.dirname(__FILE__)}/../../bin/spec")
|
||||
File.should_receive(:exists?).with(spec_path).and_return true
|
||||
@rspec_autotest.spec_command.should == spec_path
|
||||
end
|
||||
|
||||
it "should otherwise select the default spec command in gem_dir/bin/spec" do
|
||||
@rspec_autotest.stub!(:spec_commands).and_return ["/foo/spec"]
|
||||
Config::CONFIG.stub!(:[]).and_return "/foo"
|
||||
File.should_receive(:exists?).with("/foo/spec").and_return(true)
|
||||
|
||||
@rspec_autotest.spec_command.should == "/foo/spec"
|
||||
end
|
||||
|
||||
it "should raise an error if no spec command is found at all" do
|
||||
File.stub!(:exists?).and_return false
|
||||
|
||||
lambda {
|
||||
@rspec_autotest.spec_command
|
||||
}.should raise_error(RspecCommandError, "No spec command could be found!")
|
||||
end
|
||||
end
|
||||
|
||||
describe "selection of rspec command (windows compatibility issues)" do
|
||||
include AutotestHelper
|
||||
|
||||
before(:each) do
|
||||
common_setup
|
||||
end
|
||||
|
||||
it "should use the ALT_SEPARATOR if it is non-nil" do
|
||||
@rspec_autotest = Rspec.new
|
||||
spec_command = File.expand_path("#{File.dirname(__FILE__)}/../../bin/spec")
|
||||
@rspec_autotest.stub!(:spec_commands).and_return [spec_command]
|
||||
@rspec_autotest.spec_command(@windows_alt_separator).should == spec_command.gsub('/', @windows_alt_separator)
|
||||
end
|
||||
|
||||
it "should not use the ALT_SEPATOR if it is nil" do
|
||||
@windows_alt_separator = nil
|
||||
@rspec_autotest = Rspec.new
|
||||
spec_command = File.expand_path("#{File.dirname(__FILE__)}/../../bin/spec")
|
||||
@rspec_autotest.stub!(:spec_commands).and_return [spec_command]
|
||||
@rspec_autotest.spec_command.should == spec_command
|
||||
end
|
||||
end
|
||||
|
||||
describe "adding spec.opts --options" do
|
||||
before(:each) do
|
||||
@rspec_autotest = Rspec.new
|
||||
|
|
@ -116,7 +60,6 @@ HERE
|
|||
@rspec_autotest.stub!(:add_options_if_present).and_return "-O spec/spec.opts"
|
||||
|
||||
@ruby = @rspec_autotest.ruby
|
||||
@spec_command = @rspec_autotest.spec_command
|
||||
@options = @rspec_autotest.add_options_if_present
|
||||
@files_to_test = {
|
||||
:spec => ["file_one", "file_two"]
|
||||
|
|
@ -126,16 +69,13 @@ HERE
|
|||
@files_to_test.stub!(:keys).and_return @files_to_test[:spec]
|
||||
@to_test = @files_to_test.keys.flatten.join ' '
|
||||
end
|
||||
|
||||
it "should contain the various commands, ordered by preference" do
|
||||
Rspec.new.spec_commands.should == [
|
||||
File.expand_path("#{File.dirname(__FILE__)}/../../bin/spec"),
|
||||
"#{Config::CONFIG['bindir']}/spec"
|
||||
]
|
||||
end
|
||||
|
||||
it "should make the apropriate test command" do
|
||||
@rspec_autotest.make_test_cmd(@files_to_test).should == "#{@ruby} -S #{@spec_command} #{@options} #{@to_test}"
|
||||
it "should make the appropriate test command" do
|
||||
@rspec_autotest.make_test_cmd(@files_to_test).should == "#{@ruby} -S #{@to_test} #{@options}"
|
||||
end
|
||||
|
||||
it "should return a blank command for no files" do
|
||||
@rspec_autotest.make_test_cmd({}).should == ''
|
||||
end
|
||||
end
|
||||
|
||||
|
|
@ -156,7 +96,11 @@ HERE
|
|||
@rspec_autotest.should map_specs([@spec_file]).to(@spec_file)
|
||||
end
|
||||
|
||||
it "should only find the file if the file is being tracked (in @file)" do
|
||||
it "should ignore files in spec dir that aren't specs" do
|
||||
@rspec_autotest.should map_specs([]).to("spec/spec_helper.rb")
|
||||
end
|
||||
|
||||
it "should ignore untracked files (in @file)" do
|
||||
@rspec_autotest.should map_specs([]).to("lib/untracked_file")
|
||||
end
|
||||
end
|
||||
|
|
|
|||
1
vendor/plugins/rspec/spec/rspec_suite.rb
vendored
1
vendor/plugins/rspec/spec/rspec_suite.rb
vendored
|
|
@ -1,7 +1,6 @@
|
|||
if __FILE__ == $0
|
||||
dir = File.dirname(__FILE__)
|
||||
Dir["#{dir}/**/*_spec.rb"].reverse.each do |file|
|
||||
# puts "require '#{file}'"
|
||||
require file
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -7,4 +7,10 @@ describe Spec::Adapters::RubyEngine do
|
|||
Spec::Adapters::RubyEngine.stub!(:engine).and_return('rbx')
|
||||
Spec::Adapters::RubyEngine.adapter.should be_an_instance_of(Spec::Adapters::RubyEngine::Rubinius)
|
||||
end
|
||||
|
||||
it "should try to find whatever is defined by the RUBY_ENGINE const" do
|
||||
Object.stub!(:const_defined?).with('RUBY_ENGINE').and_return(true)
|
||||
Object.stub!(:const_get).with('RUBY_ENGINE').and_return("xyz")
|
||||
Spec::Adapters::RubyEngine.engine.should == "xyz"
|
||||
end
|
||||
end
|
||||
|
|
@ -125,14 +125,14 @@ module Spec
|
|||
it "should register ExampleGroup by default" do
|
||||
example_group = Spec::Example::ExampleGroupFactory.create_example_group("The ExampleGroup") do
|
||||
end
|
||||
rspec_options.example_groups.should include(example_group)
|
||||
Spec::Runner.options.example_groups.should include(example_group)
|
||||
end
|
||||
|
||||
it "should enable unregistering of ExampleGroups" do
|
||||
example_group = Spec::Example::ExampleGroupFactory.create_example_group("The ExampleGroup") do
|
||||
unregister
|
||||
end
|
||||
rspec_options.example_groups.should_not include(example_group)
|
||||
Spec::Runner.options.example_groups.should_not include(example_group)
|
||||
end
|
||||
|
||||
after(:each) do
|
||||
|
|
|
|||
|
|
@ -3,10 +3,12 @@ require File.dirname(__FILE__) + '/../../spec_helper'
|
|||
module Spec
|
||||
module Example
|
||||
describe 'ExampleGroupMethods' do
|
||||
it_should_behave_like "sandboxed rspec_options"
|
||||
include SandboxedOptions
|
||||
attr_reader :example_group, :result, :reporter
|
||||
before(:each) do
|
||||
options.formatters << mock("formatter", :null_object => true)
|
||||
# See http://rspec.lighthouseapp.com/projects/5645-rspec/tickets/525-arity-changed-on-partial-mocks#ticket-525-2
|
||||
method_with_three_args = lambda { |arg1, arg2, arg3| }
|
||||
options.formatters << mock("formatter", :null_object => true, :example_pending => method_with_three_args)
|
||||
options.backtrace_tweaker = mock("backtrace_tweaker", :null_object => true)
|
||||
@reporter = FakeReporter.new(@options)
|
||||
options.reporter = reporter
|
||||
|
|
@ -25,7 +27,7 @@ module Spec
|
|||
end
|
||||
|
||||
["describe","context"].each do |method|
|
||||
describe "#{method}" do
|
||||
describe "##{method}" do
|
||||
describe "when creating an ExampleGroup" do
|
||||
attr_reader :child_example_group
|
||||
before do
|
||||
|
|
@ -567,6 +569,13 @@ module Spec
|
|||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "#options" do
|
||||
it "should expose the options hash" do
|
||||
group = describe("group", :this => 'hash') {}
|
||||
group.options[:this].should == 'hash'
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -65,10 +65,11 @@ module Spec
|
|||
end
|
||||
|
||||
describe ExampleGroup, "#run" do
|
||||
it_should_behave_like "sandboxed rspec_options"
|
||||
include SandboxedOptions
|
||||
attr_reader :example_group, :formatter, :reporter
|
||||
before :each do
|
||||
@formatter = mock("formatter", :null_object => true)
|
||||
method_with_three_args = lambda { |arg1, arg2, arg3| }
|
||||
@formatter = mock("formatter", :null_object => true, :example_pending => method_with_three_args)
|
||||
options.formatters << formatter
|
||||
options.backtrace_tweaker = mock("backtrace_tweaker", :null_object => true)
|
||||
@reporter = FakeReporter.new(options)
|
||||
|
|
@ -233,7 +234,7 @@ module Spec
|
|||
options.examples = ["should be run"]
|
||||
end
|
||||
|
||||
it "should run only the example, when there in only one" do
|
||||
it "should run only the example, when there is only one" do
|
||||
example_group.run
|
||||
examples_that_were_run.should == ["should be run"]
|
||||
end
|
||||
|
|
|
|||
|
|
@ -23,9 +23,9 @@ module Spec
|
|||
|
||||
describe "lifecycle" do
|
||||
before do
|
||||
@original_rspec_options = $rspec_options
|
||||
@original_rspec_options = Spec::Runner.options
|
||||
@options = ::Spec::Runner::Options.new(StringIO.new, StringIO.new)
|
||||
$rspec_options = @options
|
||||
Spec::Runner.use @options
|
||||
@options.formatters << mock("formatter", :null_object => true)
|
||||
@options.backtrace_tweaker = mock("backtrace_tweaker", :null_object => true)
|
||||
@reporter = FakeReporter.new(@options)
|
||||
|
|
@ -43,7 +43,7 @@ module Spec
|
|||
end
|
||||
|
||||
after do
|
||||
$rspec_options = @original_rspec_options
|
||||
Spec::Runner.use @original_rspec_options
|
||||
ExampleMethods.instance_variable_set("@before_all_parts", [])
|
||||
ExampleMethods.instance_variable_set("@before_each_parts", [])
|
||||
ExampleMethods.instance_variable_set("@after_each_parts", [])
|
||||
|
|
@ -83,19 +83,56 @@ module Spec
|
|||
ExampleMethods.count.should == 7
|
||||
end
|
||||
|
||||
describe "run_with_description_capturing" do
|
||||
describe "eval_block" do
|
||||
before(:each) do
|
||||
@example_group = Class.new(ExampleGroup) do end
|
||||
@example = @example_group.new("foo", &(lambda { 2.should == 2 }))
|
||||
@example.run_with_description_capturing
|
||||
@example_group = Class.new(ExampleGroup)
|
||||
end
|
||||
|
||||
describe "with a given description" do
|
||||
it "should provide the given description" do
|
||||
@example = @example_group.it("given description") { 2.should == 2 }
|
||||
@example.eval_block
|
||||
@example.description.should == "given description"
|
||||
end
|
||||
end
|
||||
|
||||
it "should provide the generated description" do
|
||||
@example.instance_eval { @_matcher_description }.should == "should == 2"
|
||||
describe "with no given description" do
|
||||
it "should provide the generated description" do
|
||||
@example = @example_group.it { 2.should == 2 }
|
||||
@example.eval_block
|
||||
@example.description.should == "should == 2"
|
||||
end
|
||||
end
|
||||
|
||||
it "should clear the global generated_description" do
|
||||
Spec::Matchers.generated_description.should == nil
|
||||
|
||||
describe "with no implementation" do
|
||||
it "should raise an NotYetImplementedError" do
|
||||
lambda {
|
||||
@example = @example_group.it
|
||||
@example.eval_block
|
||||
}.should raise_error(Spec::Example::NotYetImplementedError, "Not Yet Implemented")
|
||||
end
|
||||
|
||||
def extract_error(&blk)
|
||||
begin
|
||||
blk.call
|
||||
rescue Exception => e
|
||||
return e
|
||||
end
|
||||
|
||||
nil
|
||||
end
|
||||
|
||||
it "should use the proper file and line number for the NotYetImplementedError" do
|
||||
file = __FILE__
|
||||
line_number = __LINE__ + 3
|
||||
|
||||
error = extract_error do
|
||||
@example = @example_group.it
|
||||
@example.eval_block
|
||||
end
|
||||
|
||||
error.pending_caller.should == "#{file}:#{line_number}"
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -122,5 +159,14 @@ module Spec
|
|||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "#options" do
|
||||
it "should expose the options hash" do
|
||||
example_group = Class.new(ExampleGroup)
|
||||
example = example_group.example "name", :this => 'that' do; end
|
||||
example.options[:this].should == 'that'
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -1,53 +0,0 @@
|
|||
require File.dirname(__FILE__) + '/../../spec_helper'
|
||||
|
||||
module Spec
|
||||
module Example
|
||||
# describe Example do
|
||||
# before(:each) do
|
||||
# @example = Example.new "example" do
|
||||
# foo
|
||||
# end
|
||||
# end
|
||||
#
|
||||
# it "should tell you its docstring" do
|
||||
# @example.description.should == "example"
|
||||
# end
|
||||
#
|
||||
# it "should execute its block in the context provided" do
|
||||
# context = Class.new do
|
||||
# def foo
|
||||
# "foo"
|
||||
# end
|
||||
# end.new
|
||||
# @example.run_in(context).should == "foo"
|
||||
# end
|
||||
# end
|
||||
#
|
||||
# describe Example, "#description" do
|
||||
# it "should default to NO NAME when not passed anything when there are no matchers" do
|
||||
# example = Example.new {}
|
||||
# example.run_in(Object.new)
|
||||
# example.description.should == "NO NAME"
|
||||
# end
|
||||
#
|
||||
# it "should default to NO NAME description (Because of --dry-run) when passed nil and there are no matchers" do
|
||||
# example = Example.new(nil) {}
|
||||
# example.run_in(Object.new)
|
||||
# example.description.should == "NO NAME"
|
||||
# end
|
||||
#
|
||||
# it "should allow description to be overridden" do
|
||||
# example = Example.new("Test description")
|
||||
# example.description.should == "Test description"
|
||||
# end
|
||||
#
|
||||
# it "should use description generated from matcher when there is no passed in description" do
|
||||
# example = Example.new(nil) do
|
||||
# 1.should == 1
|
||||
# end
|
||||
# example.run_in(Object.new)
|
||||
# example.description.should == "should == 1"
|
||||
# end
|
||||
# end
|
||||
end
|
||||
end
|
||||
|
|
@ -18,6 +18,17 @@ module Spec
|
|||
}.should raise_error(ExamplePendingError, /TODO/)
|
||||
end
|
||||
|
||||
it 'should raise an ExamplePendingError if a supplied block fails as expected with a mock' do
|
||||
lambda {
|
||||
include Pending
|
||||
pending "TODO" do
|
||||
m = mock('thing')
|
||||
m.should_receive(:foo)
|
||||
m.rspec_verify
|
||||
end
|
||||
}.should raise_error(ExamplePendingError, /TODO/)
|
||||
end
|
||||
|
||||
it 'should raise a PendingExampleFixedError if a supplied block starts working' do
|
||||
lambda {
|
||||
include Pending
|
||||
|
|
@ -26,6 +37,109 @@ module Spec
|
|||
end
|
||||
}.should raise_error(PendingExampleFixedError, /TODO/)
|
||||
end
|
||||
|
||||
it "should have the correct file and line number for pending given with a block which fails" do
|
||||
file = __FILE__
|
||||
line_number = __LINE__ + 3
|
||||
begin
|
||||
include Pending
|
||||
pending do
|
||||
raise
|
||||
end
|
||||
rescue => error
|
||||
error.pending_caller.should == "#{file}:#{line_number}"
|
||||
end
|
||||
end
|
||||
|
||||
it "should have the correct file and line number for pending given with no block" do
|
||||
file = __FILE__
|
||||
line_number = __LINE__ + 3
|
||||
begin
|
||||
include Pending
|
||||
pending("TODO")
|
||||
rescue => error
|
||||
error.pending_caller.should == "#{file}:#{line_number}"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe ExamplePendingError do
|
||||
it "should have the caller (from two calls from initialization)" do
|
||||
two_calls_ago = caller[0]
|
||||
ExamplePendingError.new("a message").pending_caller.should == two_calls_ago
|
||||
end
|
||||
|
||||
it "should keep the trace information from initialization" do
|
||||
two_calls_ago = caller[0]
|
||||
obj = ExamplePendingError.new("a message")
|
||||
obj.pending_caller
|
||||
def another_caller(obj)
|
||||
obj.pending_caller
|
||||
end
|
||||
|
||||
another_caller(obj).should == two_calls_ago
|
||||
end
|
||||
|
||||
it "should have the message provided" do
|
||||
ExamplePendingError.new("a message").message.should == "a message"
|
||||
end
|
||||
|
||||
it "should use a 'ExamplePendingError' as it's default message" do
|
||||
ExamplePendingError.new.message.should == "Spec::Example::ExamplePendingError"
|
||||
end
|
||||
end
|
||||
|
||||
describe NotYetImplementedError do
|
||||
def rspec_root
|
||||
File.expand_path(__FILE__.gsub("/spec/spec/example/pending_module_spec.rb", "/lib"))
|
||||
end
|
||||
|
||||
it "should have the root rspec path" do
|
||||
NotYetImplementedError::RSPEC_ROOT_LIB.should == rspec_root
|
||||
end
|
||||
|
||||
it "should always have the error 'Not Yet Implemented'" do
|
||||
NotYetImplementedError.new([]).message.should == "Not Yet Implemented"
|
||||
end
|
||||
|
||||
describe "pending_caller" do
|
||||
it "should select an element out of the backtrace" do
|
||||
error = NotYetImplementedError.new(["foo/bar.rb:18"])
|
||||
|
||||
error.pending_caller.should == "foo/bar.rb:18"
|
||||
end
|
||||
|
||||
it "should actually report the element from the backtrace" do
|
||||
error = NotYetImplementedError.new(["bar.rb:18"])
|
||||
|
||||
error.pending_caller.should == "bar.rb:18"
|
||||
end
|
||||
|
||||
it "should not use an element with the rspec root path" do
|
||||
error = NotYetImplementedError.new(["#{rspec_root}:8"])
|
||||
|
||||
error.pending_caller.should be_nil
|
||||
end
|
||||
|
||||
it "should select the first line in the backtrace which isn't in the rspec root" do
|
||||
error = NotYetImplementedError.new([
|
||||
"#{rspec_root}/foo.rb:2",
|
||||
"#{rspec_root}/foo/bar.rb:18",
|
||||
"path1.rb:22",
|
||||
"path2.rb:33"
|
||||
])
|
||||
|
||||
error.pending_caller.should == "path1.rb:22"
|
||||
end
|
||||
|
||||
it "should cache the caller" do
|
||||
backtrace = mock('backtrace')
|
||||
backtrace.should_receive(:detect).once
|
||||
|
||||
error = NotYetImplementedError.new(backtrace)
|
||||
error.pending_caller.should == error.pending_caller
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ require File.dirname(__FILE__) + '/../../spec_helper'
|
|||
module Spec
|
||||
module Example
|
||||
describe ExampleGroup, "with :shared => true" do
|
||||
it_should_behave_like "sandboxed rspec_options"
|
||||
include SandboxedOptions
|
||||
attr_reader :formatter, :example_group
|
||||
before(:each) do
|
||||
@formatter = Spec::Mocks::Mock.new("formatter", :null_object => true)
|
||||
|
|
|
|||
|
|
@ -39,12 +39,6 @@ describe Object, "#should" do
|
|||
}.should raise_error(Spec::Expectations::InvalidMatcherError)
|
||||
end
|
||||
|
||||
it "should raise error if it receives nil" do
|
||||
lambda {
|
||||
@target.should nil
|
||||
}.should raise_error(Spec::Expectations::InvalidMatcherError)
|
||||
end
|
||||
|
||||
it "should raise error if it receives no argument and it is not used as a left side of an operator" do
|
||||
pending "Is it even possible to catch this?"
|
||||
lambda {
|
||||
|
|
@ -92,12 +86,6 @@ describe Object, "#should_not" do
|
|||
}.should raise_error(Spec::Expectations::InvalidMatcherError)
|
||||
end
|
||||
|
||||
it "should raise error if it receives nil" do
|
||||
lambda {
|
||||
@target.should_not nil
|
||||
}.should raise_error(Spec::Expectations::InvalidMatcherError)
|
||||
end
|
||||
|
||||
it "should raise error if it receives no argument and it is not used as a left side of an operator" do
|
||||
pending "Is it even possible to catch this?"
|
||||
lambda {
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ require File.dirname(__FILE__) + '/../../spec_helper.rb'
|
|||
module Spec
|
||||
module Extensions
|
||||
describe Main do
|
||||
it_should_behave_like "sandboxed rspec_options"
|
||||
include SandboxedOptions
|
||||
before(:each) do
|
||||
@main = Class.new do; include Main; end
|
||||
end
|
||||
|
|
@ -12,11 +12,6 @@ module Spec
|
|||
$rspec_story_steps = @original_rspec_story_steps
|
||||
end
|
||||
|
||||
it "should create an Options object" do
|
||||
@main.send(:rspec_options).should be_instance_of(Spec::Runner::Options)
|
||||
@main.send(:rspec_options).should === $rspec_options
|
||||
end
|
||||
|
||||
specify {@main.should respond_to(:describe)}
|
||||
specify {@main.should respond_to(:context)}
|
||||
|
||||
|
|
@ -30,7 +25,7 @@ module Spec
|
|||
|
||||
it "should registered ExampleGroups by default" do
|
||||
example_group = @main.describe("The ExampleGroup") do end
|
||||
rspec_options.example_groups.should include(example_group)
|
||||
Spec::Runner.options.example_groups.should include(example_group)
|
||||
end
|
||||
|
||||
it "should not run unregistered ExampleGroups" do
|
||||
|
|
@ -38,7 +33,7 @@ module Spec
|
|||
unregister
|
||||
end
|
||||
|
||||
rspec_options.example_groups.should_not include(example_group)
|
||||
Spec::Runner.options.example_groups.should_not include(example_group)
|
||||
end
|
||||
|
||||
it "should create a shared ExampleGroup with share_examples_for" do
|
||||
|
|
|
|||
13
vendor/plugins/rspec/spec/spec/interop/test/unit/resources/spec_with_options_hash.rb
vendored
Normal file
13
vendor/plugins/rspec/spec/spec/interop/test/unit/resources/spec_with_options_hash.rb
vendored
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
rspec_lib = File.dirname(__FILE__) + "/../../../../../../lib"
|
||||
$:.unshift rspec_lib unless $:.include?(rspec_lib)
|
||||
require 'test/unit'
|
||||
require 'spec'
|
||||
|
||||
describe "options hash" do
|
||||
describe "#options" do
|
||||
it "should expose the options hash" do
|
||||
group = describe("group", :this => 'hash') {}
|
||||
group.options[:this].should == 'hash'
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -42,4 +42,11 @@ describe "ExampleGroup with test/unit/interop" do
|
|||
$?.should == 256
|
||||
end
|
||||
end
|
||||
|
||||
describe "options hash" do
|
||||
it "should be exposed" do
|
||||
output = ruby("#{@dir}/spec_with_options_hash.rb")
|
||||
output.should include("1 example, 0 failures")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -42,4 +42,8 @@ describe "Test::Unit::TestCase" do
|
|||
$?.should == 256
|
||||
end
|
||||
end
|
||||
|
||||
describe "not yet implemented examples:" do
|
||||
it "this example should be reported as pending (not an error)"
|
||||
end
|
||||
end
|
||||
|
|
@ -55,10 +55,9 @@ describe "should change { block }" do
|
|||
end.should fail_with("result should have changed, but is still 5")
|
||||
end
|
||||
|
||||
it "should warn if passed a block using do/end" do
|
||||
it "should warn if passed a block using do/end instead of {}" do
|
||||
lambda do
|
||||
lambda {}.should change do
|
||||
end
|
||||
lambda {}.should change do; end
|
||||
end.should raise_error(Spec::Matchers::MatcherError, /block passed to should or should_not/)
|
||||
end
|
||||
end
|
||||
|
|
@ -79,10 +78,9 @@ describe "should_not change { block }" do
|
|||
end.should fail_with("result should not have changed, but did change from 5 to 6")
|
||||
end
|
||||
|
||||
it "should warn if passed a block using do/end" do
|
||||
it "should warn if passed a block using do/end instead of {}" do
|
||||
lambda do
|
||||
lambda {}.should_not change do
|
||||
end
|
||||
lambda {}.should_not change do; end
|
||||
end.should raise_error(Spec::Matchers::MatcherError, /block passed to should or should_not/)
|
||||
end
|
||||
end
|
||||
|
|
@ -317,3 +315,15 @@ describe "should change{ block }.from(old).to(new)" do
|
|||
lambda { @instance.some_value = "cat" }.should change{@instance.some_value}.from("string").to("cat")
|
||||
end
|
||||
end
|
||||
|
||||
describe Spec::Matchers::Change do
|
||||
it "should work when the receiver has implemented #send" do
|
||||
@instance = SomethingExpected.new
|
||||
@instance.some_value = "string"
|
||||
def @instance.send(*args); raise "DOH! Library developers shouldn't use #send!" end
|
||||
|
||||
lambda {
|
||||
lambda { @instance.some_value = "cat" }.should change(@instance, :some_value)
|
||||
}.should_not raise_error
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -48,53 +48,73 @@ end
|
|||
|
||||
module Spec
|
||||
module Expectations
|
||||
describe ExpectationMatcherHandler, ".handle_matcher" do
|
||||
it "should ask the matcher if it matches" do
|
||||
matcher = mock("matcher")
|
||||
actual = Object.new
|
||||
matcher.should_receive(:matches?).with(actual).and_return(true)
|
||||
ExpectationMatcherHandler.handle_matcher(actual, matcher)
|
||||
end
|
||||
|
||||
it "should explain when the matcher parameter is not a matcher" do
|
||||
begin
|
||||
nonmatcher = mock("nonmatcher")
|
||||
describe ExpectationMatcherHandler do
|
||||
describe "#handle_matcher" do
|
||||
it "should ask the matcher if it matches" do
|
||||
matcher = mock("matcher")
|
||||
actual = Object.new
|
||||
ExpectationMatcherHandler.handle_matcher(actual, nonmatcher)
|
||||
rescue Spec::Expectations::InvalidMatcherError => e
|
||||
matcher.should_receive(:matches?).with(actual).and_return(true)
|
||||
ExpectationMatcherHandler.handle_matcher(actual, matcher)
|
||||
end
|
||||
|
||||
it "should explain when the matcher parameter is not a matcher" do
|
||||
begin
|
||||
nonmatcher = mock("nonmatcher")
|
||||
actual = Object.new
|
||||
ExpectationMatcherHandler.handle_matcher(actual, nonmatcher)
|
||||
rescue Spec::Expectations::InvalidMatcherError => e
|
||||
end
|
||||
|
||||
e.message.should =~ /^Expected a matcher, got /
|
||||
e.message.should =~ /^Expected a matcher, got /
|
||||
end
|
||||
|
||||
it "should return the match value" do
|
||||
matcher = mock("matcher")
|
||||
actual = Object.new
|
||||
matcher.should_receive(:matches?).with(actual).and_return(:this_value)
|
||||
ExpectationMatcherHandler.handle_matcher(actual, matcher).should == :this_value
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe NegativeExpectationMatcherHandler, ".handle_matcher" do
|
||||
it "should explain when matcher does not support should_not" do
|
||||
matcher = mock("matcher")
|
||||
matcher.stub!(:matches?)
|
||||
actual = Object.new
|
||||
lambda {
|
||||
NegativeExpectationMatcherHandler.handle_matcher(actual, matcher)
|
||||
}.should fail_with(/Matcher does not support should_not.\n/)
|
||||
end
|
||||
|
||||
it "should ask the matcher if it matches" do
|
||||
matcher = mock("matcher")
|
||||
actual = Object.new
|
||||
matcher.stub!(:negative_failure_message)
|
||||
matcher.should_receive(:matches?).with(actual).and_return(false)
|
||||
NegativeExpectationMatcherHandler.handle_matcher(actual, matcher)
|
||||
end
|
||||
|
||||
it "should explain when the matcher parameter is not a matcher" do
|
||||
begin
|
||||
nonmatcher = mock("nonmatcher")
|
||||
describe NegativeExpectationMatcherHandler do
|
||||
describe "#handle_matcher" do
|
||||
it "should explain when matcher does not support should_not" do
|
||||
matcher = mock("matcher")
|
||||
matcher.stub!(:matches?)
|
||||
actual = Object.new
|
||||
NegativeExpectationMatcherHandler.handle_matcher(actual, nonmatcher)
|
||||
rescue Spec::Expectations::InvalidMatcherError => e
|
||||
lambda {
|
||||
NegativeExpectationMatcherHandler.handle_matcher(actual, matcher)
|
||||
}.should fail_with(/Matcher does not support should_not.\n/)
|
||||
end
|
||||
|
||||
it "should ask the matcher if it matches" do
|
||||
matcher = mock("matcher")
|
||||
actual = Object.new
|
||||
matcher.stub!(:negative_failure_message)
|
||||
matcher.should_receive(:matches?).with(actual).and_return(false)
|
||||
NegativeExpectationMatcherHandler.handle_matcher(actual, matcher)
|
||||
end
|
||||
|
||||
it "should explain when the matcher parameter is not a matcher" do
|
||||
begin
|
||||
nonmatcher = mock("nonmatcher")
|
||||
actual = Object.new
|
||||
NegativeExpectationMatcherHandler.handle_matcher(actual, nonmatcher)
|
||||
rescue Spec::Expectations::InvalidMatcherError => e
|
||||
end
|
||||
|
||||
e.message.should =~ /^Expected a matcher, got /
|
||||
end
|
||||
|
||||
e.message.should =~ /^Expected a matcher, got /
|
||||
|
||||
it "should return the match value" do
|
||||
matcher = mock("matcher")
|
||||
actual = Object.new
|
||||
matcher.should_receive(:matches?).with(actual).and_return(false)
|
||||
matcher.stub!(:negative_failure_message).and_return("ignore")
|
||||
NegativeExpectationMatcherHandler.handle_matcher(actual, matcher).should be_false
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
|
@ -124,6 +144,7 @@ module Spec
|
|||
}.should fail_with(/Matcher does not support should_not.\n/)
|
||||
end
|
||||
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -51,3 +51,13 @@ describe "should_not have_sym(*args)" do
|
|||
lambda { o.should_not have_sym(:foo) }.should raise_error("Funky exception")
|
||||
end
|
||||
end
|
||||
|
||||
describe Spec::Matchers::Has do
|
||||
it "should work when the target implements #send" do
|
||||
o = {:a => "A"}
|
||||
def o.send(*args); raise "DOH! Library developers shouldn't use #send!" end
|
||||
lambda {
|
||||
o.should have_key(:a)
|
||||
}.should_not raise_error
|
||||
end
|
||||
end
|
||||
|
|
|
|||
103
vendor/plugins/rspec/spec/spec/matchers/have_spec.rb
vendored
103
vendor/plugins/rspec/spec/spec/matchers/have_spec.rb
vendored
|
|
@ -50,8 +50,9 @@ end
|
|||
describe 'should have(1).item when ActiveSupport::Inflector is defined' do
|
||||
include HaveSpecHelper
|
||||
|
||||
before do
|
||||
before(:each) do
|
||||
unless defined?(ActiveSupport::Inflector)
|
||||
@active_support_was_not_defined
|
||||
module ActiveSupport
|
||||
class Inflector
|
||||
def self.pluralize(string)
|
||||
|
|
@ -66,6 +67,38 @@ describe 'should have(1).item when ActiveSupport::Inflector is defined' do
|
|||
owner = create_collection_owner_with(1)
|
||||
owner.should have(1).item
|
||||
end
|
||||
|
||||
after(:each) do
|
||||
if @active_support_was_not_defined
|
||||
Object.send :remove_const, :ActiveSupport
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe 'should have(1).item when Inflector is defined' do
|
||||
include HaveSpecHelper
|
||||
|
||||
before(:each) do
|
||||
unless defined?(Inflector)
|
||||
@inflector_was_not_defined
|
||||
class Inflector
|
||||
def self.pluralize(string)
|
||||
string.to_s + 's'
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
it 'should pluralize the collection name' do
|
||||
owner = create_collection_owner_with(1)
|
||||
owner.should have(1).item
|
||||
end
|
||||
|
||||
after(:each) do
|
||||
if @inflector_was_not_defined
|
||||
Object.send :remove_const, :Inflector
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "should have(n).items where result responds to items but returns something other than a collection" do
|
||||
|
|
@ -291,3 +324,71 @@ describe "have(n).things on an object which is not a collection nor contains one
|
|||
lambda { Object.new.should have(2).things }.should raise_error(NoMethodError, /undefined method `things' for #<Object:/)
|
||||
end
|
||||
end
|
||||
|
||||
describe Spec::Matchers::Have, "for a collection owner that implements #send" do
|
||||
include HaveSpecHelper
|
||||
|
||||
before(:each) do
|
||||
@collection = Object.new
|
||||
def @collection.floozles; [1,2] end
|
||||
def @collection.send(*args); raise "DOH! Library developers shouldn't use #send!" end
|
||||
end
|
||||
|
||||
it "should work in the straightforward case" do
|
||||
lambda {
|
||||
@collection.should have(2).floozles
|
||||
}.should_not raise_error
|
||||
end
|
||||
|
||||
it "should work when doing automatic pluralization" do
|
||||
lambda {
|
||||
@collection.should have_at_least(1).floozle
|
||||
}.should_not raise_error
|
||||
end
|
||||
|
||||
it "should blow up when the owner doesn't respond to that method" do
|
||||
lambda {
|
||||
@collection.should have(99).problems
|
||||
}.should raise_error(NoMethodError, /problems/)
|
||||
end
|
||||
end
|
||||
|
||||
module Spec
|
||||
module Matchers
|
||||
describe Have do
|
||||
it "should have method_missing as private" do
|
||||
Have.private_instance_methods.should include("method_missing")
|
||||
end
|
||||
|
||||
describe "respond_to?" do
|
||||
before :each do
|
||||
@have = Have.new(:foo)
|
||||
@a_method_which_have_defines = Have.instance_methods.first
|
||||
@a_method_which_object_defines = Object.instance_methods.first
|
||||
end
|
||||
|
||||
it "should be true for a method which Have defines" do
|
||||
@have.should respond_to(@a_method_which_have_defines)
|
||||
end
|
||||
|
||||
it "should be true for a method that it's superclass (Object) defines" do
|
||||
@have.should respond_to(@a_method_which_object_defines)
|
||||
end
|
||||
|
||||
it "should be false for a method which neither Object nor nor Have defines" do
|
||||
@have.should_not respond_to(:foo_bar_baz)
|
||||
end
|
||||
|
||||
it "should be false if the owner doesn't respond to the method" do
|
||||
have = Have.new(99)
|
||||
have.should_not respond_to(:problems)
|
||||
end
|
||||
|
||||
it "should be true if the owner responds to the method" do
|
||||
have = Have.new(:a_symbol)
|
||||
have.should respond_to(:to_sym)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -10,12 +10,17 @@ describe "should ==" do
|
|||
subject.should == "apple"
|
||||
end
|
||||
|
||||
it "should return true on success" do
|
||||
subject = "apple"
|
||||
(subject.should == "apple").should be_true
|
||||
end
|
||||
|
||||
it "should fail when target.==(actual) returns false" do
|
||||
subject = "apple"
|
||||
Spec::Expectations.should_receive(:fail_with).with(%[expected: "orange",\n got: "apple" (using ==)], "orange", "apple")
|
||||
subject.should == "orange"
|
||||
end
|
||||
|
||||
|
||||
end
|
||||
|
||||
describe "should_not ==" do
|
||||
|
|
@ -26,12 +31,17 @@ describe "should_not ==" do
|
|||
subject.should_not == "apple"
|
||||
end
|
||||
|
||||
it "should return true on success" do
|
||||
subject = "apple"
|
||||
(subject.should_not == "orange").should be_true
|
||||
end
|
||||
|
||||
it "should fail when target.==(actual) returns false" do
|
||||
subject = "apple"
|
||||
Spec::Expectations.should_receive(:fail_with).with(%[expected not: == "apple",\n got: "apple"], "apple", "apple")
|
||||
subject.should_not == "apple"
|
||||
end
|
||||
|
||||
|
||||
end
|
||||
|
||||
describe "should ===" do
|
||||
|
|
@ -156,3 +166,26 @@ describe "should <=" do
|
|||
|
||||
end
|
||||
|
||||
describe Spec::Matchers::PositiveOperatorMatcher do
|
||||
|
||||
it "should work when the target has implemented #send" do
|
||||
o = Object.new
|
||||
def o.send(*args); raise "DOH! Library developers shouldn't use #send!" end
|
||||
lambda {
|
||||
o.should == o
|
||||
}.should_not raise_error
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
describe Spec::Matchers::NegativeOperatorMatcher do
|
||||
|
||||
it "should work when the target has implemented #send" do
|
||||
o = Object.new
|
||||
def o.send(*args); raise "DOH! Library developers shouldn't use #send!" end
|
||||
lambda {
|
||||
o.should_not == :foo
|
||||
}.should_not raise_error
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
|||
|
|
@ -8,8 +8,8 @@ describe "should respond_to(:sym)" do
|
|||
|
||||
it "should fail target does not respond to :sym" do
|
||||
lambda {
|
||||
Object.new.should respond_to(:some_method)
|
||||
}.should fail_with("expected target to respond to :some_method")
|
||||
"this string".should respond_to(:some_method)
|
||||
}.should fail_with("expected \"this string\" to respond to :some_method")
|
||||
end
|
||||
|
||||
end
|
||||
|
|
@ -23,19 +23,19 @@ describe "should respond_to(message1, message2)" do
|
|||
it "should fail target does not respond to first message" do
|
||||
lambda {
|
||||
Object.new.should respond_to('method_one', 'inspect')
|
||||
}.should fail_with('expected target to respond to "method_one"')
|
||||
}.should fail_with(/expected #<Object:.*> to respond to "method_one"/)
|
||||
end
|
||||
|
||||
it "should fail target does not respond to second message" do
|
||||
lambda {
|
||||
Object.new.should respond_to('inspect', 'method_one')
|
||||
}.should fail_with('expected target to respond to "method_one"')
|
||||
}.should fail_with(/expected #<Object:.*> to respond to "method_one"/)
|
||||
end
|
||||
|
||||
it "should fail target does not respond to either message" do
|
||||
lambda {
|
||||
Object.new.should respond_to('method_one', 'method_two')
|
||||
}.should fail_with('expected target to respond to "method_one", "method_two"')
|
||||
}.should fail_with(/expected #<Object:.*> to respond to "method_one", "method_two"/)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
@ -48,7 +48,7 @@ describe "should_not respond_to(:sym)" do
|
|||
it "should fail target responds to :sym" do
|
||||
lambda {
|
||||
Object.new.should_not respond_to(:methods)
|
||||
}.should fail_with("expected target not to respond to :methods")
|
||||
}.should fail_with(/expected #<Object:.*> not to respond to :methods/)
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ require File.dirname(__FILE__) + '/../../spec_helper'
|
|||
module Spec
|
||||
module Matchers
|
||||
describe SimpleMatcher do
|
||||
it "should match pass match arg to block" do
|
||||
it "should pass match arg to block" do
|
||||
actual = nil
|
||||
matcher = simple_matcher("message") do |given| actual = given end
|
||||
matcher.matches?("foo")
|
||||
|
|
@ -22,10 +22,72 @@ module Spec
|
|||
matcher.negative_failure_message.should =~ /expected not to get \"thing\", but got \"other\"/
|
||||
end
|
||||
|
||||
it "should provide a description" do
|
||||
it "should provide the given description" do
|
||||
matcher = simple_matcher("thing") do end
|
||||
matcher.description.should =="thing"
|
||||
end
|
||||
|
||||
it "should fail if a wrapped 'should' fails" do
|
||||
matcher = simple_matcher("should fail") do
|
||||
2.should == 3
|
||||
end
|
||||
lambda do
|
||||
matcher.matches?("anything").should be_true
|
||||
end.should fail_with(/expected: 3/)
|
||||
end
|
||||
end
|
||||
|
||||
describe "with arity of 2" do
|
||||
it "should provide the matcher so you can access its messages" do
|
||||
provided_matcher = nil
|
||||
matcher = simple_matcher("thing") do |given, matcher|
|
||||
provided_matcher = matcher
|
||||
end
|
||||
matcher.matches?("anything")
|
||||
provided_matcher.should equal(matcher)
|
||||
end
|
||||
|
||||
it "should support a custom failure message" do
|
||||
matcher = simple_matcher("thing") do |given, matcher|
|
||||
matcher.failure_message = "custom message"
|
||||
end
|
||||
matcher.matches?("other")
|
||||
matcher.failure_message.should == "custom message"
|
||||
end
|
||||
|
||||
it "should complain when asked for a failure message if you don't give it a description or a message" do
|
||||
matcher = simple_matcher do |given, matcher| end
|
||||
matcher.matches?("other")
|
||||
matcher.failure_message.should =~ /No description provided/
|
||||
end
|
||||
|
||||
it "should support a custom negative failure message" do
|
||||
matcher = simple_matcher("thing") do |given, matcher|
|
||||
matcher.negative_failure_message = "custom message"
|
||||
end
|
||||
matcher.matches?("other")
|
||||
matcher.negative_failure_message.should == "custom message"
|
||||
end
|
||||
|
||||
it "should complain when asked for a negative failure message if you don't give it a description or a message" do
|
||||
matcher = simple_matcher do |given, matcher| end
|
||||
matcher.matches?("other")
|
||||
matcher.negative_failure_message.should =~ /No description provided/
|
||||
end
|
||||
|
||||
it "should support a custom description" do
|
||||
matcher = simple_matcher("thing") do |given, matcher|
|
||||
matcher.description = "custom message"
|
||||
end
|
||||
matcher.matches?("description")
|
||||
matcher.description.should == "custom message"
|
||||
end
|
||||
|
||||
it "should tell you no description was provided when it doesn't receive one" do
|
||||
matcher = simple_matcher do end
|
||||
matcher.description.should =~ /No description provided/
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
|
@ -23,6 +23,13 @@ module Spec
|
|||
it "should pass if any number of times method is not called" do
|
||||
@mock.should_receive(:random_call).any_number_of_times
|
||||
end
|
||||
|
||||
it "should return the mocked value when called after a similar stub" do
|
||||
@mock.stub!(:message).and_return :stub_value
|
||||
@mock.should_receive(:message).any_number_of_times.and_return(:mock_value)
|
||||
@mock.message.should == :mock_value
|
||||
@mock.message.should == :mock_value
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
|||
17
vendor/plugins/rspec/spec/spec/mocks/bug_report_496.rb
vendored
Normal file
17
vendor/plugins/rspec/spec/spec/mocks/bug_report_496.rb
vendored
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
require File.dirname(__FILE__) + '/../../spec_helper.rb'
|
||||
|
||||
class BaseClass
|
||||
end
|
||||
|
||||
class SubClass < BaseClass
|
||||
end
|
||||
|
||||
describe "a message expectation on a base class object" do
|
||||
it "should correctly pick up message sent to it subclass" do
|
||||
pending("fix for http://rspec.lighthouseapp.com/projects/5645-rspec/tickets/496") do
|
||||
BaseClass.should_receive(:new).once
|
||||
SubClass.new
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
|
@ -91,40 +91,5 @@ module Spec
|
|||
end
|
||||
|
||||
end
|
||||
|
||||
describe "failing deprecated MockArgumentConstraints" do
|
||||
before(:each) do
|
||||
@mock = mock("test mock")
|
||||
@reporter = Mock.new("reporter", :null_object => true)
|
||||
Kernel.stub!(:warn)
|
||||
end
|
||||
|
||||
after(:each) do
|
||||
@mock.rspec_reset
|
||||
end
|
||||
|
||||
it "should reject non boolean" do
|
||||
@mock.should_receive(:random_call).with(:boolean)
|
||||
lambda do
|
||||
@mock.random_call("false")
|
||||
end.should raise_error(MockExpectationError)
|
||||
end
|
||||
|
||||
it "should reject non numeric" do
|
||||
@mock.should_receive(:random_call).with(:numeric)
|
||||
lambda do
|
||||
@mock.random_call("1")
|
||||
end.should raise_error(MockExpectationError)
|
||||
end
|
||||
|
||||
it "should reject non string" do
|
||||
@mock.should_receive(:random_call).with(:string)
|
||||
lambda do
|
||||
@mock.random_call(123)
|
||||
end.should raise_error(MockExpectationError)
|
||||
end
|
||||
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -2,31 +2,52 @@ require File.dirname(__FILE__) + '/../../spec_helper.rb'
|
|||
|
||||
module Spec
|
||||
module Mocks
|
||||
describe HashIncludingConstraint do
|
||||
|
||||
it "should match the same hash" do
|
||||
hash_including(:a => 1).matches?(:a => 1).should be_true
|
||||
end
|
||||
|
||||
it "should not match a non-hash" do
|
||||
hash_including(:a => 1).matches?(1).should_not be_true
|
||||
end
|
||||
module ArgumentConstraints
|
||||
describe HashIncludingConstraint do
|
||||
|
||||
it "should describe itself properly" do
|
||||
HashIncludingConstraint.new(:a => 1).description.should == "hash_including(:a=>1)"
|
||||
end
|
||||
|
||||
it "should match a hash with extra stuff" do
|
||||
hash_including(:a => 1).matches?(:a => 1, :b => 2).should be_true
|
||||
end
|
||||
|
||||
it "should not match a hash with a missing key" do
|
||||
hash_including(:a => 1).matches?(:b => 2).should_not be_true
|
||||
end
|
||||
describe "passing" do
|
||||
it "should match the same hash" do
|
||||
hash_including(:a => 1).should == {:a => 1}
|
||||
end
|
||||
|
||||
it "should not match a hash with an incorrect value" do
|
||||
hash_including(:a => 1, :b => 2).matches?(:a => 1, :b => 3).should_not be_true
|
||||
end
|
||||
it "should match a hash with extra stuff" do
|
||||
hash_including(:a => 1).should == {:a => 1, :b => 2}
|
||||
end
|
||||
|
||||
describe "when matching against other constraints" do
|
||||
it "should match an int against anything()" do
|
||||
hash_including(:a => anything, :b => 2).should == {:a => 1, :b => 2}
|
||||
end
|
||||
|
||||
it "should describe itself properly" do
|
||||
HashIncludingConstraint.new(:a => 1).description.should == "hash_including(:a=>1)"
|
||||
end
|
||||
it "should match a string against anything()" do
|
||||
hash_including(:a => anything, :b => 2).should == {:a => "1", :b => 2}
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "failing" do
|
||||
it "should not match a non-hash" do
|
||||
hash_including(:a => 1).should_not == 1
|
||||
end
|
||||
|
||||
|
||||
it "should not match a hash with a missing key" do
|
||||
hash_including(:a => 1).should_not == {:b => 2}
|
||||
end
|
||||
|
||||
it "should not match a hash with an incorrect value" do
|
||||
hash_including(:a => 1, :b => 2).should_not == {:a => 1, :b => 3}
|
||||
end
|
||||
|
||||
it "should not match when values are nil but keys are different" do
|
||||
hash_including(:a => nil).should_not == {:b => nil}
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -23,6 +23,18 @@ module Spec
|
|||
end
|
||||
end
|
||||
|
||||
it "should report line number of expectation of unreceived message after #should_receive after similar stub" do
|
||||
@mock.stub!(:wont_happen)
|
||||
expected_error_line = __LINE__; @mock.should_receive(:wont_happen).with("x", 3)
|
||||
begin
|
||||
@mock.rspec_verify
|
||||
violated
|
||||
rescue MockExpectationError => e
|
||||
# NOTE - this regexp ended w/ $, but jruby adds extra info at the end of the line
|
||||
e.backtrace[0].should match(/#{File.basename(__FILE__)}:#{expected_error_line}/)
|
||||
end
|
||||
end
|
||||
|
||||
it "should pass when not receiving message specified as not to be received" do
|
||||
@mock.should_not_receive(:not_expected)
|
||||
@mock.rspec_verify
|
||||
|
|
@ -403,7 +415,22 @@ module Spec
|
|||
@mock.msg.should equal(:stub_value)
|
||||
@mock.rspec_verify
|
||||
end
|
||||
|
||||
|
||||
it "should not require a different signature to replace a method stub" do
|
||||
@mock.stub!(:msg).and_return(:stub_value)
|
||||
@mock.should_receive(:msg).and_return(:mock_value)
|
||||
@mock.msg(:arg).should equal(:mock_value)
|
||||
@mock.msg.should equal(:stub_value)
|
||||
@mock.msg.should equal(:stub_value)
|
||||
@mock.rspec_verify
|
||||
end
|
||||
|
||||
it "should raise an error when a previously stubbed method has a negative expectation" do
|
||||
@mock.stub!(:msg).and_return(:stub_value)
|
||||
@mock.should_not_receive(:msg).and_return(:mock_value)
|
||||
lambda {@mock.msg(:arg)}.should raise_error(MockExpectationError)
|
||||
end
|
||||
|
||||
it "should temporarily replace a method stub on a non-mock" do
|
||||
non_mock = Object.new
|
||||
non_mock.stub!(:msg).and_return(:stub_value)
|
||||
|
|
@ -413,7 +440,32 @@ module Spec
|
|||
non_mock.msg.should equal(:stub_value)
|
||||
non_mock.rspec_verify
|
||||
end
|
||||
|
||||
|
||||
it "should return the stubbed value when no new value specified" do
|
||||
@mock.stub!(:msg).and_return(:stub_value)
|
||||
@mock.should_receive(:msg)
|
||||
@mock.msg.should equal(:stub_value)
|
||||
@mock.rspec_verify
|
||||
end
|
||||
|
||||
it "should not mess with the stub's yielded values when also mocked" do
|
||||
@mock.stub!(:yield_back).and_yield(:stub_value)
|
||||
@mock.should_receive(:yield_back).and_yield(:mock_value)
|
||||
@mock.yield_back{|v| v.should == :mock_value }
|
||||
@mock.yield_back{|v| v.should == :stub_value }
|
||||
@mock.rspec_verify
|
||||
end
|
||||
|
||||
it "should yield multiple values after a similar stub" do
|
||||
File.stub!(:open).and_yield(:stub_value)
|
||||
File.should_receive(:open).and_yield(:first_call).and_yield(:second_call)
|
||||
yielded_args = []
|
||||
File.open {|v| yielded_args << v }
|
||||
yielded_args.should == [:first_call, :second_call]
|
||||
File.open {|v| v.should == :stub_value }
|
||||
File.rspec_verify
|
||||
end
|
||||
|
||||
it "should assign stub return values" do
|
||||
mock = Mock.new('name', :message => :response)
|
||||
mock.message.should == :response
|
||||
|
|
@ -439,6 +491,15 @@ module Spec
|
|||
@calls.should == 1
|
||||
end
|
||||
|
||||
it "should call the block after #should_receive after a similar stub" do
|
||||
@mock.stub!(:foo).and_return(:bar)
|
||||
@mock.should_receive(:foo) { add_call }
|
||||
|
||||
@mock.foo
|
||||
|
||||
@calls.should == 1
|
||||
end
|
||||
|
||||
it "should call the block after #once" do
|
||||
@mock.should_receive(:foo).once { add_call }
|
||||
|
||||
|
|
|
|||
54
vendor/plugins/rspec/spec/spec/mocks/nil_expectation_warning_spec.rb
vendored
Normal file
54
vendor/plugins/rspec/spec/spec/mocks/nil_expectation_warning_spec.rb
vendored
Normal file
|
|
@ -0,0 +1,54 @@
|
|||
require File.dirname(__FILE__) + '/../../spec_helper.rb'
|
||||
|
||||
module Spec
|
||||
module Mocks
|
||||
|
||||
describe "an expectation set on nil" do
|
||||
|
||||
it "should issue a warning with file and line number information" do
|
||||
expected_warning = "An expectation of :foo was set on nil. Called from #{__FILE__}:#{__LINE__+3}. Use allow_message_expectations_on_nil to disable warnings."
|
||||
Kernel.should_receive(:warn).with(expected_warning)
|
||||
|
||||
nil.should_receive(:foo)
|
||||
nil.foo
|
||||
end
|
||||
|
||||
it "should issue a warning when the expectation is negative" do
|
||||
Kernel.should_receive(:warn)
|
||||
|
||||
nil.should_not_receive(:foo)
|
||||
end
|
||||
|
||||
it "should not issue a warning when expectations are set to be allowed" do
|
||||
allow_message_expectations_on_nil
|
||||
Kernel.should_not_receive(:warn)
|
||||
|
||||
nil.should_receive(:foo)
|
||||
nil.should_not_receive(:bar)
|
||||
nil.foo
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
describe "#allow_message_expectations_on_nil" do
|
||||
include SandboxedOptions
|
||||
|
||||
it "should not effect subsequent examples" do
|
||||
example_group = Class.new(ExampleGroup)
|
||||
example_group.it("when called in one example that doesn't end up setting an expectation on nil") do
|
||||
allow_message_expectations_on_nil
|
||||
end
|
||||
example_group.it("should not effect the next exapmle ran") do
|
||||
Kernel.should_receive(:warn)
|
||||
nil.should_receive(:foo)
|
||||
nil.foo
|
||||
end
|
||||
|
||||
example_group.run.should be_true
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
|
@ -36,5 +36,19 @@ module Spec
|
|||
@mock.message(:unexpected_arg)
|
||||
end
|
||||
end
|
||||
|
||||
describe "#null_object?" do
|
||||
it "should default to false" do
|
||||
obj = mock('anything')
|
||||
obj.should_not be_null_object
|
||||
end
|
||||
end
|
||||
|
||||
describe "#as_null_object" do
|
||||
it "should set the object to null_object" do
|
||||
obj = mock('anything').as_null_object
|
||||
obj.should be_null_object
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -3,42 +3,32 @@ require File.dirname(__FILE__) + '/../../spec_helper.rb'
|
|||
module Spec
|
||||
module Mocks
|
||||
describe "calling :should_receive with an options hash" do
|
||||
it_should_behave_like "sandboxed rspec_options"
|
||||
attr_reader :reporter, :example_group
|
||||
before do
|
||||
@reporter = ::Spec::Runner::Reporter.new(options)
|
||||
@example_group = Class.new(::Spec::Example::ExampleGroup) do
|
||||
plugin_mock_framework
|
||||
describe("Some Examples")
|
||||
end
|
||||
reporter.add_example_group example_group
|
||||
end
|
||||
|
||||
it "should report the file and line submitted with :expected_from" do
|
||||
example_definition = example_group.it "spec" do
|
||||
begin
|
||||
mock = Spec::Mocks::Mock.new("a mock")
|
||||
mock.should_receive(:message, :expected_from => "/path/to/blah.ext:37")
|
||||
mock.rspec_verify
|
||||
rescue => e
|
||||
ensure
|
||||
e.backtrace.to_s.should =~ /\/path\/to\/blah.ext:37/m
|
||||
end
|
||||
example = example_group.new(example_definition)
|
||||
|
||||
reporter.should_receive(:example_finished) do |spec, error|
|
||||
error.backtrace.detect {|line| line =~ /\/path\/to\/blah.ext:37/}.should_not be_nil
|
||||
end
|
||||
example.execute(options, {})
|
||||
end
|
||||
|
||||
it "should use the message supplied with :message" do
|
||||
example_definition = @example_group.it "spec" do
|
||||
mock = Spec::Mocks::Mock.new("a mock")
|
||||
mock.should_receive(:message, :message => "recebi nada")
|
||||
mock.rspec_verify
|
||||
end
|
||||
example = @example_group.new(example_definition)
|
||||
@reporter.should_receive(:example_finished) do |spec, error|
|
||||
error.message.should == "recebi nada"
|
||||
end
|
||||
example.execute(@options, {})
|
||||
lambda {
|
||||
m = Spec::Mocks::Mock.new("a mock")
|
||||
m.should_receive(:message, :message => "recebi nada")
|
||||
m.rspec_verify
|
||||
}.should raise_error("recebi nada")
|
||||
end
|
||||
|
||||
it "should use the message supplied with :message after a similar stub" do
|
||||
lambda {
|
||||
m = Spec::Mocks::Mock.new("a mock")
|
||||
m.stub!(:message)
|
||||
m.should_receive(:message, :message => "from mock")
|
||||
m.rspec_verify
|
||||
}.should raise_error("from mock")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -11,7 +11,14 @@ module Spec
|
|||
@object.should_receive(:foo)
|
||||
lambda do
|
||||
@object.rspec_verify
|
||||
end.should raise_error(Spec::Mocks::MockExpectationError, /Object/)
|
||||
end.should raise_error(Spec::Mocks::MockExpectationError, /<Object:.*> expected/)
|
||||
end
|
||||
|
||||
it "should name the class in the failure message when expectation is on class" do
|
||||
Object.should_receive(:foo)
|
||||
lambda do
|
||||
Object.rspec_verify
|
||||
end.should raise_error(Spec::Mocks::MockExpectationError, /<Object \(class\)>/)
|
||||
end
|
||||
|
||||
it "should not conflict with @options in the object" do
|
||||
|
|
@ -21,11 +28,10 @@ module Spec
|
|||
end
|
||||
|
||||
it "should_not_receive should mock out the method" do
|
||||
pending("example raises the expected error, yet fails")
|
||||
@object.should_not_receive(:fuhbar)
|
||||
lambda do
|
||||
@object.fuhbar
|
||||
end.should raise_error(MockExpectationError, "Mock 'Object' expected :fuhbar with (no args) 0 times, but received it once")
|
||||
end.should raise_error(MockExpectationError, /<Object:.*> expected :fuhbar with \(no args\) 0 times/)
|
||||
end
|
||||
|
||||
it "should_not_receive should return a negative message expectation" do
|
||||
|
|
@ -66,7 +72,6 @@ module Spec
|
|||
end
|
||||
|
||||
it "should_not_receive should also take a String argument" do
|
||||
pending("example raises the expected error, yet fails")
|
||||
@object.should_not_receive('foobar')
|
||||
lambda do
|
||||
@object.foobar
|
||||
|
|
@ -74,10 +79,12 @@ module Spec
|
|||
end
|
||||
|
||||
it "should use report nil in the error message" do
|
||||
allow_message_expectations_on_nil
|
||||
|
||||
@this_will_resolve_to_nil.should_receive(:foobar)
|
||||
lambda do
|
||||
@this_will_resolve_to_nil.rspec_verify
|
||||
end.should raise_error(Spec::Mocks::MockExpectationError, /NilClass.*expected :foobar with/)
|
||||
end.should raise_error(Spec::Mocks::MockExpectationError, /nil expected :foobar with/)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -13,50 +13,6 @@ module Spec
|
|||
end
|
||||
end
|
||||
|
||||
describe Methods, "handling argument constraints with DEPRECATED symbols" do
|
||||
it_should_behave_like "mock argument constraints"
|
||||
|
||||
it "should accept true as boolean" do
|
||||
@mock.should_receive(:random_call).with(:boolean)
|
||||
@mock.random_call(true)
|
||||
end
|
||||
|
||||
it "should accept false as boolean" do
|
||||
@mock.should_receive(:random_call).with(:boolean)
|
||||
@mock.random_call(false)
|
||||
end
|
||||
|
||||
it "should accept fixnum as numeric" do
|
||||
@mock.should_receive(:random_call).with(:numeric)
|
||||
@mock.random_call(1)
|
||||
end
|
||||
|
||||
it "should accept float as numeric" do
|
||||
@mock.should_receive(:random_call).with(:numeric)
|
||||
@mock.random_call(1.5)
|
||||
end
|
||||
|
||||
it "should accept string as anything" do
|
||||
@mock.should_receive(:random_call).with("a", :anything, "c")
|
||||
@mock.random_call("a", "whatever", "c")
|
||||
end
|
||||
|
||||
it "should match string" do
|
||||
@mock.should_receive(:random_call).with(:string)
|
||||
@mock.random_call("a string")
|
||||
end
|
||||
|
||||
it "should match no args against any_args" do
|
||||
@mock.should_receive(:random_call).with(:any_args)
|
||||
@mock.random_call("a string")
|
||||
end
|
||||
|
||||
it "should match no args against no_args" do
|
||||
@mock.should_receive(:random_call).with(:no_args)
|
||||
@mock.random_call
|
||||
end
|
||||
end
|
||||
|
||||
describe Methods, "handling argument constraints" do
|
||||
it_should_behave_like "mock argument constraints"
|
||||
|
||||
|
|
@ -133,7 +89,11 @@ module Spec
|
|||
end
|
||||
|
||||
describe Methods, "handling non-constraint arguments" do
|
||||
|
||||
|
||||
before(:each) do
|
||||
@mock = Mock.new("test mock")
|
||||
end
|
||||
|
||||
it "should match non special symbol (can be removed when deprecated symbols are removed)" do
|
||||
@mock.should_receive(:random_call).with(:some_symbol)
|
||||
@mock.random_call(:some_symbol)
|
||||
|
|
@ -165,11 +125,6 @@ module Spec
|
|||
@mock.should_receive(:random_call).with(:a => "a", :b => "b")
|
||||
@mock.random_call(opts)
|
||||
end
|
||||
|
||||
it "should match against a Matcher" do
|
||||
@mock.should_receive(:msg).with(equal(37))
|
||||
@mock.msg(37)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -14,6 +14,7 @@ module Spec
|
|||
end
|
||||
end
|
||||
@instance = @class.new
|
||||
@stub = Object.new
|
||||
end
|
||||
|
||||
it "should return expected value when expected message is received" do
|
||||
|
|
@ -44,6 +45,12 @@ module Spec
|
|||
@instance.rspec_verify
|
||||
end.should_not raise_error
|
||||
end
|
||||
|
||||
it "should handle multiple stubbed methods" do
|
||||
@instance.stub!(:msg1 => 1, :msg2 => 2)
|
||||
@instance.msg1.should == 1
|
||||
@instance.msg2.should == 2
|
||||
end
|
||||
|
||||
it "should clear itself when verified" do
|
||||
@instance.stub!(:this_should_go).and_return(:blah)
|
||||
|
|
|
|||
|
|
@ -11,4 +11,12 @@ describe "The bin/spec script" do
|
|||
output = ruby "-w #{spec_path} --help 2>&1"
|
||||
output.should_not =~ /warning/n
|
||||
end
|
||||
|
||||
it "should show the help w/ no args" do
|
||||
pending "Hangs on JRuby" if PLATFORM =~ /java/
|
||||
spec_path = "#{File.dirname(__FILE__)}/../../../bin/spec"
|
||||
|
||||
output = ruby "-w #{spec_path} 2>&1"
|
||||
output.should =~ /^Usage: spec/
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -3,16 +3,16 @@ require File.dirname(__FILE__) + '/../../spec_helper.rb'
|
|||
module Spec
|
||||
module Runner
|
||||
describe CommandLine, ".run" do
|
||||
it_should_behave_like "sandboxed rspec_options"
|
||||
include SandboxedOptions
|
||||
attr_reader :options, :err, :out
|
||||
before do
|
||||
@err = options.error_stream
|
||||
@out = options.output_stream
|
||||
end
|
||||
|
||||
|
||||
it "should run directory" do
|
||||
file = File.dirname(__FILE__) + '/../../../examples/pure'
|
||||
Spec::Runner::CommandLine.run(OptionParser.parse([file,"-p","**/*.rb"], @err, @out))
|
||||
run_with(OptionParser.parse([file,"-p","**/*.rb"], @err, @out))
|
||||
|
||||
@out.rewind
|
||||
@out.read.should =~ /\d+ examples, 0 failures, 3 pending/n
|
||||
|
|
@ -20,7 +20,7 @@ module Spec
|
|||
|
||||
it "should run file" do
|
||||
file = File.dirname(__FILE__) + '/../../../failing_examples/predicate_example.rb'
|
||||
Spec::Runner::CommandLine.run(OptionParser.parse([file], @err, @out))
|
||||
run_with(OptionParser.parse([file], @err, @out))
|
||||
|
||||
@out.rewind
|
||||
@out.read.should =~ /2 examples, 1 failure/n
|
||||
|
|
@ -130,18 +130,11 @@ module Spec
|
|||
options.reporter.should_receive(:add_example_group).with(example_group)
|
||||
|
||||
options.add_example_group example_group
|
||||
Spec::Runner::CommandLine.run(OptionParser.parse([], @err, @out))
|
||||
run_with(options)
|
||||
|
||||
should_has_run.should be_true
|
||||
should_not_has_run.should be_false
|
||||
end
|
||||
|
||||
it "sets Spec.run to true" do
|
||||
::Spec.run = false
|
||||
::Spec.should_not be_run
|
||||
Spec::Runner::CommandLine.run(OptionParser.parse([], @err, @out))
|
||||
::Spec.should be_run
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -3,6 +3,8 @@ require File.dirname(__FILE__) + '/../../spec_helper.rb'
|
|||
module Spec
|
||||
module Runner
|
||||
describe DrbCommandLine, "without running local server" do
|
||||
include SandboxedOptions
|
||||
|
||||
unless Config::CONFIG['ruby_install_name'] == 'jruby'
|
||||
it "should print error when there is no running local server" do
|
||||
err = StringIO.new
|
||||
|
|
@ -15,12 +17,16 @@ module Spec
|
|||
end
|
||||
end
|
||||
|
||||
class DrbCommandLineSpec < ::Spec::Example::ExampleGroup
|
||||
describe DrbCommandLine, "with local server"
|
||||
describe "with local server" do
|
||||
|
||||
class CommandLineForSpec
|
||||
def self.run(argv, stderr, stdout)
|
||||
exit Spec::Runner::CommandLine.run(OptionParser.parse(argv, stderr, stdout))
|
||||
orig_options = Spec::Runner.options
|
||||
tmp_options = OptionParser.parse(argv, stderr, stdout)
|
||||
Spec::Runner.use tmp_options
|
||||
Spec::Runner::CommandLine.run(tmp_options)
|
||||
ensure
|
||||
Spec::Runner.use orig_options
|
||||
end
|
||||
end
|
||||
|
||||
|
|
@ -45,7 +51,7 @@ module Spec
|
|||
|
||||
it "should run against local server" do
|
||||
out = run_spec_via_druby(['--version'])
|
||||
out.should =~ /RSpec/n
|
||||
out.should =~ /rspec \d+\.\d+\.\d+.*/n
|
||||
end
|
||||
|
||||
it "should output green colorized text when running with --colour option" do
|
||||
|
|
@ -86,7 +92,8 @@ module Spec
|
|||
out.rewind; out.read
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -1,37 +0,0 @@
|
|||
require File.dirname(__FILE__) + '/../../spec_helper.rb'
|
||||
|
||||
describe "ExecutionContext" do
|
||||
|
||||
it "should provide duck_type()" do
|
||||
dt = duck_type(:length)
|
||||
dt.should be_an_instance_of(Spec::Mocks::DuckTypeArgConstraint)
|
||||
dt.matches?([]).should be_true
|
||||
end
|
||||
|
||||
it "should provide hash_including" do
|
||||
hi = hash_including(:a => 1)
|
||||
hi.should be_an_instance_of(Spec::Mocks::HashIncludingConstraint)
|
||||
hi.matches?(:a => 1).should be_true
|
||||
end
|
||||
|
||||
it "should violate when violated()" do
|
||||
lambda do
|
||||
violated
|
||||
end.should raise_error(Spec::Expectations::ExpectationNotMetError)
|
||||
end
|
||||
|
||||
it "should provide mock()" do
|
||||
mock("thing").should be_an_instance_of(Spec::Mocks::Mock)
|
||||
end
|
||||
|
||||
it "should provide stub()" do
|
||||
thing_stub = stub("thing").should be_an_instance_of(Spec::Mocks::Mock)
|
||||
end
|
||||
|
||||
it "should add method stubs to stub()" do
|
||||
thing_stub = stub("thing", :a => "A", :b => "B")
|
||||
thing_stub.a.should == "A"
|
||||
thing_stub.b.should == "B"
|
||||
end
|
||||
|
||||
end
|
||||
112
vendor/plugins/rspec/spec/spec/runner/formatter/base_formatter_spec.rb
vendored
Normal file
112
vendor/plugins/rspec/spec/spec/runner/formatter/base_formatter_spec.rb
vendored
Normal file
|
|
@ -0,0 +1,112 @@
|
|||
require File.dirname(__FILE__) + "/../../../spec_helper"
|
||||
|
||||
module Spec
|
||||
module Runner
|
||||
module Formatter
|
||||
describe BaseFormatter do
|
||||
before :each do
|
||||
@options, @where = nil, nil
|
||||
@formatter = BaseFormatter.new(@options, @where)
|
||||
end
|
||||
|
||||
class HaveInterfaceMatcher
|
||||
def initialize(method)
|
||||
@method = method
|
||||
end
|
||||
|
||||
attr_reader :object
|
||||
attr_reader :method
|
||||
|
||||
def matches?(object)
|
||||
@object = object
|
||||
object.respond_to?(@method)
|
||||
end
|
||||
|
||||
def with(arity)
|
||||
WithArity.new(self, @method, arity)
|
||||
end
|
||||
|
||||
class WithArity
|
||||
def initialize(matcher, method, arity)
|
||||
@have_matcher = matcher
|
||||
@method = method
|
||||
@arity = arity
|
||||
end
|
||||
|
||||
def matches?(an_object)
|
||||
@have_matcher.matches?(an_object) && real_arity == @arity
|
||||
end
|
||||
|
||||
def failure_message
|
||||
"#{@have_matcher} should have method :#{@method} with #{argument_arity}, but it had #{real_arity}"
|
||||
end
|
||||
|
||||
def arguments
|
||||
self
|
||||
end
|
||||
|
||||
alias_method :argument, :arguments
|
||||
|
||||
private
|
||||
|
||||
def real_arity
|
||||
@have_matcher.object.method(@method).arity
|
||||
end
|
||||
|
||||
def argument_arity
|
||||
if @arity == 1
|
||||
"1 argument"
|
||||
else
|
||||
"#{@arity} arguments"
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def have_interface_for(method)
|
||||
HaveInterfaceMatcher.new(method)
|
||||
end
|
||||
|
||||
it "should have start as an interface with one argument"do
|
||||
@formatter.should have_interface_for(:start).with(1).argument
|
||||
end
|
||||
|
||||
it "should have add_example_group as an interface with one argument" do
|
||||
@formatter.should have_interface_for(:add_example_group).with(1).argument
|
||||
end
|
||||
|
||||
it "should have example_started as an interface with one argument" do
|
||||
@formatter.should have_interface_for(:example_started).with(1).argument
|
||||
end
|
||||
|
||||
it "should have example_failed as an interface with three arguments" do
|
||||
@formatter.should have_interface_for(:example_failed).with(3).arguments
|
||||
end
|
||||
|
||||
it "should have example_pending as an interface with three arguments" do
|
||||
@formatter.should have_interface_for(:example_pending).with(3).arguments
|
||||
end
|
||||
|
||||
it "should have start_dump as an interface with zero arguments" do
|
||||
@formatter.should have_interface_for(:start_dump).with(0).arguments
|
||||
end
|
||||
|
||||
it "should have dump_failure as an interface with two arguments" do
|
||||
@formatter.should have_interface_for(:dump_failure).with(2).arguments
|
||||
end
|
||||
|
||||
it "should have dump_summary as an interface with two arguments" do
|
||||
@formatter.should have_interface_for(:dump_failure).with(2).arguments
|
||||
end
|
||||
|
||||
it "should have dump_pending as an interface with zero arguments" do
|
||||
@formatter.should have_interface_for(:dump_pending).with(0).arguments
|
||||
end
|
||||
|
||||
it "should have close as an interface with zero arguments" do
|
||||
@formatter.should have_interface_for(:close).with(0).arguments
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -6,6 +6,7 @@ module Spec
|
|||
module Runner
|
||||
module Formatter
|
||||
describe HtmlFormatter do
|
||||
include SandboxedOptions
|
||||
['--diff', '--dry-run'].each do |opt|
|
||||
def jruby?
|
||||
PLATFORM == 'java'
|
||||
|
|
@ -22,7 +23,7 @@ module Spec
|
|||
args = ['failing_examples/mocking_example.rb', 'failing_examples/diffing_spec.rb', 'examples/pure/stubbing_example.rb', 'examples/pure/pending_example.rb', '--format', 'html', opt]
|
||||
err = StringIO.new
|
||||
out = StringIO.new
|
||||
CommandLine.run(
|
||||
run_with(
|
||||
OptionParser.parse(args, err, out)
|
||||
)
|
||||
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ module Spec
|
|||
module Runner
|
||||
module Formatter
|
||||
describe NestedTextFormatter do
|
||||
it_should_behave_like "sandboxed rspec_options"
|
||||
include SandboxedOptions
|
||||
attr_reader :io, :options, :formatter, :example_group
|
||||
before(:each) do
|
||||
@io = StringIO.new
|
||||
|
|
@ -304,7 +304,7 @@ module Spec
|
|||
|
||||
describe "#example_pending" do
|
||||
it "should push pending example name and message" do
|
||||
formatter.example_pending(example_group.examples.first, 'reason')
|
||||
formatter.example_pending(example_group.examples.first, 'reason', "#{__FILE__}:#{__LINE__}")
|
||||
expected_output = <<-OUT
|
||||
ExampleGroup
|
||||
example (PENDING: reason)
|
||||
|
|
@ -313,7 +313,7 @@ module Spec
|
|||
end
|
||||
|
||||
it "should dump pending" do
|
||||
formatter.example_pending(example_group.examples.first, 'reason')
|
||||
formatter.example_pending(example_group.examples.first, 'reason', "#{__FILE__}:#{__LINE__}")
|
||||
io.rewind
|
||||
formatter.dump_pending
|
||||
io.string.should =~ /Pending\:\nExampleGroup example \(reason\)\n/
|
||||
|
|
|
|||
|
|
@ -29,7 +29,7 @@ module Spec
|
|||
end
|
||||
end
|
||||
example = example_group.examples.first
|
||||
@formatter.example_pending(example, "message")
|
||||
@formatter.example_pending(example, "message", "#{__FILE__}:#{__LINE__}")
|
||||
@io.rewind
|
||||
@formatter.dump_summary(3, 2, 1, 1)
|
||||
@io.string.should eql(%Q|
|
||||
|
|
@ -94,10 +94,28 @@ EOE
|
|||
end
|
||||
end
|
||||
example = example_group.examples.first
|
||||
@formatter.example_pending(example, "message")
|
||||
@formatter.example_pending(example, "message", "#{__FILE__}:#{__LINE__}")
|
||||
@formatter.dump_pending
|
||||
@io.string.should =~ /Pending\:\nexample_group example \(message\)\n/
|
||||
end
|
||||
|
||||
it "should dump pending with file and line number" do
|
||||
example_group = ExampleGroup.describe("example_group") do
|
||||
specify "example" do
|
||||
end
|
||||
end
|
||||
example = example_group.examples.first
|
||||
file = __FILE__
|
||||
line = __LINE__ + 1
|
||||
@formatter.example_pending(example, "message", "#{__FILE__}:#{__LINE__}")
|
||||
@formatter.dump_pending
|
||||
@io.string.should ==(<<-HERE)
|
||||
*
|
||||
Pending:
|
||||
example_group example (message)
|
||||
Called from #{file}:#{line}
|
||||
HERE
|
||||
end
|
||||
end
|
||||
|
||||
describe "ProgressBarFormatter outputting to custom out" do
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ module Spec
|
|||
module Runner
|
||||
module Formatter
|
||||
describe TextMateFormatter do
|
||||
include SandboxedOptions
|
||||
attr_reader :root, :suffix, :expected_file
|
||||
before do
|
||||
@root = File.expand_path(File.dirname(__FILE__) + '/../../../..')
|
||||
|
|
@ -33,7 +34,7 @@ module Spec
|
|||
err = StringIO.new
|
||||
out = StringIO.new
|
||||
options = ::Spec::Runner::OptionParser.parse(args, err, out)
|
||||
Spec::Runner::CommandLine.run(options)
|
||||
run_with(options)
|
||||
|
||||
yield(out.string)
|
||||
end
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ module Spec
|
|||
module Runner
|
||||
module Formatter
|
||||
describe SpecdocFormatter do
|
||||
it_should_behave_like "sandboxed rspec_options"
|
||||
include SandboxedOptions
|
||||
attr_reader :io, :options, :formatter, :example_group
|
||||
before(:each) do
|
||||
@io = StringIO.new
|
||||
|
|
@ -133,12 +133,12 @@ module Spec
|
|||
|
||||
describe "#example_pending" do
|
||||
it "should push pending example name and message" do
|
||||
formatter.example_pending(example_group.examples.first, 'reason')
|
||||
formatter.example_pending(example_group.examples.first, 'reason', "#{__FILE__}:#{__LINE__}")
|
||||
io.string.should have_example_group_output("- example (PENDING: reason)\n")
|
||||
end
|
||||
|
||||
it "should dump pending" do
|
||||
formatter.example_pending(example_group.examples.first, 'reason')
|
||||
formatter.example_pending(example_group.examples.first, 'reason', "#{__FILE__}:#{__LINE__}")
|
||||
io.rewind
|
||||
formatter.dump_pending
|
||||
io.string.should =~ /Pending\:\nExampleGroup example \(reason\)\n/
|
||||
|
|
|
|||
|
|
@ -61,6 +61,54 @@ module Spec
|
|||
EOF
|
||||
end
|
||||
|
||||
it 'should document additional givens using And' do
|
||||
# when
|
||||
@reporter.step_succeeded :given, 'step 1'
|
||||
@reporter.step_succeeded :given, 'step 2'
|
||||
@reporter.scenario_ended
|
||||
@reporter.story_ended '', ''
|
||||
|
||||
# then
|
||||
@out.string.should include("Given step 1")
|
||||
@out.string.should include("And step 2")
|
||||
end
|
||||
|
||||
it 'should document additional events using And' do
|
||||
# when
|
||||
@reporter.step_succeeded :when, 'step 1'
|
||||
@reporter.step_succeeded :when, 'step 2'
|
||||
@reporter.scenario_ended
|
||||
@reporter.story_ended '', ''
|
||||
|
||||
# then
|
||||
@out.string.should include("When step 1")
|
||||
@out.string.should include("And step 2")
|
||||
end
|
||||
|
||||
it 'should document additional outcomes using And' do
|
||||
# when
|
||||
@reporter.step_succeeded :then, 'step 1'
|
||||
@reporter.step_succeeded :then, 'step 2'
|
||||
@reporter.scenario_ended
|
||||
@reporter.story_ended '', ''
|
||||
|
||||
# then
|
||||
@out.string.should include("Then step 1")
|
||||
@out.string.should include("And step 2")
|
||||
end
|
||||
|
||||
it 'should document a GivenScenario followed by a Given using And' do
|
||||
# when
|
||||
@reporter.step_succeeded :'given scenario', 'a scenario'
|
||||
@reporter.step_succeeded :given, 'a context'
|
||||
@reporter.scenario_ended
|
||||
@reporter.story_ended '', ''
|
||||
|
||||
# then
|
||||
@out.string.should include("Given scenario a scenario")
|
||||
@out.string.should include("And a context")
|
||||
end
|
||||
|
||||
it "should create a failed story if one of its scenarios fails" do
|
||||
@reporter.story_started('story_title', 'narrative')
|
||||
@reporter.scenario_started('story_title', 'succeeded_scenario_name')
|
||||
|
|
|
|||
|
|
@ -159,6 +159,45 @@ module Spec
|
|||
@out.string.should include("3 scenarios: 1 succeeded, 1 failed, 1 pending")
|
||||
end
|
||||
|
||||
it 'should show test summary in red if there were failed scenarios' do
|
||||
# when
|
||||
@out.stub!(:tty?).and_return(true)
|
||||
@options.stub!(:colour).and_return(true)
|
||||
|
||||
@formatter.scenario_started(nil, nil)
|
||||
@formatter.scenario_failed('story', 'scenario', exception_from { raise RuntimeError, 'oops' })
|
||||
@formatter.run_ended
|
||||
|
||||
# then
|
||||
@out.string.should include("\e[31m scenarios: 0 succeeded, 1 failed, 0 pending\e[0m")
|
||||
end
|
||||
|
||||
it 'should show test summary in yellow if there are pending scenarios' do
|
||||
# when
|
||||
@out.stub!(:tty?).and_return(true)
|
||||
@options.stub!(:colour).and_return(true)
|
||||
|
||||
@formatter.scenario_started(nil, nil)
|
||||
@formatter.scenario_pending('story', 'scenario', '')
|
||||
@formatter.run_ended
|
||||
|
||||
# then
|
||||
@out.string.should include("\e[32m scenarios: 0 succeeded, 0 failed, 1 pending\e[0m")
|
||||
end
|
||||
|
||||
it 'should show test summary in green if all scenarios pass' do
|
||||
# when
|
||||
@out.stub!(:tty?).and_return(true)
|
||||
@options.stub!(:colour).and_return(true)
|
||||
|
||||
@formatter.scenario_started(nil, nil)
|
||||
@formatter.scenario_succeeded('story', 'scenario')
|
||||
@formatter.run_ended
|
||||
|
||||
# then
|
||||
@out.string.should include("\e[32m scenarios: 1 succeeded, 0 failed, 0 pending\e[0m")
|
||||
end
|
||||
|
||||
it 'should produce details of the first failure each failed scenario when the run ends' do
|
||||
# when
|
||||
@formatter.run_started(3)
|
||||
|
|
@ -180,6 +219,19 @@ module Spec
|
|||
@out.string.should include("RuntimeError: oops3")
|
||||
end
|
||||
|
||||
it 'should produce details of the failures in red when the run ends' do
|
||||
# when
|
||||
@out.stub!(:tty?).and_return(true)
|
||||
@options.stub!(:colour).and_return(true)
|
||||
@formatter.scenario_started(nil, nil)
|
||||
@formatter.scenario_failed('story', 'scenario1', exception_from { raise RuntimeError, 'oops1' })
|
||||
@formatter.run_ended
|
||||
|
||||
# then
|
||||
@out.string.should =~ /\e\[31m[\n\s]*story \(scenario1\) FAILED\e\[0m/m
|
||||
@out.string.should =~ /\e\[31m[\n\s]*RuntimeError: oops1\e\[0m/m
|
||||
end
|
||||
|
||||
it 'should produce details of each pending step when the run ends' do
|
||||
# when
|
||||
@formatter.run_started(2)
|
||||
|
|
|
|||
82
vendor/plugins/rspec/spec/spec/runner/formatter/story/progress_bar_formatter_spec.rb
vendored
Normal file
82
vendor/plugins/rspec/spec/spec/runner/formatter/story/progress_bar_formatter_spec.rb
vendored
Normal file
|
|
@ -0,0 +1,82 @@
|
|||
require File.dirname(__FILE__) + '/../../../../spec_helper'
|
||||
require 'spec/runner/formatter/story/progress_bar_formatter'
|
||||
|
||||
module Spec
|
||||
module Runner
|
||||
module Formatter
|
||||
module Story
|
||||
describe ProgressBarFormatter do
|
||||
before :each do
|
||||
# given
|
||||
@out = StringIO.new
|
||||
@out.stub!(:tty?).and_return(true)
|
||||
@tweaker = mock('tweaker')
|
||||
@tweaker.stub!(:tweak_backtrace)
|
||||
@options = mock('options')
|
||||
@options.stub!(:colour).and_return(true)
|
||||
@options.stub!(:backtrace_tweaker).and_return(@tweaker)
|
||||
|
||||
@formatter = ProgressBarFormatter.new(@options, @out)
|
||||
end
|
||||
|
||||
it 'should print some white space before test summary' do
|
||||
#when
|
||||
@formatter.run_started(1)
|
||||
@formatter.run_ended
|
||||
|
||||
#then
|
||||
@out.string.should =~ /^\n{2}/
|
||||
end
|
||||
|
||||
it "should print how long tests took to complete" do
|
||||
#when
|
||||
now = Time.now
|
||||
future = now+1
|
||||
Time.stub!(:now).and_return(now)
|
||||
@formatter.run_started(1)
|
||||
Time.stub!(:now).and_return(future)
|
||||
@formatter.run_ended
|
||||
|
||||
#then
|
||||
@out.string.should include("Finished in %f seconds" % (future-now))
|
||||
end
|
||||
|
||||
|
||||
it "should push green dot for passing scenario" do
|
||||
#when
|
||||
@formatter.scenario_started('','')
|
||||
@formatter.step_succeeded('', '')
|
||||
@formatter.scenario_ended
|
||||
@formatter.story_ended '', ''
|
||||
|
||||
#then
|
||||
@out.string.should eql("\e[32m.\e[0m")
|
||||
end
|
||||
|
||||
it "should push red F for failure scenario" do
|
||||
#when
|
||||
@formatter.scenario_started('','')
|
||||
@formatter.step_failed('', '')
|
||||
@formatter.scenario_failed('', '', '')
|
||||
@formatter.story_ended '', ''
|
||||
|
||||
#then
|
||||
@out.string.should eql("\e[31mF\e[0m")
|
||||
end
|
||||
|
||||
it "should push yellow P for pending scenario" do
|
||||
#when
|
||||
@formatter.scenario_started('','')
|
||||
@formatter.step_pending('', '')
|
||||
@formatter.scenario_pending('story', '', '')
|
||||
@formatter.story_ended '', ''
|
||||
|
||||
#then
|
||||
@out.string.should eql("\e[33mP\e[0m")
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -21,18 +21,18 @@ unless [/mswin/, /java/].detect{|p| p =~ RUBY_PLATFORM}
|
|||
end
|
||||
|
||||
it "should heckle all methods in all classes in a module" do
|
||||
@heckle_class.should_receive(:new).with("Foo::Bar", "one", rspec_options).and_return(@heckle)
|
||||
@heckle_class.should_receive(:new).with("Foo::Bar", "two", rspec_options).and_return(@heckle)
|
||||
@heckle_class.should_receive(:new).with("Foo::Zap", "three", rspec_options).and_return(@heckle)
|
||||
@heckle_class.should_receive(:new).with("Foo::Zap", "four", rspec_options).and_return(@heckle)
|
||||
@heckle_class.should_receive(:new).with("Foo::Bar", "one", Spec::Runner.options).and_return(@heckle)
|
||||
@heckle_class.should_receive(:new).with("Foo::Bar", "two", Spec::Runner.options).and_return(@heckle)
|
||||
@heckle_class.should_receive(:new).with("Foo::Zap", "three", Spec::Runner.options).and_return(@heckle)
|
||||
@heckle_class.should_receive(:new).with("Foo::Zap", "four", Spec::Runner.options).and_return(@heckle)
|
||||
|
||||
heckle_runner = Spec::Runner::HeckleRunner.new("Foo", @heckle_class)
|
||||
heckle_runner.heckle_with
|
||||
end
|
||||
|
||||
it "should heckle all methods in a class" do
|
||||
@heckle_class.should_receive(:new).with("Foo::Bar", "one", rspec_options).and_return(@heckle)
|
||||
@heckle_class.should_receive(:new).with("Foo::Bar", "two", rspec_options).and_return(@heckle)
|
||||
@heckle_class.should_receive(:new).with("Foo::Bar", "one", Spec::Runner.options).and_return(@heckle)
|
||||
@heckle_class.should_receive(:new).with("Foo::Bar", "two", Spec::Runner.options).and_return(@heckle)
|
||||
|
||||
heckle_runner = Spec::Runner::HeckleRunner.new("Foo::Bar", @heckle_class)
|
||||
heckle_runner.heckle_with
|
||||
|
|
@ -46,14 +46,14 @@ unless [/mswin/, /java/].detect{|p| p =~ RUBY_PLATFORM}
|
|||
end
|
||||
|
||||
it "should heckle specific method in a class (with #)" do
|
||||
@heckle_class.should_receive(:new).with("Foo::Bar", "two", rspec_options).and_return(@heckle)
|
||||
@heckle_class.should_receive(:new).with("Foo::Bar", "two", Spec::Runner.options).and_return(@heckle)
|
||||
|
||||
heckle_runner = Spec::Runner::HeckleRunner.new("Foo::Bar#two", @heckle_class)
|
||||
heckle_runner.heckle_with
|
||||
end
|
||||
|
||||
it "should heckle specific method in a class (with .)" do
|
||||
@heckle_class.should_receive(:new).with("Foo::Bar", "two", rspec_options).and_return(@heckle)
|
||||
@heckle_class.should_receive(:new).with("Foo::Bar", "two", Spec::Runner.options).and_return(@heckle)
|
||||
|
||||
heckle_runner = Spec::Runner::HeckleRunner.new("Foo::Bar.two", @heckle_class)
|
||||
heckle_runner.heckle_with
|
||||
|
|
|
|||
|
|
@ -1,6 +1,21 @@
|
|||
require File.dirname(__FILE__) + '/../../spec_helper.rb'
|
||||
require 'fileutils'
|
||||
|
||||
module Custom
|
||||
class ExampleGroupRunner
|
||||
attr_reader :options, :arg
|
||||
def initialize(options, arg)
|
||||
@options, @arg = options, arg
|
||||
end
|
||||
|
||||
def load_files(files)
|
||||
end
|
||||
|
||||
def run
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "OptionParser" do
|
||||
before(:each) do
|
||||
@out = StringIO.new
|
||||
|
|
@ -51,12 +66,18 @@ describe "OptionParser" do
|
|||
options.colour.should == false
|
||||
end
|
||||
|
||||
it "should print help to stdout if no args" do
|
||||
pending 'A regression since 1.0.8' do
|
||||
options = parse([])
|
||||
@out.rewind
|
||||
@out.read.should match(/Usage: spec \(FILE\|DIRECTORY\|GLOB\)\+ \[options\]/m)
|
||||
end
|
||||
it "should print help to stdout if no args and spec_comand?" do
|
||||
Spec.stub!(:spec_command?).and_return(true)
|
||||
options = parse([])
|
||||
@out.rewind
|
||||
@out.read.should match(/Usage: spec \(FILE\|DIRECTORY\|GLOB\)\+ \[options\]/m)
|
||||
end
|
||||
|
||||
it "should not print help to stdout if no args and NOT spec_command?" do
|
||||
Spec.stub!(:spec_command?).and_return(false)
|
||||
options = parse([])
|
||||
@out.rewind
|
||||
@out.read.should == ""
|
||||
end
|
||||
|
||||
it "should print help to stdout" do
|
||||
|
|
@ -76,7 +97,7 @@ describe "OptionParser" do
|
|||
it "should print version to stdout" do
|
||||
options = parse(["--version"])
|
||||
@out.rewind
|
||||
@out.read.should match(/RSpec-\d+\.\d+\.\d+.*\(build \d+\) - BDD for Ruby\nhttp:\/\/rspec.rubyforge.org\/\n/n)
|
||||
@out.read.should match(/rspec \d+\.\d+\.\d+/n)
|
||||
end
|
||||
|
||||
it "should require file when require specified" do
|
||||
|
|
@ -231,19 +252,19 @@ describe "OptionParser" do
|
|||
|
||||
describe "when attempting a focussed spec" do
|
||||
attr_reader :file, :dir
|
||||
before do
|
||||
@original_rspec_options = $rspec_options
|
||||
before(:each) do
|
||||
@original_rspec_options = Spec::Runner.options
|
||||
@file = "#{File.dirname(__FILE__)}/spec_parser/spec_parser_fixture.rb"
|
||||
@dir = File.dirname(file)
|
||||
end
|
||||
|
||||
after do
|
||||
$rspec_options = @original_rspec_options
|
||||
after(:each) do
|
||||
Spec::Runner.use @original_rspec_options
|
||||
end
|
||||
|
||||
def parse(args)
|
||||
options = super
|
||||
$rspec_options = options
|
||||
Spec::Runner.use options
|
||||
options.filename_pattern = "*_fixture.rb"
|
||||
options
|
||||
end
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
dir = File.dirname(__FILE__)
|
||||
require "#{dir}/../../spec_helper"
|
||||
|
||||
triggering_double_output = rspec_options
|
||||
triggering_double_output = Spec::Runner.options
|
||||
options = Spec::Runner::OptionParser.parse(
|
||||
["#{dir}/output_one_time_fixture.rb"], $stderr, $stdout
|
||||
)
|
||||
|
|
|
|||
|
|
@ -51,6 +51,12 @@ module Spec
|
|||
@tweaker.tweak_backtrace(@error)
|
||||
@error.backtrace.should include("/a/b/c/d.rb")
|
||||
end
|
||||
|
||||
it "should gracefully handle backtraces with newlines" do
|
||||
@error.set_backtrace(["we like\nbin/spec:\nnewlines"])
|
||||
@tweaker.tweak_backtrace(@error)
|
||||
@error.backtrace.should include("we like\nnewlines")
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ module Spec
|
|||
end
|
||||
|
||||
def failure
|
||||
Mocks::DuckTypeArgConstraint.new(:header, :exception)
|
||||
Mocks::ArgumentConstraints::DuckTypeConstraint.new(:header, :exception)
|
||||
end
|
||||
|
||||
def create_example_group(description_text)
|
||||
|
|
@ -155,26 +155,72 @@ module Spec
|
|||
end
|
||||
|
||||
describe Reporter, "reporting one pending example (ExamplePendingError)" do
|
||||
before :each do
|
||||
@pending_error = Spec::Example::ExamplePendingError.new("reason")
|
||||
@pending_caller = @pending_error.pending_caller
|
||||
end
|
||||
|
||||
it "should tell formatter example is pending" do
|
||||
example = ExampleGroup.new("example")
|
||||
formatter.should_receive(:example_pending).with(example, "reason")
|
||||
formatter.should_receive(:example_pending).with(example, "reason", @pending_caller)
|
||||
formatter.should_receive(:add_example_group).with(example_group)
|
||||
reporter.add_example_group(example_group)
|
||||
reporter.example_finished(example, Spec::Example::ExamplePendingError.new("reason"))
|
||||
reporter.example_finished(example, @pending_error)
|
||||
end
|
||||
|
||||
it "should account for pending example in stats" do
|
||||
example = ExampleGroup.new("example")
|
||||
formatter.should_receive(:example_pending).with(example, "reason")
|
||||
formatter.should_receive(:example_pending).with(example, "reason", @pending_caller)
|
||||
formatter.should_receive(:start_dump)
|
||||
formatter.should_receive(:dump_pending)
|
||||
formatter.should_receive(:dump_summary).with(anything(), 1, 0, 1)
|
||||
formatter.should_receive(:close).with(no_args)
|
||||
formatter.should_receive(:add_example_group).with(example_group)
|
||||
reporter.add_example_group(example_group)
|
||||
reporter.example_finished(example, Spec::Example::ExamplePendingError.new("reason"))
|
||||
reporter.example_finished(example, @pending_error)
|
||||
reporter.dump
|
||||
end
|
||||
|
||||
describe "to formatters which have example_pending's arity of 2 (which is now deprecated)" do
|
||||
before :each do
|
||||
Kernel.stub!(:warn).with(Spec::Runner::Reporter::EXAMPLE_PENDING_DEPRECATION_WARNING)
|
||||
|
||||
@deprecated_formatter = Class.new(@formatter.class) do
|
||||
attr_reader :example_passed_to_method, :message_passed_to_method
|
||||
|
||||
def example_pending(example_passed_to_method, message_passed_to_method)
|
||||
@example_passed_to_method = example_passed_to_method
|
||||
@message_passed_to_method = message_passed_to_method
|
||||
end
|
||||
end.new(options, formatter_output)
|
||||
|
||||
options.formatters << @deprecated_formatter
|
||||
end
|
||||
|
||||
it "should pass the correct example to the formatter" do
|
||||
example = ExampleGroup.new("example")
|
||||
reporter.add_example_group(example_group)
|
||||
reporter.example_finished(example, @pending_error)
|
||||
|
||||
@deprecated_formatter.example_passed_to_method.should == example
|
||||
end
|
||||
|
||||
it "should pass the correct pending error message to the formatter" do
|
||||
example = ExampleGroup.new("example")
|
||||
reporter.add_example_group(example_group)
|
||||
reporter.example_finished(example, @pending_error)
|
||||
|
||||
@deprecated_formatter.message_passed_to_method.should == @pending_error.message
|
||||
end
|
||||
|
||||
it "should raise a deprecation warning" do
|
||||
Kernel.should_receive(:warn).with(Spec::Runner::Reporter::EXAMPLE_PENDING_DEPRECATION_WARNING)
|
||||
|
||||
example = ExampleGroup.new("example")
|
||||
reporter.add_example_group(example_group)
|
||||
reporter.example_finished(example, @pending_error)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe Reporter, "reporting one pending example (PendingExampleFixedError)" do
|
||||
|
|
|
|||
|
|
@ -3,15 +3,15 @@ require File.dirname(__FILE__) + '/../../spec_helper.rb'
|
|||
describe "SpecParser" do
|
||||
attr_reader :parser, :file
|
||||
before(:each) do
|
||||
@original_rspec_options = $rspec_options
|
||||
$rspec_options = ::Spec::Runner::Options.new(StringIO.new, StringIO.new)
|
||||
@original_rspec_options = Spec::Runner.options
|
||||
Spec::Runner.use ::Spec::Runner::Options.new(StringIO.new, StringIO.new)
|
||||
@parser = Spec::Runner::SpecParser.new
|
||||
@file = "#{File.dirname(__FILE__)}/spec_parser/spec_parser_fixture.rb"
|
||||
load file
|
||||
end
|
||||
|
||||
after do
|
||||
$rspec_options = @original_rspec_options
|
||||
after(:each) do
|
||||
Spec::Runner.use @original_rspec_options
|
||||
end
|
||||
|
||||
it "should find spec name for 'specify' at same line" do
|
||||
|
|
|
|||
|
|
@ -22,11 +22,8 @@ module Spec
|
|||
|
||||
it "should parse a story file" do
|
||||
runner = PlainTextStoryRunner.new("path")
|
||||
during {
|
||||
runner.run(mock('runner'))
|
||||
}.expect {
|
||||
@parser.should_receive(:parse).with(["this", "and that"])
|
||||
}
|
||||
@parser.should_receive(:parse).with(["this", "and that"])
|
||||
runner.run(mock('runner'))
|
||||
end
|
||||
|
||||
it "should build up a mediator with its own steps and the singleton story_runner" do
|
||||
|
|
|
|||
|
|
@ -235,13 +235,13 @@ module Spec
|
|||
it 'should find a scenario in the current story by name' do
|
||||
# given
|
||||
story_runner = StoryRunner.new(ScenarioRunner.new)
|
||||
$scenario = nil
|
||||
scenario = nil
|
||||
|
||||
story_runner.Story 'title', 'narrative' do
|
||||
Scenario 'first scenario' do
|
||||
end
|
||||
Scenario 'second scenario' do
|
||||
$scenario = StoryRunner.scenario_from_current_story 'first scenario'
|
||||
scenario = StoryRunner.scenario_from_current_story 'first scenario'
|
||||
end
|
||||
end
|
||||
|
||||
|
|
@ -249,7 +249,7 @@ module Spec
|
|||
story_runner.run_stories
|
||||
|
||||
# then
|
||||
$scenario.name.should == 'first scenario'
|
||||
scenario.name.should == 'first scenario'
|
||||
end
|
||||
|
||||
it "should clean the steps between stories" do
|
||||
|
|
|
|||
|
|
@ -8,9 +8,7 @@ module Spec
|
|||
story = StoryBuilder.new.to_story
|
||||
|
||||
# when
|
||||
error = exception_from do
|
||||
Scenario.new story, 'name'
|
||||
end
|
||||
error = exception_from { Scenario.new story, 'name' }
|
||||
|
||||
# then
|
||||
error.should be_nil
|
||||
|
|
|
|||
|
|
@ -42,6 +42,18 @@ module Spec
|
|||
end.should raise_error(Spec::Example::ExamplePendingError, /Unimplemented/)
|
||||
end
|
||||
|
||||
it "should create a default step with it's name stripped" do
|
||||
# given
|
||||
step_mother = StepMother.new
|
||||
|
||||
# when
|
||||
step = step_mother.find(:given, "doesn't exist\n\n")
|
||||
|
||||
# then
|
||||
step.should be_an_instance_of(Step)
|
||||
step.name.should == "doesn't exist"
|
||||
end
|
||||
|
||||
it 'should clear itself' do
|
||||
# given
|
||||
step_mother = StepMother.new
|
||||
|
|
|
|||
|
|
@ -2,12 +2,17 @@ require File.dirname(__FILE__) + '/story_helper'
|
|||
|
||||
module Spec
|
||||
module Story
|
||||
describe Step, "matching" do
|
||||
describe Step, "#matching" do
|
||||
it "should match a text string" do
|
||||
step = Step.new("this text") {}
|
||||
step.matches?("this text").should be_true
|
||||
end
|
||||
|
||||
it "should match a text string that has additional line returns" do
|
||||
step = Step.new("this text") {}
|
||||
step.matches?("this text\n\n").should be_true
|
||||
end
|
||||
|
||||
it "should not match a text string that does not start the same" do
|
||||
step = Step.new("this text") {}
|
||||
step.matches?("Xthis text").should be_false
|
||||
|
|
@ -32,6 +37,11 @@ module Spec
|
|||
step = Step.new("1 $one 2 $two 3 $three 4") {}
|
||||
step.matches?("1 a 2 b 3 c 4").should be_true
|
||||
end
|
||||
|
||||
it "should match a text string with two params sharing a prefix" do
|
||||
step = Step.new("I am cool $n times out of $n_total")
|
||||
step.matches?("I am cool 3 times out of 7").should be_true
|
||||
end
|
||||
|
||||
it "should match a text string with a param at the beginning" do
|
||||
step = Step.new("$one 2 3") {}
|
||||
|
|
@ -128,7 +138,7 @@ module Spec
|
|||
end
|
||||
|
||||
it "should match a multiline regex" do
|
||||
step = Step.new(/.* should have text.$text/) {}
|
||||
step = Step.new(/.*should have text.$text/) {}
|
||||
step.matches?(<<TEXT).should be_true
|
||||
should have text
|
||||
this is the text
|
||||
|
|
@ -153,6 +163,18 @@ TEXT
|
|||
end
|
||||
end
|
||||
|
||||
describe Step, "#parse_args" do
|
||||
it "should return an empty array for a text string with no parameters" do
|
||||
step = Step.new("this text") {}
|
||||
step.parse_args("this text").should == []
|
||||
end
|
||||
|
||||
it "should return an empty array for a text string with additional line returns and no parameters" do
|
||||
step = Step.new("this text") {}
|
||||
step.parse_args("this text\n\n").should == []
|
||||
end
|
||||
end
|
||||
|
||||
describe Step do
|
||||
it "should be pending with no block" do
|
||||
step = Step.new("foo")
|
||||
|
|
|
|||
|
|
@ -20,9 +20,7 @@ module Spec
|
|||
|
||||
it 'should not raise an error if no block is supplied' do
|
||||
# when
|
||||
error = exception_from do
|
||||
Story.new 'title', 'narrative'
|
||||
end
|
||||
error = exception_from { Story.new 'title', 'narrative' }
|
||||
|
||||
# then
|
||||
error.should be_nil
|
||||
|
|
|
|||
|
|
@ -347,10 +347,10 @@ module Spec
|
|||
|
||||
it 'should suppress listeners while it runs a GivenScenario' do
|
||||
# given
|
||||
$scenario_ran = false
|
||||
scenario_ran = false
|
||||
|
||||
scenario = ScenarioBuilder.new.name('a scenario').to_scenario do
|
||||
$scenario_ran = true
|
||||
scenario_ran = true
|
||||
Given 'given' do end
|
||||
When 'event' do end
|
||||
Then 'outcome' do end
|
||||
|
|
@ -374,16 +374,16 @@ module Spec
|
|||
world.GivenScenario 'a scenario'
|
||||
|
||||
# then
|
||||
$scenario_ran.should be_true
|
||||
scenario_ran.should be_true
|
||||
end
|
||||
|
||||
it 'should interpret GivenScenario... And... as multiple givens' do
|
||||
# given
|
||||
world = World.create
|
||||
$steps = []
|
||||
steps = []
|
||||
|
||||
scenario = ScenarioBuilder.new.name('a scenario').to_scenario do
|
||||
$steps << 1
|
||||
steps << 1
|
||||
end
|
||||
Runner::StoryRunner.should_receive(:scenario_from_current_story).
|
||||
with('a scenario').and_return(scenario)
|
||||
|
|
@ -392,12 +392,12 @@ module Spec
|
|||
world.instance_eval do
|
||||
GivenScenario 'a scenario'
|
||||
And 'step 2' do
|
||||
$steps << 2
|
||||
steps << 2
|
||||
end
|
||||
end
|
||||
|
||||
# then
|
||||
$steps.should == [1,2]
|
||||
steps.should == [1,2]
|
||||
World.step_mother.find(:given, 'step 2').should_not be_nil
|
||||
end
|
||||
|
||||
|
|
|
|||
265
vendor/plugins/rspec/spec/spec/translator_spec.rb
vendored
265
vendor/plugins/rspec/spec/spec/translator_spec.rb
vendored
|
|
@ -1,265 +0,0 @@
|
|||
require File.dirname(__FILE__) + '/../spec_helper.rb'
|
||||
require 'spec/translator'
|
||||
|
||||
describe "Translator" do
|
||||
before do
|
||||
@t = Spec::Translator.new
|
||||
end
|
||||
|
||||
it "should translate files" do
|
||||
from = File.dirname(__FILE__) + '/..'
|
||||
to = "#{Dir.tmpdir}/translated_specs"
|
||||
@t.translate_dir(from, to)
|
||||
end
|
||||
|
||||
it "should translate context_setup do" do
|
||||
@t.translate_line(
|
||||
"context_setup do\n"
|
||||
).should eql(
|
||||
"before(:all) do\n"
|
||||
)
|
||||
end
|
||||
|
||||
it "should translate context_setup {foo}" do
|
||||
@t.translate_line(
|
||||
"context_setup {foo}\n"
|
||||
).should eql(
|
||||
"before(:all) {foo}\n"
|
||||
)
|
||||
end
|
||||
|
||||
it "should translate context ' to describe '" do
|
||||
@t.translate_line(
|
||||
"context 'Translator' do\n"
|
||||
).should eql(
|
||||
"describe 'Translator' do\n"
|
||||
)
|
||||
end
|
||||
|
||||
it 'should translate context " to describe "' do
|
||||
@t.translate_line(
|
||||
'context "Translator"'
|
||||
).should eql(
|
||||
'describe "Translator"'
|
||||
)
|
||||
end
|
||||
|
||||
it 'should translate spaces then context " to describe "' do
|
||||
@t.translate_line(
|
||||
' context "Translator"'
|
||||
).should eql(
|
||||
' describe "Translator"'
|
||||
)
|
||||
end
|
||||
|
||||
it "should not translate context=foo" do
|
||||
@t.translate_line(' context=foo').should eql(' context=foo')
|
||||
end
|
||||
|
||||
it "should not translate context = foo" do
|
||||
@t.translate_line(' context = foo').should eql(' context = foo')
|
||||
end
|
||||
|
||||
it "should not translate context = foo" do
|
||||
@t.translate_line(' context = foo').should eql(' context = foo')
|
||||
end
|
||||
|
||||
it "should translate should_be_close" do
|
||||
@t.translate_line('5.0.should_be_close(5.0, 0.5)').should eql('5.0.should be_close(5.0, 0.5)')
|
||||
end
|
||||
|
||||
it "should translate should_not_raise" do
|
||||
@t.translate_line('lambda { self.call }.should_not_raise').should eql('lambda { self.call }.should_not raise_error')
|
||||
end
|
||||
|
||||
it "should translate should_throw" do
|
||||
@t.translate_line('lambda { self.call }.should_throw').should eql('lambda { self.call }.should throw_symbol')
|
||||
end
|
||||
|
||||
it "should not translate 0.9 should_not" do
|
||||
@t.translate_line('@target.should_not @matcher').should eql('@target.should_not @matcher')
|
||||
end
|
||||
|
||||
it "should leave should_not_receive" do
|
||||
@t.translate_line('@mock.should_not_receive(:not_expected).with("unexpected text")').should eql('@mock.should_not_receive(:not_expected).with("unexpected text")')
|
||||
end
|
||||
|
||||
it "should leave should_receive" do
|
||||
@t.translate_line('@mock.should_receive(:not_expected).with("unexpected text")').should eql('@mock.should_receive(:not_expected).with("unexpected text")')
|
||||
end
|
||||
|
||||
it "should translate multi word predicates" do
|
||||
@t.translate_line('foo.should_multi_word_predicate').should eql('foo.should be_multi_word_predicate')
|
||||
end
|
||||
|
||||
it "should translate multi word predicates prefixed with be" do
|
||||
@t.translate_line('foo.should_be_multi_word_predicate').should eql('foo.should be_multi_word_predicate')
|
||||
end
|
||||
|
||||
it "should translate be(expected) to equal(expected)" do
|
||||
@t.translate_line('foo.should_be :cool').should eql('foo.should equal :cool')
|
||||
end
|
||||
|
||||
it "should translate instance_of" do
|
||||
@t.translate_line('5.should_be_an_instance_of(Integer)').should eql('5.should be_an_instance_of(Integer)')
|
||||
end
|
||||
|
||||
it "should translate should_be <" do
|
||||
@t.translate_line('3.should_be < 4').should eql('3.should be < 4')
|
||||
end
|
||||
|
||||
it "should translate should_be <=" do
|
||||
@t.translate_line('3.should_be <= 4').should eql('3.should be <= 4')
|
||||
end
|
||||
|
||||
it "should translate should_be >=" do
|
||||
@t.translate_line('4.should_be >= 3').should eql('4.should be >= 3')
|
||||
end
|
||||
|
||||
it "should translate should_be >" do
|
||||
@t.translate_line('4.should_be > 3').should eql('4.should be > 3')
|
||||
end
|
||||
|
||||
it "should translate should_be_happy" do
|
||||
@t.translate_line("4.should_be_happy").should eql("4.should be_happy")
|
||||
end
|
||||
|
||||
it "should translate custom method taking regexp with parenthesis" do
|
||||
@t.translate_line("@browser.should_contain_text(/Sn.rrunger og annet rusk/)").should eql("@browser.should be_contain_text(/Sn.rrunger og annet rusk/)")
|
||||
end
|
||||
|
||||
it "should translate custom method taking regexp without parenthesis" do
|
||||
@t.translate_line("@browser.should_contain_text /Sn.rrunger og annet rusk/\n").should eql("@browser.should be_contain_text(/Sn.rrunger og annet rusk/)\n")
|
||||
end
|
||||
|
||||
it "should translate should_not_be_nil" do
|
||||
@t.translate_line("foo.should_not_be_nil\n").should eql("foo.should_not be_nil\n")
|
||||
end
|
||||
|
||||
it "should translate kind of" do
|
||||
@t.translate_line('@object.should_be_kind_of(MessageExpectation)').should(
|
||||
eql('@object.should be_kind_of(MessageExpectation)'))
|
||||
end
|
||||
|
||||
it "should translate should_be_true" do
|
||||
@t.translate_line("foo.should_be_true\n").should eql("foo.should be_true\n")
|
||||
end
|
||||
|
||||
# [#9674] spec_translate incorrectly handling shoud_match, when regexp in a var, in a block
|
||||
# http://rubyforge.org/tracker/?func=detail&atid=3149&aid=9674&group_id=797
|
||||
it "should translate should_match on a regexp, in a var, in a block" do
|
||||
@t.translate_line("collection.each { |c| c.should_match a_regexp_in_a_var }\n").should eql("collection.each { |c| c.should match(a_regexp_in_a_var) }\n")
|
||||
@t.translate_line("collection.each{|c| c.should_match a_regexp_in_a_var}\n").should eql("collection.each{|c| c.should match(a_regexp_in_a_var) }\n")
|
||||
end
|
||||
|
||||
# From Rubinius specs
|
||||
it "should translate close_to without parens" do
|
||||
@t.translate_line("end.should_be_close 3.14159_26535_89793_23846, TOLERANCE\n").should eql("end.should be_close(3.14159_26535_89793_23846, TOLERANCE)\n")
|
||||
end
|
||||
|
||||
# [#9882] 0.9 Beta 1 - translator bugs
|
||||
# http://rubyforge.org/tracker/index.php?func=detail&aid=9882&group_id=797&atid=3149
|
||||
it "should support symbol arguments" do
|
||||
@t.translate_line(
|
||||
"lambda { sequence.parse('bar') }.should_throw :ZeroWidthParseSuccess\n"
|
||||
).should eql(
|
||||
"lambda { sequence.parse('bar') }.should throw_symbol(:ZeroWidthParseSuccess)\n"
|
||||
)
|
||||
end
|
||||
|
||||
# [#9882] 0.9 Beta 1 - translator bugs
|
||||
# http://rubyforge.org/tracker/index.php?func=detail&aid=9882&group_id=797&atid=3149
|
||||
it "should support instance var arguments" do
|
||||
@t.translate_line(
|
||||
"a.should_eql @local"
|
||||
).should eql(
|
||||
"a.should eql(@local)"
|
||||
)
|
||||
end
|
||||
|
||||
# [#9882] 0.9 Beta 1 - translator bugs
|
||||
# http://rubyforge.org/tracker/index.php?func=detail&aid=9882&group_id=797&atid=3149
|
||||
it "should support lambdas as expecteds" do
|
||||
@t.translate_line(
|
||||
"@parslet.should_not_eql lambda { nil }.to_parseable"
|
||||
).should eql(
|
||||
"@parslet.should_not eql(lambda { nil }.to_parseable)"
|
||||
)
|
||||
end
|
||||
|
||||
# [#9882] 0.9 Beta 1 - translator bugs
|
||||
# http://rubyforge.org/tracker/index.php?func=detail&aid=9882&group_id=797&atid=3149
|
||||
it "should support fully qualified names" do
|
||||
@t.translate_line(
|
||||
"results.should_be_kind_of SimpleASTLanguage::Identifier"
|
||||
).should eql(
|
||||
"results.should be_kind_of(SimpleASTLanguage::Identifier)"
|
||||
)
|
||||
end
|
||||
|
||||
# [#9882] 0.9 Beta 1 - translator bugs
|
||||
# http://rubyforge.org/tracker/index.php?func=detail&aid=9882&group_id=797&atid=3149
|
||||
# it "should leave whitespace between expression and comments" do
|
||||
# @t.translate_line(
|
||||
# "lambda { @instance.foo = foo }.should_raise NoMethodError # no writer defined"
|
||||
# ).should eql(
|
||||
# "lambda { @instance.foo = foo }.should raise_error(NoMethodError) # no writer defined"
|
||||
# )
|
||||
# end
|
||||
|
||||
it "should translate redirects" do
|
||||
@t.translate_line(
|
||||
"controller.should_redirect_to 'http://not_existing_domain_for_novalis.test.host/404.html'"
|
||||
).should eql(
|
||||
"controller.should redirect_to('http://not_existing_domain_for_novalis.test.host/404.html')"
|
||||
)
|
||||
end
|
||||
|
||||
it "should translate :any_args" do
|
||||
@t.translate_line(
|
||||
"mock.should_receive(:foo).with(:any_args)"
|
||||
).should eql(
|
||||
"mock.should_receive(:foo).with(any_args)"
|
||||
)
|
||||
end
|
||||
|
||||
it "should translate :anything" do
|
||||
@t.translate_line(
|
||||
"mock.should_receive(:foo).with(:anything)"
|
||||
).should eql(
|
||||
"mock.should_receive(:foo).with(anything)"
|
||||
)
|
||||
end
|
||||
|
||||
it "should translate :boolean" do
|
||||
@t.translate_line(
|
||||
"mock.should_receive(:foo).with(:boolean)"
|
||||
).should eql(
|
||||
"mock.should_receive(:foo).with(boolean)"
|
||||
)
|
||||
end
|
||||
|
||||
it "should translate :no_args" do
|
||||
@t.translate_line(
|
||||
"mock.should_receive(:foo).with(:no_args)"
|
||||
).should eql(
|
||||
"mock.should_receive(:foo).with(no_args)"
|
||||
)
|
||||
end
|
||||
|
||||
it "should translate :numeric" do
|
||||
@t.translate_line(
|
||||
"mock.should_receive(:foo).with(:numeric)"
|
||||
).should eql(
|
||||
"mock.should_receive(:foo).with(an_instance_of(Numeric))"
|
||||
)
|
||||
end
|
||||
|
||||
it "should translate :string" do
|
||||
@t.translate_line(
|
||||
"mock.should_receive(:foo).with(:string)"
|
||||
).should eql(
|
||||
"mock.should_receive(:foo).with(an_instance_of(String))"
|
||||
)
|
||||
end
|
||||
end
|
||||
91
vendor/plugins/rspec/spec/spec_helper.rb
vendored
91
vendor/plugins/rspec/spec/spec_helper.rb
vendored
|
|
@ -12,7 +12,11 @@ spec_classes_path = File.expand_path("#{dir}/../spec/spec/spec_classes")
|
|||
require spec_classes_path unless $LOAD_PATH.include?(spec_classes_path)
|
||||
require File.dirname(__FILE__) + '/../lib/spec/expectations/differs/default'
|
||||
|
||||
module Spec
|
||||
module Spec
|
||||
module Example
|
||||
class NonStandardError < Exception; end
|
||||
end
|
||||
|
||||
module Matchers
|
||||
def fail
|
||||
raise_error(Spec::Expectations::ExpectationNotMetError)
|
||||
|
|
@ -22,82 +26,31 @@ module Spec
|
|||
raise_error(Spec::Expectations::ExpectationNotMetError, message)
|
||||
end
|
||||
|
||||
class Pass
|
||||
def matches?(proc, &block)
|
||||
begin
|
||||
proc.call
|
||||
true
|
||||
rescue Exception => @error
|
||||
false
|
||||
end
|
||||
def exception_from(&block)
|
||||
exception = nil
|
||||
begin
|
||||
yield
|
||||
rescue StandardError => e
|
||||
exception = e
|
||||
end
|
||||
|
||||
def failure_message
|
||||
@error.message + "\n" + @error.backtrace.join("\n")
|
||||
end
|
||||
end
|
||||
|
||||
def pass
|
||||
Pass.new
|
||||
end
|
||||
|
||||
class CorrectlyOrderedMockExpectation
|
||||
def initialize(&event)
|
||||
@event = event
|
||||
end
|
||||
|
||||
def expect(&expectations)
|
||||
expectations.call
|
||||
@event.call
|
||||
end
|
||||
end
|
||||
|
||||
def during(&block)
|
||||
CorrectlyOrderedMockExpectation.new(&block)
|
||||
exception
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
class NonStandardError < Exception; end
|
||||
|
||||
module Custom
|
||||
class ExampleGroupRunner
|
||||
attr_reader :options, :arg
|
||||
def initialize(options, arg)
|
||||
@options, @arg = options, arg
|
||||
end
|
||||
|
||||
def load_files(files)
|
||||
end
|
||||
|
||||
def run
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def exception_from(&block)
|
||||
exception = nil
|
||||
begin
|
||||
yield
|
||||
rescue StandardError => e
|
||||
exception = e
|
||||
end
|
||||
exception
|
||||
end
|
||||
|
||||
describe "sandboxed rspec_options", :shared => true do
|
||||
share_as :SandboxedOptions do
|
||||
attr_reader :options
|
||||
|
||||
before(:all) do
|
||||
@original_rspec_options = $rspec_options
|
||||
end
|
||||
|
||||
before(:each) do
|
||||
@options = ::Spec::Runner::Options.new(StringIO.new, StringIO.new)
|
||||
$rspec_options = options
|
||||
@original_rspec_options = ::Spec::Runner.options
|
||||
::Spec::Runner.use(@options = ::Spec::Runner::Options.new(StringIO.new, StringIO.new))
|
||||
end
|
||||
|
||||
after do
|
||||
$rspec_options = @original_rspec_options
|
||||
after(:each) do
|
||||
::Spec::Runner.use(@original_rspec_options)
|
||||
end
|
||||
end
|
||||
|
||||
def run_with(options)
|
||||
::Spec::Runner::CommandLine.run(options)
|
||||
end
|
||||
end unless Object.const_defined?(:SandboxedOptions)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue