rspec 0.6.4 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/CHANGES +90 -1
- data/EXAMPLES.rd +28 -6
- data/MIT-LICENSE +20 -0
- data/README +18 -12
- data/Rakefile +60 -54
- data/examples/custom_formatter.rb +4 -4
- data/examples/helper_method_example.rb +11 -0
- data/examples/mocking_example.rb +19 -2
- data/examples/partial_mock_example.rb +28 -0
- data/examples/stack_spec.rb +8 -8
- data/examples/stubbing_example.rb +50 -9
- data/examples/test_case_spec.rb +6 -6
- data/lib/spec.rb +1 -2
- data/lib/spec/callback.rb +0 -0
- data/lib/spec/expectations.rb +3 -6
- data/lib/spec/expectations/diff.rb +23 -47
- data/lib/spec/expectations/differs/default.rb +62 -0
- data/lib/spec/expectations/{exceptions.rb → errors.rb} +0 -0
- data/lib/spec/expectations/extensions.rb +4 -0
- data/lib/spec/expectations/extensions/inspect_for_expectation_not_met_error.rb +14 -0
- data/lib/spec/expectations/extensions/numeric.rb +5 -0
- data/lib/spec/expectations/{expectations.rb → extensions/object.rb} +3 -6
- data/lib/spec/expectations/extensions/symbol.rb +5 -0
- data/lib/spec/expectations/should.rb +4 -0
- data/lib/spec/expectations/should/base.rb +42 -0
- data/lib/spec/expectations/should/have.rb +79 -0
- data/lib/spec/expectations/should/not.rb +72 -0
- data/lib/spec/expectations/should/should.rb +83 -0
- data/lib/spec/expectations/sugar.rb +6 -25
- data/lib/spec/mocks.rb +5 -1
- data/lib/spec/mocks/argument_expectation.rb +15 -1
- data/lib/spec/mocks/error_generator.rb +72 -0
- data/lib/spec/mocks/{exceptions.rb → errors.rb} +0 -0
- data/lib/spec/mocks/extensions/object.rb +3 -0
- data/lib/spec/mocks/message_expectation.rb +80 -73
- data/lib/spec/mocks/mock.rb +4 -69
- data/lib/spec/mocks/mock_handler.rb +158 -0
- data/lib/spec/mocks/mock_methods.rb +44 -0
- data/lib/spec/mocks/order_group.rb +10 -2
- data/lib/spec/rake/spectask.rb +20 -18
- data/lib/spec/rake/{rcov_verify.rb → verify_rcov.rb} +2 -2
- data/lib/spec/runner.rb +3 -1
- data/lib/spec/runner/backtrace_tweaker.rb +2 -1
- data/lib/spec/runner/context.rb +10 -16
- data/lib/spec/runner/context_eval.rb +40 -40
- data/lib/spec/runner/execution_context.rb +1 -12
- data/lib/spec/runner/{kernel_ext.rb → extensions/kernel.rb} +2 -2
- data/lib/spec/runner/{instance_exec.rb → extensions/object.rb} +0 -0
- data/lib/spec/runner/formatter/base_text_formatter.rb +25 -18
- data/lib/spec/runner/formatter/html_formatter.rb +81 -101
- data/lib/spec/runner/formatter/progress_bar_formatter.rb +9 -9
- data/lib/spec/runner/formatter/rdoc_formatter.rb +6 -6
- data/lib/spec/runner/formatter/specdoc_formatter.rb +7 -6
- data/lib/spec/runner/option_parser.rb +41 -5
- data/lib/spec/runner/reporter.rb +3 -15
- data/lib/spec/runner/spec_should_raise_handler.rb +74 -0
- data/lib/spec/runner/specification.rb +33 -14
- data/lib/spec/version.rb +6 -3
- data/vendor/watir/README.txt +1 -1
- metadata +34 -68
- data/bin/test2spec +0 -112
- data/examples/helper_method_spec.rb +0 -12
- data/lib/spec/expectations/have_helper.rb +0 -41
- data/lib/spec/expectations/helper.rb +0 -4
- data/lib/spec/expectations/should_base.rb +0 -52
- data/lib/spec/expectations/should_helper.rb +0 -93
- data/lib/spec/expectations/should_negator.rb +0 -71
- data/lib/spec/test_to_spec/ruby2ruby.rb +0 -492
- data/lib/spec/test_to_spec/sexp_transformer.rb +0 -196
- data/lib/spec/test_to_spec/test_case_ext.rb +0 -22
- data/lib/spec/test_to_spec/translation_test_runner.rb +0 -147
- data/test/spec/expectations/arbitrary_operator_test.rb +0 -55
- data/test/spec/expectations/arbitrary_predicate_test.rb +0 -163
- data/test/spec/expectations/containment_test.rb +0 -129
- data/test/spec/expectations/diff_test.rb +0 -62
- data/test/spec/expectations/identity_test.rb +0 -75
- data/test/spec/expectations/object_equality_test.rb +0 -65
- data/test/spec/expectations/raising_test.rb +0 -106
- data/test/spec/expectations/regex_matching_test.rb +0 -36
- data/test/spec/expectations/should_have_test.rb +0 -169
- data/test/spec/expectations/should_satisfy_test.rb +0 -37
- data/test/spec/expectations/sugar_test.rb +0 -93
- data/test/spec/expectations/supported_symbols_test.rb +0 -33
- data/test/spec/expectations/throwing_test.rb +0 -55
- data/test/spec/expectations/true_false_special_case_test.rb +0 -85
- data/test/spec/expectations/typing_test.rb +0 -108
- data/test/spec/mocks/mock_arg_constraints_test.rb +0 -113
- data/test/spec/mocks/mock_counts_test.rb +0 -431
- data/test/spec/mocks/mock_ordering_test.rb +0 -109
- data/test/spec/mocks/mock_test.rb +0 -220
- data/test/spec/mocks/null_object_test.rb +0 -37
- data/test/spec/runner/backtrace_tweaker_test.rb +0 -90
- data/test/spec/runner/context_matching_test.rb +0 -35
- data/test/spec/runner/context_runner_test.rb +0 -62
- data/test/spec/runner/context_test.rb +0 -191
- data/test/spec/runner/execution_context_test.rb +0 -45
- data/test/spec/runner/formatter/failure_dump_test.rb +0 -94
- data/test/spec/runner/formatter/html_formatter_test.rb +0 -48
- data/test/spec/runner/formatter/progress_bar_formatter_test.rb +0 -56
- data/test/spec/runner/formatter/rdoc_formatter_test.rb +0 -51
- data/test/spec/runner/formatter/specdoc_formatter_test.rb +0 -57
- data/test/spec/runner/kernel_ext_test.rb +0 -13
- data/test/spec/runner/option_parser_test.rb +0 -141
- data/test/spec/runner/reporter_test.rb +0 -128
- data/test/spec/runner/spec_matcher_test.rb +0 -47
- data/test/spec/runner/specification_test.rb +0 -121
- data/test/spec/test_to_spec/ruby_to_ruby_test.rb +0 -79
- data/test/spec/test_to_spec/sexp_transformer_assertion_test.rb +0 -207
- data/test/spec/test_to_spec/sexp_transformer_test.rb +0 -303
- data/test/spec/test_to_spec/test_case_ext_test.rb +0 -25
- data/test/spec/test_to_spec/testfiles/test_unit_api_spec.rb +0 -75
- data/test/spec/test_to_spec/testfiles/test_unit_api_test.rb +0 -70
- data/test/test_classes.rb +0 -102
- data/test/test_helper.rb +0 -32
@@ -0,0 +1,28 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../lib/spec'
|
2
|
+
|
3
|
+
class MockableClass
|
4
|
+
def self.find id
|
5
|
+
return :original_return
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
context "A partial mock" do
|
10
|
+
|
11
|
+
specify "should work at the class level" do
|
12
|
+
MockableClass.should_receive(:find).with(1).and_return {:stub_return}
|
13
|
+
MockableClass.find(1).should_equal :stub_return
|
14
|
+
end
|
15
|
+
|
16
|
+
specify "should revert to the original after each spec" do
|
17
|
+
MockableClass.find(1).should_equal :original_return
|
18
|
+
end
|
19
|
+
|
20
|
+
specify "can be mocked w/ ordering" do
|
21
|
+
MockableClass.should_receive(:msg_1).ordered
|
22
|
+
MockableClass.should_receive(:msg_2).ordered
|
23
|
+
MockableClass.should_receive(:msg_3).ordered
|
24
|
+
MockableClass.msg_1
|
25
|
+
MockableClass.msg_2
|
26
|
+
MockableClass.msg_3
|
27
|
+
end
|
28
|
+
end
|
data/examples/stack_spec.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
require File.dirname(__FILE__) + '/../lib/spec'
|
2
2
|
require File.dirname(__FILE__) + "/stack"
|
3
3
|
|
4
|
-
context "A stack
|
4
|
+
context "A stack which is neither empty nor full" do
|
5
5
|
setup do
|
6
6
|
@stack = Stack.new
|
7
7
|
["a","b","c"].each { |x| @stack.push x }
|
@@ -9,25 +9,25 @@ context "A stack (in general)" do
|
|
9
9
|
|
10
10
|
specify "should add to the top when sent 'push'" do
|
11
11
|
@stack.push "d"
|
12
|
-
@stack.peek.
|
12
|
+
@stack.peek.should == "d"
|
13
13
|
end
|
14
14
|
|
15
15
|
specify "should return the top item when sent 'peek'" do
|
16
|
-
@stack.peek.
|
16
|
+
@stack.peek.should == "c"
|
17
17
|
end
|
18
18
|
|
19
19
|
specify "should NOT remove the top item when sent 'peek'" do
|
20
|
-
@stack.peek.
|
21
|
-
@stack.peek.
|
20
|
+
@stack.peek.should == "c"
|
21
|
+
@stack.peek.should == "c"
|
22
22
|
end
|
23
23
|
|
24
24
|
specify "should return the top item when sent 'pop'" do
|
25
|
-
@stack.pop.
|
25
|
+
@stack.pop.should == "c"
|
26
26
|
end
|
27
27
|
|
28
28
|
specify "should remove the top item when sent 'pop'" do
|
29
|
-
@stack.pop.
|
30
|
-
@stack.pop.
|
29
|
+
@stack.pop.should == "c"
|
30
|
+
@stack.pop.should == "b"
|
31
31
|
end
|
32
32
|
end
|
33
33
|
|
@@ -1,13 +1,11 @@
|
|
1
1
|
require File.dirname(__FILE__) + '/../lib/spec'
|
2
2
|
|
3
3
|
context "A consumer of a stub" do
|
4
|
-
|
5
|
-
specify "should be able to stub objects" do
|
4
|
+
specify "should be able to stub methods on any Object" do
|
6
5
|
obj = Object.new
|
7
|
-
|
6
|
+
obj.stub!(:foobar).and_return {:return_value}
|
8
7
|
obj.foobar.should_equal :return_value
|
9
8
|
end
|
10
|
-
|
11
9
|
end
|
12
10
|
|
13
11
|
class StubbableClass
|
@@ -16,13 +14,56 @@ class StubbableClass
|
|
16
14
|
end
|
17
15
|
end
|
18
16
|
|
19
|
-
context "A
|
20
|
-
specify "should
|
21
|
-
|
17
|
+
context "A stubbed method on a class" do
|
18
|
+
specify "should return the stubbed value" do
|
19
|
+
StubbableClass.stub!(:find).and_return(:stub_return)
|
22
20
|
StubbableClass.find(1).should_equal :stub_return
|
23
21
|
end
|
24
22
|
|
25
|
-
specify "should revert to the original after each spec" do
|
23
|
+
specify "should revert to the original method after each spec" do
|
26
24
|
StubbableClass.find(1).should_equal :original_return
|
27
25
|
end
|
28
|
-
|
26
|
+
|
27
|
+
specify "can stub! and mock the same message" do
|
28
|
+
StubbableClass.stub!(:msg).and_return(:stub_value)
|
29
|
+
StubbableClass.should_receive(:msg).with(:arg).and_return(:mock_value)
|
30
|
+
|
31
|
+
StubbableClass.msg.should_equal :stub_value
|
32
|
+
StubbableClass.msg(:other_arg).should_equal :stub_value
|
33
|
+
StubbableClass.msg(:arg).should_equal :mock_value
|
34
|
+
StubbableClass.msg(:another_arg).should_equal :stub_value
|
35
|
+
StubbableClass.msg(:yet_another_arg).should_equal :stub_value
|
36
|
+
StubbableClass.msg.should_equal :stub_value
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
context "A mock" do
|
41
|
+
specify "can stub!" do
|
42
|
+
mock = mock("stubbing mock")
|
43
|
+
mock.stub!(:msg).and_return(:value)
|
44
|
+
(1..10).each {mock.msg.should_equal :value}
|
45
|
+
end
|
46
|
+
|
47
|
+
specify "can stub! and mock" do
|
48
|
+
mock = mock("stubbing mock")
|
49
|
+
mock.stub!(:stub_message).and_return(:stub_value)
|
50
|
+
mock.should_receive(:mock_message).once.and_return(:mock_value)
|
51
|
+
(1..10).each {mock.stub_message.should_equal :stub_value}
|
52
|
+
mock.mock_message.should_equal :mock_value
|
53
|
+
(1..10).each {mock.stub_message.should_equal :stub_value}
|
54
|
+
end
|
55
|
+
|
56
|
+
specify "can stub! and mock the same message" do
|
57
|
+
mock = mock("stubbing mock")
|
58
|
+
mock.stub!(:msg).and_return(:stub_value)
|
59
|
+
mock.should_receive(:msg).with(:arg).and_return(:mock_value)
|
60
|
+
mock.msg.should_equal :stub_value
|
61
|
+
mock.msg(:other_arg).should_equal :stub_value
|
62
|
+
mock.msg(:arg).should_equal :mock_value
|
63
|
+
mock.msg(:another_arg).should_equal :stub_value
|
64
|
+
mock.msg(:yet_another_arg).should_equal :stub_value
|
65
|
+
mock.msg.should_equal :stub_value
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
|
data/examples/test_case_spec.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
require File.dirname(__FILE__) + '/../lib/spec'
|
2
2
|
require 'test/unit'
|
3
3
|
|
4
|
-
class
|
4
|
+
class RSpecIntegrationTest < Test::Unit::TestCase
|
5
5
|
def self.fixtures(*args)
|
6
6
|
@@fixtures = true
|
7
7
|
end
|
@@ -32,8 +32,8 @@ module RandomHelperModule
|
|
32
32
|
end
|
33
33
|
end
|
34
34
|
|
35
|
-
context "
|
36
|
-
inherit
|
35
|
+
context "RSpec should integrate with Test::Unit::TestCase" do
|
36
|
+
inherit RSpecIntegrationTest
|
37
37
|
include RandomHelperModule
|
38
38
|
|
39
39
|
fixtures :some_table
|
@@ -47,17 +47,17 @@ context "Rspec should integrate with Test::Unit::TestCase" do
|
|
47
47
|
@rspec_setup_called.should_be true
|
48
48
|
end
|
49
49
|
|
50
|
-
specify "
|
50
|
+
specify "RSpec should be able to access TestCase methods" do
|
51
51
|
helper_method
|
52
52
|
@helper_method_called.should_be true
|
53
53
|
end
|
54
54
|
|
55
|
-
specify "
|
55
|
+
specify "RSpec should be able to accept included modules" do
|
56
56
|
random_task
|
57
57
|
@random_task_called.should_be true
|
58
58
|
end
|
59
59
|
|
60
60
|
teardown do
|
61
|
-
|
61
|
+
RSpecIntegrationTest.verify_class_method
|
62
62
|
end
|
63
63
|
end
|
data/lib/spec.rb
CHANGED
File without changes
|
data/lib/spec/expectations.rb
CHANGED
@@ -1,7 +1,4 @@
|
|
1
|
-
require 'spec/expectations/exceptions'
|
2
|
-
require 'spec/expectations/expectations'
|
3
|
-
require 'spec/expectations/should_base'
|
4
|
-
require 'spec/expectations/have_helper'
|
5
|
-
require 'spec/expectations/should_helper'
|
6
|
-
require 'spec/expectations/should_negator'
|
7
1
|
require 'spec/expectations/sugar'
|
2
|
+
require 'spec/expectations/errors'
|
3
|
+
require 'spec/expectations/extensions'
|
4
|
+
require 'spec/expectations/should'
|
@@ -1,56 +1,32 @@
|
|
1
|
-
begin
|
2
|
-
require 'rubygems'
|
3
|
-
require 'diff/lcs' #necessary to do loading bug on some machines - not sure why - DaC
|
4
|
-
require 'diff/lcs/hunk'
|
5
|
-
rescue LoadError
|
6
|
-
raise "You must gem install diff-lcs to use diffing"
|
7
|
-
end
|
8
|
-
|
9
1
|
module Spec
|
10
2
|
module Expectations
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
end
|
19
|
-
result
|
3
|
+
module Should
|
4
|
+
class Base
|
5
|
+
unless defined? @@differ
|
6
|
+
@@differ = nil
|
7
|
+
end
|
8
|
+
def self.differ=(differ)
|
9
|
+
@@differ = differ
|
20
10
|
end
|
21
|
-
end
|
22
11
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
hunk = Diff::LCS::Hunk.new(data_old, data_new, piece, context_lines,
|
35
|
-
file_length_difference)
|
36
|
-
file_length_difference = hunk.file_length_difference
|
37
|
-
next unless oldhunk
|
38
|
-
# Hunks may overlap, which is why we need to be careful when our
|
39
|
-
# diff includes lines of context. Otherwise, we might print
|
40
|
-
# redundant lines.
|
41
|
-
if (context_lines > 0) and hunk.overlaps?(oldhunk)
|
42
|
-
hunk.unshift(oldhunk)
|
43
|
-
else
|
44
|
-
output << oldhunk.diff(format)
|
12
|
+
unless defined?(RSPEC_TESTING)
|
13
|
+
alias old_default_message default_message
|
14
|
+
def default_message(expectation, expected=:no_expectation_specified)
|
15
|
+
result = old_default_message(expectation, expected)
|
16
|
+
|
17
|
+
if expected != :no_expectation_specified
|
18
|
+
if expected.is_a?(String)
|
19
|
+
result << "\nDiff:" << @@differ.diff_as_string(@target.to_s, expected)
|
20
|
+
elsif ! @target.is_a? Proc
|
21
|
+
result << "\nDiff:" << @@differ.diff_as_object(@target,expected)
|
22
|
+
end
|
45
23
|
end
|
46
|
-
|
47
|
-
|
48
|
-
output << "\n"
|
24
|
+
|
25
|
+
result
|
49
26
|
end
|
50
|
-
end
|
51
|
-
|
52
|
-
|
53
|
-
end
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
54
30
|
end
|
55
31
|
end
|
56
32
|
end
|
@@ -0,0 +1,62 @@
|
|
1
|
+
begin
|
2
|
+
require 'rubygems'
|
3
|
+
require 'diff/lcs' #necessary due to loading bug on some machines - not sure why - DaC
|
4
|
+
require 'diff/lcs/hunk'
|
5
|
+
rescue LoadError ; raise "You must gem install diff-lcs to use diffing" ; end
|
6
|
+
|
7
|
+
require 'pp'
|
8
|
+
|
9
|
+
module Spec
|
10
|
+
module Expectations
|
11
|
+
module Differs
|
12
|
+
|
13
|
+
# TODO add colour support
|
14
|
+
# TODO add some rdoc
|
15
|
+
class Default
|
16
|
+
def initialize(format=:unified,context_lines=nil,colour=nil)
|
17
|
+
|
18
|
+
context_lines ||= 3
|
19
|
+
colour ||= false
|
20
|
+
|
21
|
+
@format,@context_lines,@colour = format,context_lines,colour
|
22
|
+
end
|
23
|
+
|
24
|
+
# This is snagged from diff/lcs/ldiff.rb (which is a commandline tool)
|
25
|
+
def diff_as_string(data_old, data_new)
|
26
|
+
data_old = data_old.split(/\n/).map! { |e| e.chomp }
|
27
|
+
data_new = data_new.split(/\n/).map! { |e| e.chomp }
|
28
|
+
output = ""
|
29
|
+
diffs = Diff::LCS.diff(data_old, data_new)
|
30
|
+
return output if diffs.empty?
|
31
|
+
oldhunk = hunk = nil
|
32
|
+
file_length_difference = 0
|
33
|
+
diffs.each do |piece|
|
34
|
+
begin
|
35
|
+
hunk = Diff::LCS::Hunk.new(data_old, data_new, piece, @context_lines,
|
36
|
+
file_length_difference)
|
37
|
+
file_length_difference = hunk.file_length_difference
|
38
|
+
next unless oldhunk
|
39
|
+
# Hunks may overlap, which is why we need to be careful when our
|
40
|
+
# diff includes lines of context. Otherwise, we might print
|
41
|
+
# redundant lines.
|
42
|
+
if (@context_lines > 0) and hunk.overlaps?(oldhunk)
|
43
|
+
hunk.unshift(oldhunk)
|
44
|
+
else
|
45
|
+
output << oldhunk.diff(@format)
|
46
|
+
end
|
47
|
+
ensure
|
48
|
+
oldhunk = hunk
|
49
|
+
output << "\n"
|
50
|
+
end
|
51
|
+
end
|
52
|
+
#Handle the last remaining hunk
|
53
|
+
output << oldhunk.diff(@format) << "\n"
|
54
|
+
end
|
55
|
+
|
56
|
+
def diff_as_object(target,expected)
|
57
|
+
diff_as_string(PP.pp(target,""), PP.pp(expected,""))
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
File without changes
|
@@ -0,0 +1,14 @@
|
|
1
|
+
class Object
|
2
|
+
def inspect_for_expectation_not_met_error
|
3
|
+
return "#{inspect}" if inspect.include? "<"
|
4
|
+
return "<#{inspect}>" unless inspect.include? "<"
|
5
|
+
end
|
6
|
+
end
|
7
|
+
class TrueClass; def inspect_for_expectation_not_met_error; "true" end end
|
8
|
+
class FalseClass; def inspect_for_expectation_not_met_error; "false" end end
|
9
|
+
class NilClass; def inspect_for_expectation_not_met_error; "nil" end end
|
10
|
+
class Class; def inspect_for_expectation_not_met_error; "<#{name}>" end end
|
11
|
+
class Proc; def inspect_for_expectation_not_met_error; "<Proc>" end end
|
12
|
+
class Array; def inspect_for_expectation_not_met_error; inspect end end
|
13
|
+
class String; def inspect_for_expectation_not_met_error; inspect end end
|
14
|
+
class Numeric; def inspect_for_expectation_not_met_error; inspect end end
|
@@ -2,7 +2,7 @@ module Spec
|
|
2
2
|
module Expectations
|
3
3
|
module ObjectExpectations
|
4
4
|
def should
|
5
|
-
|
5
|
+
Should::Should.new self
|
6
6
|
end
|
7
7
|
end
|
8
8
|
end
|
@@ -10,10 +10,7 @@ end
|
|
10
10
|
|
11
11
|
class Object
|
12
12
|
include Spec::Expectations::ObjectExpectations
|
13
|
+
include Spec::Expectations::UnderscoreSugar
|
13
14
|
end
|
14
15
|
|
15
|
-
|
16
|
-
def close?(other, precision)
|
17
|
-
(self - other).abs < precision
|
18
|
-
end
|
19
|
-
end
|
16
|
+
Object.handle_underscores_for_rspec!
|
@@ -0,0 +1,42 @@
|
|
1
|
+
module Spec
|
2
|
+
module Expectations
|
3
|
+
module Should
|
4
|
+
class Base
|
5
|
+
|
6
|
+
instance_methods.each { |m| undef_method m unless m =~ /^(__|\w)/ }
|
7
|
+
|
8
|
+
def default_message(expectation, expected=:no_expectation_specified)
|
9
|
+
message = "#{@target.inspect_for_expectation_not_met_error} #{expectation}"
|
10
|
+
if (expected != :no_expectation_specified)
|
11
|
+
message << " " << expected.inspect_for_expectation_not_met_error
|
12
|
+
end
|
13
|
+
message
|
14
|
+
end
|
15
|
+
|
16
|
+
def fail_with_message(message)
|
17
|
+
Kernel::raise(Spec::Expectations::ExpectationNotMetError.new(message))
|
18
|
+
end
|
19
|
+
|
20
|
+
def find_supported_sym(original_sym)
|
21
|
+
["#{original_sym}?", "#{original_sym}s?"].each do |alternate_sym|
|
22
|
+
return alternate_sym.to_s if @target.respond_to?(alternate_sym.to_s)
|
23
|
+
end
|
24
|
+
return original_sym.supported_by_rspec? ? original_sym : "#{original_sym}?"
|
25
|
+
end
|
26
|
+
|
27
|
+
def method_missing(original_sym, *args, &block)
|
28
|
+
if original_sym.to_s =~ /^not_/
|
29
|
+
return Not.new(@target).__send__(original_sym.to_s[4..-1].to_sym, *args, &block)
|
30
|
+
end
|
31
|
+
if original_sym.to_s =~ /^be_/
|
32
|
+
return __send__(original_sym.to_s[3..-1].to_sym, *args, &block)
|
33
|
+
end
|
34
|
+
if original_sym.to_s =~ /^have_/
|
35
|
+
return have.__send__(original_sym.to_s[5..-1].to_sym, *args, &block)
|
36
|
+
end
|
37
|
+
__delegate_method_missing_to_target original_sym, find_supported_sym(original_sym), *args
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|