You are viewing a plain text version of this content. The canonical link for it is here.
Posted to olio-commits@incubator.apache.org by ws...@apache.org on 2008/12/11 01:34:30 UTC
svn commit: r725524 [12/14] - in /incubator/olio/webapp/rails/trunk:
app/controllers/ app/models/ app/views/events/ config/ config/environments/
spec/controllers/ spec/models/ vendor/plugins/attachment_fu/
vendor/plugins/attachment_fu/lib/ vendor/plugi...
Added: incubator/olio/webapp/rails/trunk/vendor/plugins/rspec/spec/spec/expectations/wrap_expectation_spec.rb
URL: http://svn.apache.org/viewvc/incubator/olio/webapp/rails/trunk/vendor/plugins/rspec/spec/spec/expectations/wrap_expectation_spec.rb?rev=725524&view=auto
==============================================================================
--- incubator/olio/webapp/rails/trunk/vendor/plugins/rspec/spec/spec/expectations/wrap_expectation_spec.rb (added)
+++ incubator/olio/webapp/rails/trunk/vendor/plugins/rspec/spec/spec/expectations/wrap_expectation_spec.rb Wed Dec 10 17:34:18 2008
@@ -0,0 +1,30 @@
+require File.dirname(__FILE__) + '/../../spec_helper.rb'
+
+module Spec
+ module Matchers
+ describe "wrap_expectation" do
+
+ def stub_matcher
+ @_stub_matcher ||= simple_matcher do
+ end
+ end
+
+ def failing_matcher
+ @_failing_matcher ||= simple_matcher do
+ 1.should == 2
+ end
+ end
+
+ it "should return true if there is no error" do
+ wrap_expectation stub_matcher do
+ end.should be_true
+ end
+
+ it "should return false if there is an error" do
+ wrap_expectation failing_matcher do
+ raise "error"
+ end.should be_false
+ end
+ end
+ end
+end
\ No newline at end of file
Added: incubator/olio/webapp/rails/trunk/vendor/plugins/rspec/spec/spec/interop/test/unit/resources/spec_with_options_hash.rb
URL: http://svn.apache.org/viewvc/incubator/olio/webapp/rails/trunk/vendor/plugins/rspec/spec/spec/interop/test/unit/resources/spec_with_options_hash.rb?rev=725524&view=auto
==============================================================================
--- incubator/olio/webapp/rails/trunk/vendor/plugins/rspec/spec/spec/interop/test/unit/resources/spec_with_options_hash.rb (added)
+++ incubator/olio/webapp/rails/trunk/vendor/plugins/rspec/spec/spec/interop/test/unit/resources/spec_with_options_hash.rb Wed Dec 10 17:34:18 2008
@@ -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
\ No newline at end of file
Modified: incubator/olio/webapp/rails/trunk/vendor/plugins/rspec/spec/spec/interop/test/unit/spec_spec.rb
URL: http://svn.apache.org/viewvc/incubator/olio/webapp/rails/trunk/vendor/plugins/rspec/spec/spec/interop/test/unit/spec_spec.rb?rev=725524&r1=725523&r2=725524&view=diff
==============================================================================
--- incubator/olio/webapp/rails/trunk/vendor/plugins/rspec/spec/spec/interop/test/unit/spec_spec.rb (original)
+++ incubator/olio/webapp/rails/trunk/vendor/plugins/rspec/spec/spec/interop/test/unit/spec_spec.rb Wed Dec 10 17:34:18 2008
@@ -2,44 +2,47 @@
describe "ExampleGroup with test/unit/interop" do
include TestUnitSpecHelper
-
- before(:each) do
- @dir = File.dirname(__FILE__) + "/resources"
- end
-
+
describe "with passing examples" do
it "should output 0 failures" do
- output = ruby("#{@dir}/spec_that_passes.rb")
+ output = ruby("#{resources}/spec_that_passes.rb")
output.should include("1 example, 0 failures")
end
it "should return an exit code of 0" do
- ruby("#{@dir}/spec_that_passes.rb")
+ ruby("#{resources}/spec_that_passes.rb")
$?.should == 0
end
end
describe "with failing examples" do
it "should output 1 failure" do
- output = ruby("#{@dir}/spec_that_fails.rb")
+ output = ruby("#{resources}/spec_that_fails.rb")
output.should include("1 example, 1 failure")
end
it "should return an exit code of 256" do
- ruby("#{@dir}/spec_that_fails.rb")
+ ruby("#{resources}/spec_that_fails.rb")
$?.should == 256
end
end
describe "with example that raises an error" do
it "should output 1 failure" do
- output = ruby("#{@dir}/spec_with_errors.rb")
+ output = ruby("#{resources}/spec_with_errors.rb")
output.should include("1 example, 1 failure")
end
it "should return an exit code of 256" do
- ruby("#{@dir}/spec_with_errors.rb")
+ ruby("#{resources}/spec_with_errors.rb")
$?.should == 256
end
end
+
+ describe "options hash" do
+ it "should be exposed" do
+ output = ruby("#{resources}/spec_with_options_hash.rb")
+ output.should include("1 example, 0 failures")
+ end
+ end
end
\ No newline at end of file
Modified: incubator/olio/webapp/rails/trunk/vendor/plugins/rspec/spec/spec/interop/test/unit/test_unit_spec_helper.rb
URL: http://svn.apache.org/viewvc/incubator/olio/webapp/rails/trunk/vendor/plugins/rspec/spec/spec/interop/test/unit/test_unit_spec_helper.rb?rev=725524&r1=725523&r2=725524&view=diff
==============================================================================
--- incubator/olio/webapp/rails/trunk/vendor/plugins/rspec/spec/spec/interop/test/unit/test_unit_spec_helper.rb (original)
+++ incubator/olio/webapp/rails/trunk/vendor/plugins/rspec/spec/spec/interop/test/unit/test_unit_spec_helper.rb Wed Dec 10 17:34:18 2008
@@ -3,6 +3,10 @@
module TestUnitSpecHelper
include RubyForker
+
+ def resources
+ File.dirname(__FILE__) + "/resources"
+ end
def run_script(file_name)
output = ruby(file_name)
Modified: incubator/olio/webapp/rails/trunk/vendor/plugins/rspec/spec/spec/interop/test/unit/testcase_spec.rb
URL: http://svn.apache.org/viewvc/incubator/olio/webapp/rails/trunk/vendor/plugins/rspec/spec/spec/interop/test/unit/testcase_spec.rb?rev=725524&r1=725523&r2=725524&view=diff
==============================================================================
--- incubator/olio/webapp/rails/trunk/vendor/plugins/rspec/spec/spec/interop/test/unit/testcase_spec.rb (original)
+++ incubator/olio/webapp/rails/trunk/vendor/plugins/rspec/spec/spec/interop/test/unit/testcase_spec.rb Wed Dec 10 17:34:18 2008
@@ -42,4 +42,8 @@
$?.should == 256
end
end
+
+ describe "not yet implemented examples:" do
+ it "this example should be reported as pending (not an error)"
+ end
end
\ No newline at end of file
Modified: incubator/olio/webapp/rails/trunk/vendor/plugins/rspec/spec/spec/matchers/be_close_spec.rb
URL: http://svn.apache.org/viewvc/incubator/olio/webapp/rails/trunk/vendor/plugins/rspec/spec/spec/matchers/be_close_spec.rb?rev=725524&r1=725523&r2=725524&view=diff
==============================================================================
--- incubator/olio/webapp/rails/trunk/vendor/plugins/rspec/spec/spec/matchers/be_close_spec.rb (original)
+++ incubator/olio/webapp/rails/trunk/vendor/plugins/rspec/spec/spec/matchers/be_close_spec.rb Wed Dec 10 17:34:18 2008
@@ -1,38 +1,40 @@
require File.dirname(__FILE__) + '/../../spec_helper.rb'
module Spec
module Matchers
- describe BeClose do
+ describe "be_close" do
it "should match when value == target" do
- BeClose.new(5.0, 0.5).matches?(5.0).should be_true
+ be_close(5.0, 0.5).matches?(5.0).should be_true
end
it "should match when value < (target + delta)" do
- BeClose.new(5.0, 0.5).matches?(5.49).should be_true
+ be_close(5.0, 0.5).matches?(5.49).should be_true
end
it "should match when value > (target - delta)" do
- BeClose.new(5.0, 0.5).matches?(4.51).should be_true
+ be_close(5.0, 0.5).matches?(4.51).should be_true
end
it "should not match when value == (target - delta)" do
- BeClose.new(5.0, 0.5).matches?(4.5).should be_false
+ be_close(5.0, 0.5).matches?(4.5).should be_false
end
it "should not match when value < (target - delta)" do
- BeClose.new(5.0, 0.5).matches?(4.49).should be_false
+ be_close(5.0, 0.5).matches?(4.49).should be_false
end
it "should not match when value == (target + delta)" do
- BeClose.new(5.0, 0.5).matches?(5.5).should be_false
+ be_close(5.0, 0.5).matches?(5.5).should be_false
end
it "should not match when value > (target + delta)" do
- BeClose.new(5.0, 0.5).matches?(5.51).should be_false
+ be_close(5.0, 0.5).matches?(5.51).should be_false
end
it "should provide a useful failure message" do
#given
- matcher = BeClose.new(5.0, 0.5)
+ matcher = be_close(5.0, 0.5)
#when
matcher.matches?(5.51)
#then
matcher.failure_message.should == "expected 5.0 +/- (< 0.5), got 5.51"
end
it "should describe itself" do
- BeClose.new(5.0, 0.5).description.should == "be close to 5.0 (within +- 0.5)"
+ matcher = be_close(5.0, 0.5)
+ matcher.matches?(5.1)
+ matcher.description.should == "be close to 5.0 (within +- 0.5)"
end
end
end
Modified: incubator/olio/webapp/rails/trunk/vendor/plugins/rspec/spec/spec/matchers/be_spec.rb
URL: http://svn.apache.org/viewvc/incubator/olio/webapp/rails/trunk/vendor/plugins/rspec/spec/spec/matchers/be_spec.rb?rev=725524&r1=725523&r2=725524&view=diff
==============================================================================
--- incubator/olio/webapp/rails/trunk/vendor/plugins/rspec/spec/spec/matchers/be_spec.rb (original)
+++ incubator/olio/webapp/rails/trunk/vendor/plugins/rspec/spec/spec/matchers/be_spec.rb Wed Dec 10 17:34:18 2008
@@ -7,7 +7,7 @@
end
it "should pass when actual returns true for :predicates? (present tense)" do
- actual = stub("actual", :exists? => true)
+ actual = stub("actual", :exists? => true, :exist? => true)
actual.should be_exist
end
@@ -21,7 +21,23 @@
it "should fail when actual does not respond to :predicate?" do
lambda {
Object.new.should be_happy
- }.should raise_error(NameError)
+ }.should raise_error(NameError, /happy\?/)
+ end
+
+ it "should fail on error other than NameError" do
+ actual = stub("actual")
+ actual.should_receive(:foo?).and_raise("aaaah")
+ lambda {
+ actual.should be_foo
+ }.should raise_error(/aaaah/)
+ end
+
+ it "should fail on error other than NameError (with the present tense predicate)" do
+ actual = Object.new
+ actual.should_receive(:foos?).and_raise("aaaah")
+ lambda {
+ actual.should be_foo
+ }.should raise_error(/aaaah/)
end
end
@@ -121,7 +137,7 @@
it "should fail when actual is not nil" do
lambda {
:not_nil.should be_nil
- }.should fail_with("expected nil, got :not_nil")
+ }.should fail_with("expected nil? to return true, got false")
end
end
@@ -133,7 +149,7 @@
it "should fail when actual is nil" do
lambda {
nil.should_not be_nil
- }.should fail_with("expected not nil, got nil")
+ }.should fail_with("expected nil? to return false, got true")
end
end
@@ -195,7 +211,15 @@
end
it "should fail when === operator returns false" do
- lambda { Hash.should be === "not a hash" }.should fail_with(%[expected === "not a hash", got Hash])
+ lambda { Hash.should be === "not a hash" }.should fail_with(%[expected === not a hash, got Hash])
+ end
+end
+
+describe "should_not with operators" do
+ it "should coach user to stop using operators with should_not" do
+ lambda {
+ 5.should_not be < 6
+ }.should raise_error(/not only FAILED,\nit reads really poorly./m)
end
end
@@ -206,11 +230,11 @@
end
it "should fail if actual is false" do
- lambda {false.should be}.should fail_with("expected if to be satisfied, got false")
+ lambda {false.should be}.should fail_with("expected true, got false")
end
it "should fail if actual is nil" do
- lambda {nil.should be}.should fail_with("expected if to be satisfied, got nil")
+ lambda {nil.should be}.should fail_with("expected true, got nil")
end
end
@@ -223,6 +247,15 @@
end
end
+describe "'should be' with operator" do
+ it "should include 'be' in the description" do
+ (be > 6).description.should =~ /be > 6/
+ (be >= 6).description.should =~ /be >= 6/
+ (be <= 6).description.should =~ /be <= 6/
+ (be < 6).description.should =~ /be < 6/
+ end
+end
+
describe "arbitrary predicate with DelegateClass" do
it "should access methods defined in the delegating class (LH[#48])" do
Modified: incubator/olio/webapp/rails/trunk/vendor/plugins/rspec/spec/spec/matchers/change_spec.rb
URL: http://svn.apache.org/viewvc/incubator/olio/webapp/rails/trunk/vendor/plugins/rspec/spec/spec/matchers/change_spec.rb?rev=725524&r1=725523&r2=725524&view=diff
==============================================================================
--- incubator/olio/webapp/rails/trunk/vendor/plugins/rspec/spec/spec/matchers/change_spec.rb (original)
+++ incubator/olio/webapp/rails/trunk/vendor/plugins/rspec/spec/spec/matchers/change_spec.rb Wed Dec 10 17:34:18 2008
@@ -55,10 +55,9 @@
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 @@
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 @@
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
Modified: incubator/olio/webapp/rails/trunk/vendor/plugins/rspec/spec/spec/matchers/description_generation_spec.rb
URL: http://svn.apache.org/viewvc/incubator/olio/webapp/rails/trunk/vendor/plugins/rspec/spec/spec/matchers/description_generation_spec.rb?rev=725524&r1=725523&r2=725524&view=diff
==============================================================================
--- incubator/olio/webapp/rails/trunk/vendor/plugins/rspec/spec/spec/matchers/description_generation_spec.rb (original)
+++ incubator/olio/webapp/rails/trunk/vendor/plugins/rspec/spec/spec/matchers/description_generation_spec.rb Wed Dec 10 17:34:18 2008
@@ -107,6 +107,11 @@
[1,2,3].should include(3)
Spec::Matchers.generated_description.should == "should include 3"
end
+
+ it "array.should =~ [1,2,3]" do
+ [1,2,3].should =~ [1,2,3]
+ Spec::Matchers.generated_description.should == "should contain exactly 1, 2 and 3"
+ end
it "should match" do
"this string".should match(/this string/)
@@ -130,7 +135,7 @@
it "should respond_to" do
[].should respond_to(:insert)
- Spec::Matchers.generated_description.should == "should respond to #insert"
+ Spec::Matchers.generated_description.should == "should respond to [:insert]"
end
it "should throw symbol" do
@@ -151,3 +156,17 @@
end.new
end
end
+
+describe "a Matcher with no description" do
+ def matcher
+ Class.new do
+ def matches?(ignore); true; end
+ def failure_message; ""; end
+ end.new
+ end
+
+ it "should provide a helpful message when used in a string-less example block" do
+ 5.should matcher
+ Spec::Matchers.generated_description.should =~ /When you call.*description method/m
+ end
+end
Modified: incubator/olio/webapp/rails/trunk/vendor/plugins/rspec/spec/spec/matchers/eql_spec.rb
URL: http://svn.apache.org/viewvc/incubator/olio/webapp/rails/trunk/vendor/plugins/rspec/spec/spec/matchers/eql_spec.rb?rev=725524&r1=725523&r2=725524&view=diff
==============================================================================
--- incubator/olio/webapp/rails/trunk/vendor/plugins/rspec/spec/spec/matchers/eql_spec.rb (original)
+++ incubator/olio/webapp/rails/trunk/vendor/plugins/rspec/spec/spec/matchers/eql_spec.rb Wed Dec 10 17:34:18 2008
@@ -2,24 +2,25 @@
module Spec
module Matchers
- describe Eql do
+ describe "eql" do
it "should match when actual.eql?(expected)" do
- Eql.new(1).matches?(1).should be_true
+ eql(1).matches?(1).should be_true
end
it "should not match when !actual.eql?(expected)" do
- Eql.new(1).matches?(2).should be_false
+ eql(1).matches?(2).should be_false
end
it "should describe itself" do
- matcher = Eql.new(1)
+ matcher = eql(1)
+ matcher.matches?(1)
matcher.description.should == "eql 1"
end
it "should provide message, expected and actual on #failure_message" do
- matcher = Eql.new("1")
+ matcher = eql("1")
matcher.matches?(1)
matcher.failure_message.should == ["expected \"1\", got 1 (using .eql?)", "1", 1]
end
it "should provide message, expected and actual on #negative_failure_message" do
- matcher = Eql.new(1)
+ matcher = eql(1)
matcher.matches?(1)
matcher.negative_failure_message.should == ["expected 1 not to equal 1 (using .eql?)", 1, 1]
end
Modified: incubator/olio/webapp/rails/trunk/vendor/plugins/rspec/spec/spec/matchers/equal_spec.rb
URL: http://svn.apache.org/viewvc/incubator/olio/webapp/rails/trunk/vendor/plugins/rspec/spec/spec/matchers/equal_spec.rb?rev=725524&r1=725523&r2=725524&view=diff
==============================================================================
--- incubator/olio/webapp/rails/trunk/vendor/plugins/rspec/spec/spec/matchers/equal_spec.rb (original)
+++ incubator/olio/webapp/rails/trunk/vendor/plugins/rspec/spec/spec/matchers/equal_spec.rb Wed Dec 10 17:34:18 2008
@@ -2,24 +2,25 @@
module Spec
module Matchers
- describe Equal do
+ describe "equal" do
it "should match when actual.equal?(expected)" do
- Equal.new(1).matches?(1).should be_true
+ equal(1).matches?(1).should be_true
end
it "should not match when !actual.equal?(expected)" do
- Equal.new("1").matches?("1").should be_false
+ equal("1").matches?("1").should be_false
end
it "should describe itself" do
- matcher = Equal.new(1)
+ matcher = equal(1)
+ matcher.matches?(1)
matcher.description.should == "equal 1"
end
it "should provide message, expected and actual on #failure_message" do
- matcher = Equal.new("1")
+ matcher = equal("1")
matcher.matches?(1)
matcher.failure_message.should == ["expected \"1\", got 1 (using .equal?)", "1", 1]
end
it "should provide message, expected and actual on #negative_failure_message" do
- matcher = Equal.new(1)
+ matcher = equal(1)
matcher.matches?(1)
matcher.negative_failure_message.should == ["expected 1 not to equal 1 (using .equal?)", 1, 1]
end
Modified: incubator/olio/webapp/rails/trunk/vendor/plugins/rspec/spec/spec/matchers/handler_spec.rb
URL: http://svn.apache.org/viewvc/incubator/olio/webapp/rails/trunk/vendor/plugins/rspec/spec/spec/matchers/handler_spec.rb?rev=725524&r1=725523&r2=725524&view=diff
==============================================================================
--- incubator/olio/webapp/rails/trunk/vendor/plugins/rspec/spec/spec/matchers/handler_spec.rb (original)
+++ incubator/olio/webapp/rails/trunk/vendor/plugins/rspec/spec/spec/matchers/handler_spec.rb Wed Dec 10 17:34:18 2008
@@ -48,53 +48,73 @@
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)
+ Spec::Expectations::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
+ Spec::Expectations::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)
+ Spec::Expectations::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
+ 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
+ lambda {
+ Spec::Expectations::NegativeExpectationMatcherHandler.handle_matcher(actual, matcher)
+ }.should fail_with(/Matcher does not support should_not.\n/)
+ end
- it "should explain when the matcher parameter is not a matcher" do
- begin
- nonmatcher = mock("nonmatcher")
+ it "should ask the matcher if it matches" do
+ matcher = mock("matcher")
actual = Object.new
- NegativeExpectationMatcherHandler.handle_matcher(actual, nonmatcher)
- rescue Spec::Expectations::InvalidMatcherError => e
+ matcher.stub!(:negative_failure_message)
+ matcher.should_receive(:matches?).with(actual).and_return(false)
+ Spec::Expectations::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
+ Spec::Expectations::NegativeExpectationMatcherHandler.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(false)
+ matcher.stub!(:negative_failure_message).and_return("ignore")
+ Spec::Expectations::NegativeExpectationMatcherHandler.handle_matcher(actual, matcher).should be_false
+ end
end
end
@@ -124,6 +144,7 @@
}.should fail_with(/Matcher does not support should_not.\n/)
end
+
end
end
end
Modified: incubator/olio/webapp/rails/trunk/vendor/plugins/rspec/spec/spec/matchers/has_spec.rb
URL: http://svn.apache.org/viewvc/incubator/olio/webapp/rails/trunk/vendor/plugins/rspec/spec/spec/matchers/has_spec.rb?rev=725524&r1=725523&r2=725524&view=diff
==============================================================================
--- incubator/olio/webapp/rails/trunk/vendor/plugins/rspec/spec/spec/matchers/has_spec.rb (original)
+++ incubator/olio/webapp/rails/trunk/vendor/plugins/rspec/spec/spec/matchers/has_spec.rb Wed Dec 10 17:34:18 2008
@@ -51,3 +51,13 @@
lambda { o.should_not have_sym(:foo) }.should raise_error("Funky exception")
end
end
+
+describe "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
Modified: incubator/olio/webapp/rails/trunk/vendor/plugins/rspec/spec/spec/matchers/have_spec.rb
URL: http://svn.apache.org/viewvc/incubator/olio/webapp/rails/trunk/vendor/plugins/rspec/spec/spec/matchers/have_spec.rb?rev=725524&r1=725523&r2=725524&view=diff
==============================================================================
--- incubator/olio/webapp/rails/trunk/vendor/plugins/rspec/spec/spec/matchers/have_spec.rb (original)
+++ incubator/olio/webapp/rails/trunk/vendor/plugins/rspec/spec/spec/matchers/have_spec.rb Wed Dec 10 17:34:18 2008
@@ -1,6 +1,6 @@
require File.dirname(__FILE__) + '/../../spec_helper.rb'
-module HaveSpecHelper
+share_as :HaveSpecHelper do
def create_collection_owner_with(n)
owner = Spec::Expectations::Helper::CollectionOwner.new
(1..n).each do |n|
@@ -9,8 +9,21 @@
end
owner
end
+ before(:each) do
+ unless defined?(ActiveSupport::Inflector)
+ @active_support_was_not_defined
+ module ActiveSupport
+ class Inflector
+ def self.pluralize(string)
+ string.to_s + 's'
+ end
+ end
+ end
+ end
+ end
end
+
describe "should have(n).items" do
include HaveSpecHelper
@@ -50,13 +63,27 @@
describe 'should have(1).item when ActiveSupport::Inflector is defined' do
include HaveSpecHelper
- before do
- unless defined?(ActiveSupport::Inflector)
- module ActiveSupport
- class Inflector
- def self.pluralize(string)
- string.to_s + 's'
- end
+ it 'should pluralize the collection name' 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
@@ -66,6 +93,12 @@
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,76 @@
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
+ with_ruby '1.8' do
+ Have.private_instance_methods.should include("method_missing")
+ end
+ with_ruby '1.9' do
+ Have.private_instance_methods.should include(:method_missing)
+ end
+ 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
Modified: incubator/olio/webapp/rails/trunk/vendor/plugins/rspec/spec/spec/matchers/include_spec.rb
URL: http://svn.apache.org/viewvc/incubator/olio/webapp/rails/trunk/vendor/plugins/rspec/spec/spec/matchers/include_spec.rb?rev=725524&r1=725523&r2=725524&view=diff
==============================================================================
--- incubator/olio/webapp/rails/trunk/vendor/plugins/rspec/spec/spec/matchers/include_spec.rb (original)
+++ incubator/olio/webapp/rails/trunk/vendor/plugins/rspec/spec/spec/matchers/include_spec.rb Wed Dec 10 17:34:18 2008
@@ -5,6 +5,10 @@
[1,2,3].should include(3)
"abc".should include("a")
end
+
+ it 'should pass if target is a Hash and has the expected as a key' do
+ {:key => 'value'}.should include(:key)
+ end
it "should fail if target does not include expected" do
lambda {
@@ -13,6 +17,9 @@
lambda {
"abc".should include("d")
}.should fail_with("expected \"abc\" to include \"d\"")
+ lambda {
+ {:key => 'value'}.should include(:other)
+ }.should fail_with(%Q|expected {:key=>"value"} to include :other|)
end
end
@@ -20,12 +27,22 @@
it "should pass if target includes all items" do
[1,2,3].should include(1,2,3)
end
+
+ it 'should pass if target is a Hash including all items as keys' do
+ {:key => 'value', :other => 'value'}.should include(:key, :other)
+ end
it "should fail if target does not include any one of the items" do
lambda {
[1,2,3].should include(1,2,4)
}.should fail_with("expected [1, 2, 3] to include 1, 2 and 4")
end
+
+ it 'should pass if target is a Hash missing any item as a key' do
+ lambda {
+ {:key => 'value'}.should include(:key, :other)
+ }.should fail_with(%Q|expected {:key=>"value"} to include :key and :other|)
+ end
end
describe "should_not include(expected)" do
@@ -33,6 +50,10 @@
[1,2,3].should_not include(4)
"abc".should_not include("d")
end
+
+ it 'should pass if target is a Hash and does not have the expected as a key' do
+ {:other => 'value'}.should_not include(:key)
+ end
it "should fail if target includes expected" do
lambda {
@@ -41,5 +62,27 @@
lambda {
"abc".should_not include("c")
}.should fail_with("expected \"abc\" not to include \"c\"")
+ lambda {
+ {:key => 'value'}.should_not include(:key)
+ }.should fail_with(%Q|expected {:key=>"value"} not to include :key|)
+ end
+end
+
+describe "should include(:key => value)" do
+ it "should pass if target is a Hash and includes the key/value pair" do
+ {:key => 'value'}.should include(:key => 'value')
+ end
+ it "should pass if target is a Hash and includes the key/value pair among others" do
+ {:key => 'value', :other => 'different'}.should include(:key => 'value')
+ end
+ it "should fail if target is a Hash and has a different value for key" do
+ lambda {
+ {:key => 'different'}.should include(:key => 'value')
+ }.should fail_with(%Q|expected {:key=>"different"} to include {:key=>"value"}|)
+ end
+ it "should fail if target is a Hash and has a different key" do
+ lambda {
+ {:other => 'value'}.should include(:key => 'value')
+ }.should fail_with(%Q|expected {:other=>"value"} to include {:key=>"value"}|)
end
end
Added: incubator/olio/webapp/rails/trunk/vendor/plugins/rspec/spec/spec/matchers/match_array_spec.rb
URL: http://svn.apache.org/viewvc/incubator/olio/webapp/rails/trunk/vendor/plugins/rspec/spec/spec/matchers/match_array_spec.rb?rev=725524&view=auto
==============================================================================
--- incubator/olio/webapp/rails/trunk/vendor/plugins/rspec/spec/spec/matchers/match_array_spec.rb (added)
+++ incubator/olio/webapp/rails/trunk/vendor/plugins/rspec/spec/spec/matchers/match_array_spec.rb Wed Dec 10 17:34:18 2008
@@ -0,0 +1,83 @@
+require File.dirname(__FILE__) + '/../../spec_helper.rb'
+
+describe "array.should =~ other_array" do
+ it "should pass if target contains all items" do
+ [1,2,3].should =~ [1,2,3]
+ end
+
+ it "should pass if target contains all items out of order" do
+ [1,3,2].should =~ [1,2,3]
+ end
+
+ it "should fail if target includes extra items" do
+ lambda {
+ [1,2,3,4].should =~ [1,2,3]
+ }.should fail_with(<<-MESSAGE)
+expected collection contained: [1, 2, 3]
+actual collection contained: [1, 2, 3, 4]
+the extra elements were: [4]
+MESSAGE
+ end
+
+ it "should fail if target is missing items" do
+ lambda {
+ [1,2].should =~ [1,2,3]
+ }.should fail_with(<<-MESSAGE)
+expected collection contained: [1, 2, 3]
+actual collection contained: [1, 2]
+the missing elements were: [3]
+MESSAGE
+ end
+
+ it "should fail if target is missing items and has extra items" do
+
+ lambda {
+ [1,2,4].should =~ [1,2,3]
+ }.should fail_with(<<-MESSAGE)
+expected collection contained: [1, 2, 3]
+actual collection contained: [1, 2, 4]
+the missing elements were: [3]
+the extra elements were: [4]
+MESSAGE
+ end
+
+ it "should sort items in the error message" do
+ lambda {
+ [6,2,1,5].should =~ [4,1,2,3]
+ }.should fail_with(<<-MESSAGE)
+expected collection contained: [1, 2, 3, 4]
+actual collection contained: [1, 2, 5, 6]
+the missing elements were: [3, 4]
+the extra elements were: [5, 6]
+MESSAGE
+ end
+
+ it "should accurately report extra elements when there are duplicates" do
+ lambda {
+ [1,1,1,5].should =~ [1,5]
+ }.should fail_with(<<-MESSAGE)
+expected collection contained: [1, 5]
+actual collection contained: [1, 1, 1, 5]
+the extra elements were: [1, 1]
+MESSAGE
+ end
+
+ it "should accurately report missing elements when there are duplicates" do
+ lambda {
+ [1,5].should =~ [1,1,5]
+ }.should fail_with(<<-MESSAGE)
+expected collection contained: [1, 1, 5]
+actual collection contained: [1, 5]
+the missing elements were: [1]
+MESSAGE
+ end
+
+end
+
+describe "should_not =~ [:with, :multiple, :args]" do
+ it "should not be supported" do
+ lambda {
+ [1,2,3].should_not =~ [1,2,3]
+ }.should fail_with(/Matcher does not support should_not/)
+ end
+end
Modified: incubator/olio/webapp/rails/trunk/vendor/plugins/rspec/spec/spec/matchers/matcher_methods_spec.rb
URL: http://svn.apache.org/viewvc/incubator/olio/webapp/rails/trunk/vendor/plugins/rspec/spec/spec/matchers/matcher_methods_spec.rb?rev=725524&r1=725523&r2=725524&view=diff
==============================================================================
--- incubator/olio/webapp/rails/trunk/vendor/plugins/rspec/spec/spec/matchers/matcher_methods_spec.rb (original)
+++ incubator/olio/webapp/rails/trunk/vendor/plugins/rspec/spec/spec/matchers/matcher_methods_spec.rb Wed Dec 10 17:34:18 2008
@@ -16,18 +16,9 @@
it "be_arbitrary_predicate" do
be_arbitrary_predicate.should be_an_instance_of(Be)
end
- it "be_close" do
- be_close(1,2).should be_an_instance_of(BeClose)
- end
it "change" do
change("target", :message).should be_an_instance_of(Change)
end
- it "eql" do
- eql(:expected).should be_an_instance_of(Eql)
- end
- it "equal" do
- equal(:expected).should be_an_instance_of(Equal)
- end
it "have" do
have(0).should be_an_instance_of(Have)
end
@@ -43,9 +34,6 @@
it "include" do
include(:value).should be_an_instance_of(Include)
end
- it "match" do
- match(:value).should be_an_instance_of(Match)
- end
it "raise_error" do
raise_error.should be_an_instance_of(RaiseError)
raise_error(NoMethodError).should be_an_instance_of(RaiseError)
@@ -70,7 +58,7 @@
end
it "should convert have_xyz to Has(:have_xyz)" do
- Has.should_receive(:new).with(:have_whatever)
+ self.should_receive(:has).with(:have_whatever)
have_whatever
end
end
Modified: incubator/olio/webapp/rails/trunk/vendor/plugins/rspec/spec/spec/matchers/operator_matcher_spec.rb
URL: http://svn.apache.org/viewvc/incubator/olio/webapp/rails/trunk/vendor/plugins/rspec/spec/spec/matchers/operator_matcher_spec.rb?rev=725524&r1=725523&r2=725524&view=diff
==============================================================================
--- incubator/olio/webapp/rails/trunk/vendor/plugins/rspec/spec/spec/matchers/operator_matcher_spec.rb (original)
+++ incubator/olio/webapp/rails/trunk/vendor/plugins/rspec/spec/spec/matchers/operator_matcher_spec.rb Wed Dec 10 17:34:18 2008
@@ -10,12 +10,17 @@
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 @@
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 @@
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
Modified: incubator/olio/webapp/rails/trunk/vendor/plugins/rspec/spec/spec/matchers/raise_error_spec.rb
URL: http://svn.apache.org/viewvc/incubator/olio/webapp/rails/trunk/vendor/plugins/rspec/spec/spec/matchers/raise_error_spec.rb?rev=725524&r1=725523&r2=725524&view=diff
==============================================================================
--- incubator/olio/webapp/rails/trunk/vendor/plugins/rspec/spec/spec/matchers/raise_error_spec.rb (original)
+++ incubator/olio/webapp/rails/trunk/vendor/plugins/rspec/spec/spec/matchers/raise_error_spec.rb Wed Dec 10 17:34:18 2008
@@ -12,6 +12,24 @@
end
end
+describe "should raise_error {|err| ... }" do
+ it "passes if there is an error" do
+ ran = false
+ lambda { non_existent_method }.should raise_error {|e|
+ ran = true
+ }
+ ran.should be_true
+ end
+
+ it "passes the error to the block" do
+ error = nil
+ lambda { non_existent_method }.should raise_error {|e|
+ error = e
+ }
+ error.should be_an_instance_of(NameError)
+ end
+end
+
describe "should_not raise_error" do
it "should pass if nothing is raised" do
lambda {}.should_not raise_error
Modified: incubator/olio/webapp/rails/trunk/vendor/plugins/rspec/spec/spec/matchers/respond_to_spec.rb
URL: http://svn.apache.org/viewvc/incubator/olio/webapp/rails/trunk/vendor/plugins/rspec/spec/spec/matchers/respond_to_spec.rb?rev=725524&r1=725523&r2=725524&view=diff
==============================================================================
--- incubator/olio/webapp/rails/trunk/vendor/plugins/rspec/spec/spec/matchers/respond_to_spec.rb (original)
+++ incubator/olio/webapp/rails/trunk/vendor/plugins/rspec/spec/spec/matchers/respond_to_spec.rb Wed Dec 10 17:34:18 2008
@@ -8,8 +8,8 @@
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 @@
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 @@
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
Modified: incubator/olio/webapp/rails/trunk/vendor/plugins/rspec/spec/spec/matchers/simple_matcher_spec.rb
URL: http://svn.apache.org/viewvc/incubator/olio/webapp/rails/trunk/vendor/plugins/rspec/spec/spec/matchers/simple_matcher_spec.rb?rev=725524&r1=725523&r2=725524&view=diff
==============================================================================
--- incubator/olio/webapp/rails/trunk/vendor/plugins/rspec/spec/spec/matchers/simple_matcher_spec.rb (original)
+++ incubator/olio/webapp/rails/trunk/vendor/plugins/rspec/spec/spec/matchers/simple_matcher_spec.rb Wed Dec 10 17:34:18 2008
@@ -3,7 +3,7 @@
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 @@
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
\ No newline at end of file
Modified: incubator/olio/webapp/rails/trunk/vendor/plugins/rspec/spec/spec/matchers/throw_symbol_spec.rb
URL: http://svn.apache.org/viewvc/incubator/olio/webapp/rails/trunk/vendor/plugins/rspec/spec/spec/matchers/throw_symbol_spec.rb?rev=725524&r1=725523&r2=725524&view=diff
==============================================================================
--- incubator/olio/webapp/rails/trunk/vendor/plugins/rspec/spec/spec/matchers/throw_symbol_spec.rb (original)
+++ incubator/olio/webapp/rails/trunk/vendor/plugins/rspec/spec/spec/matchers/throw_symbol_spec.rb Wed Dec 10 17:34:18 2008
@@ -2,52 +2,94 @@
module Spec
module Matchers
- describe ThrowSymbol, "(constructed with no Symbol)" do
- before(:each) { @matcher = ThrowSymbol.new }
-
- it "should match if any Symbol is thrown" do
- @matcher.matches?(lambda{ throw :sym }).should be_true
- end
- it "should not match if no Symbol is thrown" do
- @matcher.matches?(lambda{ }).should be_false
- end
- it "should provide a failure message" do
- @matcher.matches?(lambda{})
- @matcher.failure_message.should == "expected a Symbol but nothing was thrown"
- end
- it "should provide a negative failure message" do
- @matcher.matches?(lambda{ throw :sym})
- @matcher.negative_failure_message.should == "expected no Symbol, got :sym"
- end
- end
-
- describe ThrowSymbol, "(constructed with a Symbol)" do
- before(:each) { @matcher = ThrowSymbol.new(:sym) }
+ describe ThrowSymbol do
+ describe "with no args" do
+ before(:each) { @matcher = ThrowSymbol.new }
- it "should match if correct Symbol is thrown" do
- @matcher.matches?(lambda{ throw :sym }).should be_true
- end
- it "should not match if no Symbol is thrown" do
- @matcher.matches?(lambda{ }).should be_false
- end
- it "should not match if correct Symbol is thrown" do
- @matcher.matches?(lambda{ throw :other_sym }).should be_false
- @matcher.failure_message.should == "expected :sym, got :other_sym"
- end
- it "should provide a failure message when no Symbol is thrown" do
- @matcher.matches?(lambda{})
- @matcher.failure_message.should == "expected :sym but nothing was thrown"
- end
- it "should provide a failure message when wrong Symbol is thrown" do
- @matcher.matches?(lambda{ throw :other_sym })
- @matcher.failure_message.should == "expected :sym, got :other_sym"
- end
- it "should provide a negative failure message" do
- @matcher.matches?(lambda{ throw :sym })
- @matcher.negative_failure_message.should == "expected :sym not to be thrown"
+ it "should match if any Symbol is thrown" do
+ @matcher.matches?(lambda{ throw :sym }).should be_true
+ end
+ it "should match if any Symbol is thrown with an arg" do
+ @matcher.matches?(lambda{ throw :sym, "argument" }).should be_true
+ end
+ it "should not match if no Symbol is thrown" do
+ @matcher.matches?(lambda{ }).should be_false
+ end
+ it "should provide a failure message" do
+ @matcher.matches?(lambda{})
+ @matcher.failure_message.should == "expected a Symbol but nothing was thrown"
+ end
+ it "should provide a negative failure message" do
+ @matcher.matches?(lambda{ throw :sym})
+ @matcher.negative_failure_message.should == "expected no Symbol, got :sym"
+ end
+ end
+
+ describe "with a symbol" do
+ before(:each) { @matcher = ThrowSymbol.new(:sym) }
+
+ it "should match if correct Symbol is thrown" do
+ @matcher.matches?(lambda{ throw :sym }).should be_true
+ end
+ it "should match if correct Symbol is thrown with an arg" do
+ @matcher.matches?(lambda{ throw :sym, "argument" }).should be_true
+ end
+ it "should not match if no Symbol is thrown" do
+ @matcher.matches?(lambda{ }).should be_false
+ end
+ it "should not match if correct Symbol is thrown" do
+ @matcher.matches?(lambda{ throw :other_sym }).should be_false
+ end
+ it "should provide a failure message when no Symbol is thrown" do
+ @matcher.matches?(lambda{})
+ @matcher.failure_message.should == "expected :sym but nothing was thrown"
+ end
+ it "should provide a failure message when wrong Symbol is thrown" do
+ @matcher.matches?(lambda{ throw :other_sym })
+ @matcher.failure_message.should == "expected :sym, got :other_sym"
+ end
+ it "should provide a negative failure message" do
+ @matcher.matches?(lambda{ throw :sym })
+ @matcher.negative_failure_message.should == "expected :sym not to be thrown"
+ end
+ it "should only match NameErrors raised by uncaught throws" do
+ @matcher.matches?(lambda{ sym }).should be_false
+ end
end
- it "should only match NameErrors raised by uncaught throws" do
- @matcher.matches?(lambda{ sym }).should be_false
+
+ describe "with a symbol and an arg" do
+ before(:each) { @matcher = ThrowSymbol.new(:sym, "a") }
+
+ it "should match if correct Symbol and args are thrown" do
+ @matcher.matches?(lambda{ throw :sym, "a" }).should be_true
+ end
+ it "should not match if nothing is thrown" do
+ @matcher.matches?(lambda{ }).should be_false
+ end
+ it "should not match if other Symbol is thrown" do
+ @matcher.matches?(lambda{ throw :other_sym, "a" }).should be_false
+ end
+ it "should not match if no arg is thrown" do
+ @matcher.matches?(lambda{ throw :sym }).should be_false
+ end
+ it "should not match if wrong arg is thrown" do
+ @matcher.matches?(lambda{ throw :sym, "b" }).should be_false
+ end
+ it "should provide a failure message when no Symbol is thrown" do
+ @matcher.matches?(lambda{})
+ @matcher.failure_message.should == %q[expected :sym with "a" but nothing was thrown]
+ end
+ it "should provide a failure message when wrong Symbol is thrown" do
+ @matcher.matches?(lambda{ throw :other_sym })
+ @matcher.failure_message.should == %q[expected :sym with "a", got :other_sym]
+ end
+ it "should provide a negative failure message" do
+ @matcher.matches?(lambda{ throw :sym })
+ @matcher.negative_failure_message.should == %q[expected :sym with "a" not to be thrown]
+ end
+ it "should only match NameErrors raised by uncaught throws" do
+ @matcher.matches?(lambda{ sym }).should be_false
+ end
end
end
end
Modified: incubator/olio/webapp/rails/trunk/vendor/plugins/rspec/spec/spec/mocks/any_number_of_times_spec.rb
URL: http://svn.apache.org/viewvc/incubator/olio/webapp/rails/trunk/vendor/plugins/rspec/spec/spec/mocks/any_number_of_times_spec.rb?rev=725524&r1=725523&r2=725524&view=diff
==============================================================================
--- incubator/olio/webapp/rails/trunk/vendor/plugins/rspec/spec/spec/mocks/any_number_of_times_spec.rb (original)
+++ incubator/olio/webapp/rails/trunk/vendor/plugins/rspec/spec/spec/mocks/any_number_of_times_spec.rb Wed Dec 10 17:34:18 2008
@@ -23,6 +23,13 @@
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
Modified: incubator/olio/webapp/rails/trunk/vendor/plugins/rspec/spec/spec/mocks/bug_report_11545_spec.rb
URL: http://svn.apache.org/viewvc/incubator/olio/webapp/rails/trunk/vendor/plugins/rspec/spec/spec/mocks/bug_report_11545_spec.rb?rev=725524&r1=725523&r2=725524&view=diff
==============================================================================
--- incubator/olio/webapp/rails/trunk/vendor/plugins/rspec/spec/spec/mocks/bug_report_11545_spec.rb (original)
+++ incubator/olio/webapp/rails/trunk/vendor/plugins/rspec/spec/spec/mocks/bug_report_11545_spec.rb Wed Dec 10 17:34:18 2008
@@ -1,13 +1,11 @@
require File.dirname(__FILE__) + '/../../spec_helper.rb'
class LiarLiarPantsOnFire
- include Spec::MetaClass
- extend Spec::MetaClass
- def respond_to?(sym)
+ def respond_to?(sym, incl_private=false)
true
end
- def self.respond_to?(sym)
+ def self.respond_to?(sym, incl_private=false)
true
end
end
@@ -28,6 +26,7 @@
end
it 'should cleanup after itself' do
- LiarLiarPantsOnFire.metaclass.instance_methods.should_not include("something")
+ (class << LiarLiarPantsOnFire; self; end).instance_methods.should_not include("something")
end
end
+
Added: incubator/olio/webapp/rails/trunk/vendor/plugins/rspec/spec/spec/mocks/bug_report_496.rb
URL: http://svn.apache.org/viewvc/incubator/olio/webapp/rails/trunk/vendor/plugins/rspec/spec/spec/mocks/bug_report_496.rb?rev=725524&view=auto
==============================================================================
--- incubator/olio/webapp/rails/trunk/vendor/plugins/rspec/spec/spec/mocks/bug_report_496.rb (added)
+++ incubator/olio/webapp/rails/trunk/vendor/plugins/rspec/spec/spec/mocks/bug_report_496.rb Wed Dec 10 17:34:18 2008
@@ -0,0 +1,19 @@
+require File.dirname(__FILE__) + '/../../spec_helper.rb'
+
+module BugReport496
+ 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/tickets/496") do
+ BaseClass.should_receive(:new).once
+ SubClass.new
+ end
+ end
+ end
+end
+
Added: incubator/olio/webapp/rails/trunk/vendor/plugins/rspec/spec/spec/mocks/bug_report_600_spec.rb
URL: http://svn.apache.org/viewvc/incubator/olio/webapp/rails/trunk/vendor/plugins/rspec/spec/spec/mocks/bug_report_600_spec.rb?rev=725524&view=auto
==============================================================================
--- incubator/olio/webapp/rails/trunk/vendor/plugins/rspec/spec/spec/mocks/bug_report_600_spec.rb (added)
+++ incubator/olio/webapp/rails/trunk/vendor/plugins/rspec/spec/spec/mocks/bug_report_600_spec.rb Wed Dec 10 17:34:18 2008
@@ -0,0 +1,22 @@
+require File.dirname(__FILE__) + '/../../spec_helper.rb'
+
+module BugReport600
+ class ExampleClass
+ def self.method_that_uses_define_method
+ define_method "defined_method" do |attributes|
+ load_address(address, attributes)
+ end
+ end
+ end
+
+ describe "stubbing a class method" do
+ it "should work" do
+ ExampleClass.should_receive(:define_method).with("defined_method")
+ ExampleClass.method_that_uses_define_method
+ end
+
+ it "should restore the original method" do
+ ExampleClass.method_that_uses_define_method
+ end
+ end
+end
\ No newline at end of file
Modified: incubator/olio/webapp/rails/trunk/vendor/plugins/rspec/spec/spec/mocks/failing_mock_argument_constraints_spec.rb
URL: http://svn.apache.org/viewvc/incubator/olio/webapp/rails/trunk/vendor/plugins/rspec/spec/spec/mocks/failing_mock_argument_constraints_spec.rb?rev=725524&r1=725523&r2=725524&view=diff
==============================================================================
--- incubator/olio/webapp/rails/trunk/vendor/plugins/rspec/spec/spec/mocks/failing_mock_argument_constraints_spec.rb (original)
+++ incubator/olio/webapp/rails/trunk/vendor/plugins/rspec/spec/spec/mocks/failing_mock_argument_constraints_spec.rb Wed Dec 10 17:34:18 2008
@@ -91,40 +91,5 @@
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
Modified: incubator/olio/webapp/rails/trunk/vendor/plugins/rspec/spec/spec/mocks/hash_including_matcher_spec.rb
URL: http://svn.apache.org/viewvc/incubator/olio/webapp/rails/trunk/vendor/plugins/rspec/spec/spec/mocks/hash_including_matcher_spec.rb?rev=725524&r1=725523&r2=725524&view=diff
==============================================================================
--- incubator/olio/webapp/rails/trunk/vendor/plugins/rspec/spec/spec/mocks/hash_including_matcher_spec.rb (original)
+++ incubator/olio/webapp/rails/trunk/vendor/plugins/rspec/spec/spec/mocks/hash_including_matcher_spec.rb Wed Dec 10 17:34:18 2008
@@ -2,31 +2,52 @@
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
\ No newline at end of file
+ end
+end
Modified: incubator/olio/webapp/rails/trunk/vendor/plugins/rspec/spec/spec/mocks/mock_spec.rb
URL: http://svn.apache.org/viewvc/incubator/olio/webapp/rails/trunk/vendor/plugins/rspec/spec/spec/mocks/mock_spec.rb?rev=725524&r1=725523&r2=725524&view=diff
==============================================================================
--- incubator/olio/webapp/rails/trunk/vendor/plugins/rspec/spec/spec/mocks/mock_spec.rb (original)
+++ incubator/olio/webapp/rails/trunk/vendor/plugins/rspec/spec/spec/mocks/mock_spec.rb Wed Dec 10 17:34:18 2008
@@ -3,7 +3,6 @@
module Spec
module Mocks
describe Mock do
-
before(:each) do
@mock = mock("test mock")
end
@@ -23,6 +22,18 @@
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
@@ -215,7 +226,7 @@
it "should yield 0 args to blocks that take a variable number of arguments" do
@mock.should_receive(:yield_back).with(no_args()).once.and_yield
a = nil
- @mock.yield_back {|*a|}
+ @mock.yield_back {|*x| a = x}
a.should == []
@mock.rspec_verify
end
@@ -233,7 +244,7 @@
it "should yield one arg to blocks that take a variable number of arguments" do
@mock.should_receive(:yield_back).with(no_args()).once.and_yield(99)
a = nil
- @mock.yield_back {|*a|}
+ @mock.yield_back {|*x| a = x}
a.should == [99]
@mock.rspec_verify
end
@@ -252,7 +263,7 @@
it "should yield many args to blocks that take a variable number of arguments" do
@mock.should_receive(:yield_back).with(no_args()).once.and_yield(99, 27, "go")
a = nil
- @mock.yield_back {|*a|}
+ @mock.yield_back {|*x| a = x}
a.should == [99, 27, "go"]
@mock.rspec_verify
end
@@ -271,7 +282,7 @@
it "should yield single value" do
@mock.should_receive(:yield_back).with(no_args()).once.and_yield(99)
a = nil
- @mock.yield_back {|a|}
+ @mock.yield_back {|x| a = x}
a.should == 99
@mock.rspec_verify
end
@@ -290,7 +301,7 @@
it "should yield two values" do
@mock.should_receive(:yield_back).with(no_args()).once.and_yield('wha', 'zup')
a, b = nil
- @mock.yield_back {|a,b|}
+ @mock.yield_back {|x,y| a=x; b=y}
a.should == 'wha'
b.should == 'zup'
@mock.rspec_verify
@@ -403,7 +414,22 @@
@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 +439,32 @@
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 +490,15 @@
@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 }
Added: incubator/olio/webapp/rails/trunk/vendor/plugins/rspec/spec/spec/mocks/nil_expectation_warning_spec.rb
URL: http://svn.apache.org/viewvc/incubator/olio/webapp/rails/trunk/vendor/plugins/rspec/spec/spec/mocks/nil_expectation_warning_spec.rb?rev=725524&view=auto
==============================================================================
--- incubator/olio/webapp/rails/trunk/vendor/plugins/rspec/spec/spec/mocks/nil_expectation_warning_spec.rb (added)
+++ incubator/olio/webapp/rails/trunk/vendor/plugins/rspec/spec/spec/mocks/nil_expectation_warning_spec.rb Wed Dec 10 17:34:18 2008
@@ -0,0 +1,53 @@
+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
+
+ 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
Modified: incubator/olio/webapp/rails/trunk/vendor/plugins/rspec/spec/spec/mocks/null_object_mock_spec.rb
URL: http://svn.apache.org/viewvc/incubator/olio/webapp/rails/trunk/vendor/plugins/rspec/spec/spec/mocks/null_object_mock_spec.rb?rev=725524&r1=725523&r2=725524&view=diff
==============================================================================
--- incubator/olio/webapp/rails/trunk/vendor/plugins/rspec/spec/spec/mocks/null_object_mock_spec.rb (original)
+++ incubator/olio/webapp/rails/trunk/vendor/plugins/rspec/spec/spec/mocks/null_object_mock_spec.rb Wed Dec 10 17:34:18 2008
@@ -36,5 +36,19 @@
@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
Modified: incubator/olio/webapp/rails/trunk/vendor/plugins/rspec/spec/spec/mocks/options_hash_spec.rb
URL: http://svn.apache.org/viewvc/incubator/olio/webapp/rails/trunk/vendor/plugins/rspec/spec/spec/mocks/options_hash_spec.rb?rev=725524&r1=725523&r2=725524&view=diff
==============================================================================
--- incubator/olio/webapp/rails/trunk/vendor/plugins/rspec/spec/spec/mocks/options_hash_spec.rb (original)
+++ incubator/olio/webapp/rails/trunk/vendor/plugins/rspec/spec/spec/mocks/options_hash_spec.rb Wed Dec 10 17:34:18 2008
@@ -3,42 +3,32 @@
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
Modified: incubator/olio/webapp/rails/trunk/vendor/plugins/rspec/spec/spec/mocks/partial_mock_spec.rb
URL: http://svn.apache.org/viewvc/incubator/olio/webapp/rails/trunk/vendor/plugins/rspec/spec/spec/mocks/partial_mock_spec.rb?rev=725524&r1=725523&r2=725524&view=diff
==============================================================================
--- incubator/olio/webapp/rails/trunk/vendor/plugins/rspec/spec/spec/mocks/partial_mock_spec.rb (original)
+++ incubator/olio/webapp/rails/trunk/vendor/plugins/rspec/spec/spec/mocks/partial_mock_spec.rb Wed Dec 10 17:34:18 2008
@@ -11,7 +11,14 @@
@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 @@
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 @@
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 @@
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
Modified: incubator/olio/webapp/rails/trunk/vendor/plugins/rspec/spec/spec/mocks/passing_mock_argument_constraints_spec.rb
URL: http://svn.apache.org/viewvc/incubator/olio/webapp/rails/trunk/vendor/plugins/rspec/spec/spec/mocks/passing_mock_argument_constraints_spec.rb?rev=725524&r1=725523&r2=725524&view=diff
==============================================================================
--- incubator/olio/webapp/rails/trunk/vendor/plugins/rspec/spec/spec/mocks/passing_mock_argument_constraints_spec.rb (original)
+++ incubator/olio/webapp/rails/trunk/vendor/plugins/rspec/spec/spec/mocks/passing_mock_argument_constraints_spec.rb Wed Dec 10 17:34:18 2008
@@ -13,50 +13,6 @@
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 @@
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 @@
@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
Modified: incubator/olio/webapp/rails/trunk/vendor/plugins/rspec/spec/spec/mocks/stub_spec.rb
URL: http://svn.apache.org/viewvc/incubator/olio/webapp/rails/trunk/vendor/plugins/rspec/spec/spec/mocks/stub_spec.rb?rev=725524&r1=725523&r2=725524&view=diff
==============================================================================
--- incubator/olio/webapp/rails/trunk/vendor/plugins/rspec/spec/spec/mocks/stub_spec.rb (original)
+++ incubator/olio/webapp/rails/trunk/vendor/plugins/rspec/spec/spec/mocks/stub_spec.rb Wed Dec 10 17:34:18 2008
@@ -14,6 +14,7 @@
end
end
@instance = @class.new
+ @stub = Object.new
end
it "should return expected value when expected message is received" do
@@ -44,6 +45,12 @@
@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)
Modified: incubator/olio/webapp/rails/trunk/vendor/plugins/rspec/spec/spec/package/bin_spec_spec.rb
URL: http://svn.apache.org/viewvc/incubator/olio/webapp/rails/trunk/vendor/plugins/rspec/spec/spec/package/bin_spec_spec.rb?rev=725524&r1=725523&r2=725524&view=diff
==============================================================================
--- incubator/olio/webapp/rails/trunk/vendor/plugins/rspec/spec/spec/package/bin_spec_spec.rb (original)
+++ incubator/olio/webapp/rails/trunk/vendor/plugins/rspec/spec/spec/package/bin_spec_spec.rb Wed Dec 10 17:34:18 2008
@@ -11,4 +11,12 @@
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