rspec 1.2.9 → 1.3.1
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/History.rdoc +51 -1
- data/License.txt +1 -1
- data/Manifest.txt +11 -4
- data/README.rdoc +10 -24
- data/Rakefile +17 -13
- data/Upgrade.rdoc +63 -2
- data/examples/passing/shared_example_group_example.rb +0 -36
- data/examples/passing/simple_matcher_example.rb +3 -3
- data/features/formatters/nested_formatter.feature +32 -0
- data/features/interop/cucumber_stubs_dont_leak.feature +11 -0
- data/features/interop/test_but_not_test_unit.feature +1 -1
- data/features/interop/test_case_with_should_methods.feature +1 -1
- data/features/matchers/define_matcher_with_fluent_interface.feature +21 -0
- data/features/matchers/define_wrapped_matcher.feature +28 -1
- data/features/matchers/match_unless_raises.feature +60 -0
- data/features/matchers/match_unless_raises_unexpected_error.feature +39 -0
- data/features/mocks/block_local_expectations.feature +62 -0
- data/features/step_definitions/running_rspec_steps.rb +9 -0
- data/features/step_definitions/stubbing_steps.rb +16 -0
- data/features/support/env.rb +1 -0
- data/features/support/matchers/smart_match.rb +23 -4
- data/geminstaller.yml +29 -0
- data/lib/autotest/rspec.rb +14 -7
- data/lib/spec/deprecation.rb +2 -1
- data/lib/spec/dsl/main.rb +2 -1
- data/lib/spec/example/example_group_methods.rb +6 -1
- data/lib/spec/example/example_methods.rb +4 -0
- data/lib/spec/example/subject.rb +9 -3
- data/lib/spec/interop/test/unit/testsuite_adapter.rb +2 -0
- data/lib/spec/interop/test.rb +1 -1
- data/lib/spec/matchers/be.rb +167 -128
- data/lib/spec/matchers/has.rb +3 -3
- data/lib/spec/matchers/have.rb +1 -0
- data/lib/spec/matchers/matcher.rb +55 -10
- data/lib/spec/matchers/method_missing.rb +2 -2
- data/lib/spec/matchers/operator_matcher.rb +6 -1
- data/lib/spec/matchers/pretty.rb +2 -2
- data/lib/spec/matchers/raise_exception.rb +131 -0
- data/lib/spec/matchers/simple_matcher.rb +2 -1
- data/lib/spec/matchers/throw_symbol.rb +18 -22
- data/lib/spec/matchers.rb +21 -2
- data/lib/spec/mocks/message_expectation.rb +63 -48
- data/lib/spec/mocks/methods.rb +13 -8
- data/lib/spec/mocks/proxy.rb +45 -22
- data/lib/spec/runner/backtrace_tweaker.rb +3 -2
- data/lib/spec/runner/configuration.rb +8 -0
- data/lib/spec/runner/differs/default.rb +1 -1
- data/lib/spec/runner/drb_command_line.rb +8 -2
- data/lib/spec/runner/example_group_runner.rb +1 -2
- data/lib/spec/runner/formatter/nested_text_formatter.rb +6 -3
- data/lib/spec/runner/option_parser.rb +2 -0
- data/lib/spec/runner/options.rb +8 -2
- data/lib/spec/stubs/cucumber.rb +2 -2
- data/lib/spec/version.rb +2 -2
- data/spec/autotest/autotest_helper.rb +1 -1
- data/spec/autotest/discover_spec.rb +2 -2
- data/spec/autotest/failed_results_re_spec.rb +2 -2
- data/spec/autotest/rspec_spec.rb +21 -6
- data/spec/spec/dsl/main_spec.rb +10 -2
- data/spec/spec/example/example_group_methods_spec.rb +21 -1
- data/spec/spec/example/example_group_proxy_spec.rb +1 -1
- data/spec/spec/example/example_group_spec.rb +1 -12
- data/spec/spec/example/example_matcher_spec.rb +3 -4
- data/spec/spec/example/subject_spec.rb +7 -0
- data/spec/spec/expectations/wrap_expectation_spec.rb +2 -1
- data/spec/spec/interop/test/unit/spec_spec.rb +7 -7
- data/spec/spec/interop/test/unit/testcase_spec.rb +7 -7
- data/spec/spec/interop/test/unit/testsuite_adapter_spec.rb +1 -1
- data/spec/spec/matchers/be_spec.rb +159 -10
- data/spec/spec/matchers/has_spec.rb +109 -0
- data/spec/spec/matchers/have_spec.rb +278 -293
- data/spec/spec/matchers/match_array_spec.rb +8 -1
- data/spec/spec/matchers/matcher_spec.rb +70 -9
- data/spec/spec/matchers/raise_exception_spec.rb +345 -0
- data/spec/spec/matchers/simple_matcher_spec.rb +51 -44
- data/spec/spec/matchers/throw_symbol_spec.rb +83 -58
- data/spec/spec/mocks/and_yield_spec.rb +117 -0
- data/spec/spec/mocks/bug_report_496_spec.rb +2 -4
- data/spec/spec/mocks/mock_spec.rb +2 -2
- data/spec/spec/runner/command_line_spec.rb +26 -5
- data/spec/spec/runner/drb_command_line_spec.rb +39 -0
- data/spec/spec/runner/formatter/nested_text_formatter_spec.rb +35 -11
- data/spec/spec/runner/option_parser_spec.rb +12 -6
- data/spec/spec/runner/options_spec.rb +7 -0
- data/spec/spec/runner/quiet_backtrace_tweaker_spec.rb +23 -5
- data/spec/spec_helper.rb +2 -1
- metadata +107 -38
- data/lib/spec/matchers/raise_error.rb +0 -129
- data/spec/spec/matchers/matcher_methods_spec.rb +0 -63
- data/spec/spec/matchers/raise_error_spec.rb +0 -333
- /data/lib/spec/{matchers/extensions → extensions}/instance_exec.rb +0 -0
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
require '
|
|
1
|
+
require 'autotest/autotest_helper'
|
|
2
2
|
|
|
3
3
|
describe "failed_results_re" do
|
|
4
4
|
it "should match a failure" do
|
|
@@ -28,4 +28,4 @@ describe "failed_results_re" do
|
|
|
28
28
|
$1.should == "this example"
|
|
29
29
|
$2.should == "reason\n/path.rb:37:"
|
|
30
30
|
end
|
|
31
|
-
end
|
|
31
|
+
end
|
data/spec/autotest/rspec_spec.rb
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
require '
|
|
1
|
+
require 'autotest/autotest_helper'
|
|
2
2
|
|
|
3
3
|
describe Autotest::Rspec do
|
|
4
4
|
describe "adding spec.opts --options" do
|
|
@@ -26,17 +26,21 @@ describe Autotest::Rspec do
|
|
|
26
26
|
@ruby = @rspec_autotest.ruby
|
|
27
27
|
@spec_cmd = File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'bin', 'spec'))
|
|
28
28
|
@options = @rspec_autotest.add_options_if_present
|
|
29
|
+
files = %w[file_one file_two]
|
|
29
30
|
@files_to_test = {
|
|
30
|
-
|
|
31
|
+
files[0] => [],
|
|
32
|
+
files[1] => []
|
|
31
33
|
}
|
|
32
34
|
# this is not the inner representation of Autotest!
|
|
33
|
-
@rspec_autotest.
|
|
34
|
-
@
|
|
35
|
-
@to_test = @files_to_test.keys.flatten.join ' '
|
|
35
|
+
@rspec_autotest.files_to_test = @files_to_test
|
|
36
|
+
@to_test = files.map { |f| File.expand_path(f) }.join ' '
|
|
36
37
|
end
|
|
37
38
|
|
|
38
39
|
it "should make the appropriate test command" do
|
|
39
|
-
@rspec_autotest.make_test_cmd(@files_to_test)
|
|
40
|
+
cmd = @rspec_autotest.make_test_cmd(@files_to_test)
|
|
41
|
+
(cmd =~ /#{@ruby} #{@spec_cmd} --autospec (.*) #{@options}/).should be_true
|
|
42
|
+
$1.should =~ /#{File.expand_path('file_one')}/
|
|
43
|
+
$1.should =~ /#{File.expand_path('file_two')}/
|
|
40
44
|
end
|
|
41
45
|
|
|
42
46
|
it "should return a blank command for no files" do
|
|
@@ -108,4 +112,15 @@ describe Autotest::Rspec do
|
|
|
108
112
|
@rspec_autotest.consolidate_failures(failures).keys.should_not include(subject_file)
|
|
109
113
|
end
|
|
110
114
|
end
|
|
115
|
+
|
|
116
|
+
describe "normalizing file names" do
|
|
117
|
+
it "should ensure that a single file appears in files_to_test only once" do
|
|
118
|
+
@rspec_autotest = Autotest::Rspec.new
|
|
119
|
+
@files_to_test = {}
|
|
120
|
+
['filename.rb', './filename.rb', File.expand_path('filename.rb')].each do |file|
|
|
121
|
+
@files_to_test[file] = []
|
|
122
|
+
end
|
|
123
|
+
@rspec_autotest.normalize(@files_to_test).should have(1).file
|
|
124
|
+
end
|
|
125
|
+
end
|
|
111
126
|
end
|
data/spec/spec/dsl/main_spec.rb
CHANGED
|
@@ -57,7 +57,6 @@ module Spec
|
|
|
57
57
|
end
|
|
58
58
|
end
|
|
59
59
|
|
|
60
|
-
|
|
61
60
|
describe "#share_as" do
|
|
62
61
|
def self.next_group_name
|
|
63
62
|
@group_number ||= 0
|
|
@@ -68,6 +67,15 @@ module Spec
|
|
|
68
67
|
def group_name
|
|
69
68
|
@group_name ||= self.class.next_group_name
|
|
70
69
|
end
|
|
70
|
+
|
|
71
|
+
before(:each) do
|
|
72
|
+
Spec.stub(:deprecate)
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
it "is deprecated" do
|
|
76
|
+
Spec.should_receive(:deprecate)
|
|
77
|
+
share_as group_name do; end
|
|
78
|
+
end
|
|
71
79
|
|
|
72
80
|
it "registers a shared ExampleGroup" do
|
|
73
81
|
block = lambda {|a,b|}
|
|
@@ -92,4 +100,4 @@ module Spec
|
|
|
92
100
|
end
|
|
93
101
|
end
|
|
94
102
|
end
|
|
95
|
-
|
|
103
|
+
|
|
@@ -732,7 +732,7 @@ module Spec
|
|
|
732
732
|
end
|
|
733
733
|
end
|
|
734
734
|
|
|
735
|
-
describe "#
|
|
735
|
+
describe "#let" do
|
|
736
736
|
let(:counter) do
|
|
737
737
|
Class.new do
|
|
738
738
|
def initialize
|
|
@@ -743,6 +743,7 @@ module Spec
|
|
|
743
743
|
end
|
|
744
744
|
end.new
|
|
745
745
|
end
|
|
746
|
+
|
|
746
747
|
it "generates an instance method" do
|
|
747
748
|
counter.count.should == 1
|
|
748
749
|
end
|
|
@@ -752,6 +753,25 @@ module Spec
|
|
|
752
753
|
counter.count.should == 2
|
|
753
754
|
end
|
|
754
755
|
end
|
|
756
|
+
|
|
757
|
+
describe "#let!" do
|
|
758
|
+
let!(:creator) do
|
|
759
|
+
class Creator
|
|
760
|
+
@count = 0
|
|
761
|
+
def self.count
|
|
762
|
+
@count += 1
|
|
763
|
+
end
|
|
764
|
+
end
|
|
765
|
+
end
|
|
766
|
+
|
|
767
|
+
it "evaluates the value non-lazily" do
|
|
768
|
+
lambda { Creator.count }.should_not raise_error
|
|
769
|
+
end
|
|
770
|
+
|
|
771
|
+
it "does not interfere between tests" do
|
|
772
|
+
Creator.count.should == 1
|
|
773
|
+
end
|
|
774
|
+
end
|
|
755
775
|
end
|
|
756
776
|
end
|
|
757
777
|
end
|
|
@@ -19,20 +19,9 @@ module Spec
|
|
|
19
19
|
@@class_variable = "a class variable"
|
|
20
20
|
|
|
21
21
|
it "can access class variables in examples in Ruby 1.8" do
|
|
22
|
-
|
|
23
|
-
@@class_variable.should == "a class variable"
|
|
24
|
-
end
|
|
22
|
+
@@class_variable.should == "a class variable"
|
|
25
23
|
end
|
|
26
24
|
|
|
27
|
-
it "can NOT access class variables in examples in Ruby 1.9" do
|
|
28
|
-
with_ruby 1.9 do
|
|
29
|
-
lambda do
|
|
30
|
-
@@class_variable.should == "a class variable"
|
|
31
|
-
end.should raise_error(NameError)
|
|
32
|
-
end
|
|
33
|
-
end
|
|
34
|
-
|
|
35
|
-
|
|
36
25
|
end
|
|
37
26
|
|
|
38
27
|
class ExampleClassVariablePollutionSpec < ExampleGroup
|
|
@@ -3,10 +3,9 @@ require 'spec_helper'
|
|
|
3
3
|
module Spec
|
|
4
4
|
module Example
|
|
5
5
|
describe ExampleMatcher, "#matches?" do
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
matcher.negative_failure_message = "expected matcher.matches?(#{description.inspect}) to return false, got true"
|
|
6
|
+
|
|
7
|
+
Spec::Matchers.define :match_examples do |examples|
|
|
8
|
+
match do |actual|
|
|
10
9
|
actual.matches?(examples)
|
|
11
10
|
end
|
|
12
11
|
end
|
|
@@ -86,6 +86,13 @@ module Spec
|
|
|
86
86
|
|
|
87
87
|
describe ".its (to access subject's attributes)" do
|
|
88
88
|
with_sandboxed_options do
|
|
89
|
+
it "allows before(:each) blocks on subjects in outer scope" do
|
|
90
|
+
group = Class.new(ExampleGroupDouble).describe(Array)
|
|
91
|
+
group.before(:each) { subject << 1 }
|
|
92
|
+
child = group.its(:length) { should == 1 }
|
|
93
|
+
child.run(options).should == true
|
|
94
|
+
end
|
|
95
|
+
|
|
89
96
|
it "passes when expectation should pass" do
|
|
90
97
|
group = Class.new(ExampleGroupDouble).describe(Array)
|
|
91
98
|
child = group.its(:length) { should == 0 }
|
|
@@ -5,43 +5,43 @@ describe "ExampleGroup with test/unit/interop" do
|
|
|
5
5
|
|
|
6
6
|
describe "with passing examples" do
|
|
7
7
|
it "should output 0 failures" do
|
|
8
|
-
output = ruby("#{resources}/spec_that_passes.rb")
|
|
8
|
+
output = ruby("'#{resources}/spec_that_passes.rb'")
|
|
9
9
|
output.should include("1 example, 0 failures")
|
|
10
10
|
end
|
|
11
11
|
|
|
12
12
|
it "should return an exit code of 0" do
|
|
13
|
-
ruby("#{resources}/spec_that_passes.rb")
|
|
13
|
+
ruby("'#{resources}/spec_that_passes.rb'")
|
|
14
14
|
$?.should == 0
|
|
15
15
|
end
|
|
16
16
|
end
|
|
17
17
|
|
|
18
18
|
describe "with failing examples" do
|
|
19
19
|
it "should output 1 failure" do
|
|
20
|
-
output = ruby("#{resources}/spec_that_fails.rb")
|
|
20
|
+
output = ruby("'#{resources}/spec_that_fails.rb'")
|
|
21
21
|
output.should include("1 example, 1 failure")
|
|
22
22
|
end
|
|
23
23
|
|
|
24
24
|
it "should return an exit code of 256" do
|
|
25
|
-
ruby("#{resources}/spec_that_fails.rb")
|
|
25
|
+
ruby("'#{resources}/spec_that_fails.rb'")
|
|
26
26
|
$?.should == 256
|
|
27
27
|
end
|
|
28
28
|
end
|
|
29
29
|
|
|
30
30
|
describe "with example that raises an error" do
|
|
31
31
|
it "should output 1 failure" do
|
|
32
|
-
output = ruby("#{resources}/spec_with_errors.rb")
|
|
32
|
+
output = ruby("'#{resources}/spec_with_errors.rb'")
|
|
33
33
|
output.should include("1 example, 1 failure")
|
|
34
34
|
end
|
|
35
35
|
|
|
36
36
|
it "should return an exit code of 256" do
|
|
37
|
-
ruby("#{resources}/spec_with_errors.rb")
|
|
37
|
+
ruby("'#{resources}/spec_with_errors.rb'")
|
|
38
38
|
$?.should == 256
|
|
39
39
|
end
|
|
40
40
|
end
|
|
41
41
|
|
|
42
42
|
describe "options hash" do
|
|
43
43
|
it "should be exposed" do
|
|
44
|
-
output = ruby("#{resources}/spec_with_options_hash.rb")
|
|
44
|
+
output = ruby("'#{resources}/spec_with_options_hash.rb'")
|
|
45
45
|
output.should include("1 example, 0 failures")
|
|
46
46
|
end
|
|
47
47
|
end
|
|
@@ -9,42 +9,42 @@ describe "Test::Unit::TestCase" do
|
|
|
9
9
|
|
|
10
10
|
describe "with passing test case" do
|
|
11
11
|
it "should output 0 failures" do
|
|
12
|
-
output = ruby("#{@dir}/test_case_that_passes.rb")
|
|
12
|
+
output = ruby("'#{@dir}/test_case_that_passes.rb'")
|
|
13
13
|
output.should include("1 example, 0 failures")
|
|
14
14
|
end
|
|
15
15
|
|
|
16
16
|
it "should return an exit code of 0" do
|
|
17
|
-
ruby("#{@dir}/test_case_that_passes.rb")
|
|
17
|
+
ruby("'#{@dir}/test_case_that_passes.rb'")
|
|
18
18
|
$?.should == 0
|
|
19
19
|
end
|
|
20
20
|
end
|
|
21
21
|
|
|
22
22
|
describe "with failing test case" do
|
|
23
23
|
it "should output 1 failure" do
|
|
24
|
-
output = ruby("#{@dir}/test_case_that_fails.rb")
|
|
24
|
+
output = ruby("'#{@dir}/test_case_that_fails.rb'")
|
|
25
25
|
output.should include("1 example, 1 failure")
|
|
26
26
|
end
|
|
27
27
|
|
|
28
28
|
it "should return an exit code of 256" do
|
|
29
|
-
ruby("#{@dir}/test_case_that_fails.rb")
|
|
29
|
+
ruby("'#{@dir}/test_case_that_fails.rb'")
|
|
30
30
|
$?.should == 256
|
|
31
31
|
end
|
|
32
32
|
end
|
|
33
33
|
|
|
34
34
|
describe "with test case that raises an error" do
|
|
35
35
|
it "should output 1 failure" do
|
|
36
|
-
output = ruby("#{@dir}/test_case_with_errors.rb")
|
|
36
|
+
output = ruby("'#{@dir}/test_case_with_errors.rb'")
|
|
37
37
|
output.should include("1 example, 1 failure")
|
|
38
38
|
end
|
|
39
39
|
|
|
40
40
|
it "should return an exit code of 256" do
|
|
41
|
-
ruby("#{@dir}/test_case_with_errors.rb")
|
|
41
|
+
ruby("'#{@dir}/test_case_with_errors.rb'")
|
|
42
42
|
$?.should == 256
|
|
43
43
|
end
|
|
44
44
|
end
|
|
45
45
|
|
|
46
46
|
it "should find all Test::Unit test methods" do
|
|
47
|
-
output = ruby("#{@dir}/test_case_with_various_names.rb")
|
|
47
|
+
output = ruby("'#{@dir}/test_case_with_various_names.rb'")
|
|
48
48
|
output.should include("4 examples, 0 failures")
|
|
49
49
|
end
|
|
50
50
|
end
|
|
@@ -4,6 +4,6 @@ describe "TestSuiteAdapter" do
|
|
|
4
4
|
include TestUnitSpecHelper
|
|
5
5
|
it "should pass" do
|
|
6
6
|
dir = File.dirname(__FILE__)
|
|
7
|
-
run_script "#{dir}/resources/testsuite_adapter_spec_with_test_unit.rb"
|
|
7
|
+
run_script "'#{dir}/resources/testsuite_adapter_spec_with_test_unit.rb'"
|
|
8
8
|
end
|
|
9
9
|
end
|
|
@@ -117,27 +117,143 @@ describe "should_not be_predicate(*args)" do
|
|
|
117
117
|
end
|
|
118
118
|
end
|
|
119
119
|
|
|
120
|
+
describe "should be_predicate(&block)" do
|
|
121
|
+
it "should pass when actual returns true for :predicate?(&block)" do
|
|
122
|
+
actual = mock("actual")
|
|
123
|
+
delegate = mock("delegate")
|
|
124
|
+
actual.should_receive(:happy?).and_yield
|
|
125
|
+
delegate.should_receive(:check_happy).and_return(true)
|
|
126
|
+
actual.should be_happy { delegate.check_happy }
|
|
127
|
+
end
|
|
128
|
+
|
|
129
|
+
it "should fail when actual returns false for :predicate?(&block)" do
|
|
130
|
+
actual = mock("actual")
|
|
131
|
+
delegate = mock("delegate")
|
|
132
|
+
actual.should_receive(:happy?).and_yield
|
|
133
|
+
delegate.should_receive(:check_happy).and_return(false)
|
|
134
|
+
lambda {
|
|
135
|
+
actual.should be_happy { delegate.check_happy }
|
|
136
|
+
}.should fail_with("expected happy? to return true, got false")
|
|
137
|
+
end
|
|
138
|
+
|
|
139
|
+
it "should fail when actual does not respond to :predicate?" do
|
|
140
|
+
delegate = mock("delegate", :check_happy => true)
|
|
141
|
+
lambda {
|
|
142
|
+
Object.new.should be_happy { delegate.check_happy }
|
|
143
|
+
}.should raise_error(NameError)
|
|
144
|
+
end
|
|
145
|
+
end
|
|
146
|
+
|
|
147
|
+
describe "should_not be_predicate(&block)" do
|
|
148
|
+
it "should pass when actual returns false for :predicate?(&block)" do
|
|
149
|
+
actual = mock("actual")
|
|
150
|
+
delegate = mock("delegate")
|
|
151
|
+
actual.should_receive(:happy?).and_yield
|
|
152
|
+
delegate.should_receive(:check_happy).and_return(false)
|
|
153
|
+
actual.should_not be_happy { delegate.check_happy }
|
|
154
|
+
end
|
|
155
|
+
|
|
156
|
+
it "should fail when actual returns true for :predicate?(&block)" do
|
|
157
|
+
actual = mock("actual")
|
|
158
|
+
delegate = mock("delegate")
|
|
159
|
+
actual.should_receive(:happy?).and_yield
|
|
160
|
+
delegate.should_receive(:check_happy).and_return(true)
|
|
161
|
+
lambda {
|
|
162
|
+
actual.should_not be_happy { delegate.check_happy }
|
|
163
|
+
}.should fail_with("expected happy? to return false, got true")
|
|
164
|
+
end
|
|
165
|
+
|
|
166
|
+
it "should fail when actual does not respond to :predicate?" do
|
|
167
|
+
delegate = mock("delegate", :check_happy => true)
|
|
168
|
+
lambda {
|
|
169
|
+
Object.new.should_not be_happy { delegate.check_happy }
|
|
170
|
+
}.should raise_error(NameError)
|
|
171
|
+
end
|
|
172
|
+
end
|
|
173
|
+
|
|
174
|
+
describe "should be_predicate(*args, &block)" do
|
|
175
|
+
it "should pass when actual returns true for :predicate?(*args, &block)" do
|
|
176
|
+
actual = mock("actual")
|
|
177
|
+
delegate = mock("delegate")
|
|
178
|
+
actual.should_receive(:older_than?).with(3).and_yield(3)
|
|
179
|
+
delegate.should_receive(:check_older_than).with(3).and_return(true)
|
|
180
|
+
actual.should be_older_than(3) { |age| delegate.check_older_than(age) }
|
|
181
|
+
end
|
|
182
|
+
|
|
183
|
+
it "should fail when actual returns false for :predicate?(*args, &block)" do
|
|
184
|
+
actual = mock("actual")
|
|
185
|
+
delegate = mock("delegate")
|
|
186
|
+
actual.should_receive(:older_than?).with(3).and_yield(3)
|
|
187
|
+
delegate.should_receive(:check_older_than).with(3).and_return(false)
|
|
188
|
+
lambda {
|
|
189
|
+
actual.should be_older_than(3) { |age| delegate.check_older_than(age) }
|
|
190
|
+
}.should fail_with("expected older_than?(3) to return true, got false")
|
|
191
|
+
end
|
|
192
|
+
|
|
193
|
+
it "should fail when actual does not respond to :predicate?" do
|
|
194
|
+
delegate = mock("delegate", :check_older_than => true)
|
|
195
|
+
lambda {
|
|
196
|
+
Object.new.should be_older_than(3) { |age| delegate.check_older_than(age) }
|
|
197
|
+
}.should raise_error(NameError)
|
|
198
|
+
end
|
|
199
|
+
end
|
|
200
|
+
|
|
201
|
+
describe "should_not be_predicate(*args, &block)" do
|
|
202
|
+
it "should pass when actual returns false for :predicate?(*args, &block)" do
|
|
203
|
+
actual = mock("actual")
|
|
204
|
+
delegate = mock("delegate")
|
|
205
|
+
actual.should_receive(:older_than?).with(3).and_yield(3)
|
|
206
|
+
delegate.should_receive(:check_older_than).with(3).and_return(false)
|
|
207
|
+
actual.should_not be_older_than(3) { |age| delegate.check_older_than(age) }
|
|
208
|
+
end
|
|
209
|
+
|
|
210
|
+
it "should fail when actual returns true for :predicate?(*args, &block)" do
|
|
211
|
+
actual = mock("actual")
|
|
212
|
+
delegate = mock("delegate")
|
|
213
|
+
actual.should_receive(:older_than?).with(3).and_yield(3)
|
|
214
|
+
delegate.should_receive(:check_older_than).with(3).and_return(true)
|
|
215
|
+
lambda {
|
|
216
|
+
actual.should_not be_older_than(3) { |age| delegate.check_older_than(age) }
|
|
217
|
+
}.should fail_with("expected older_than?(3) to return false, got true")
|
|
218
|
+
end
|
|
219
|
+
|
|
220
|
+
it "should fail when actual does not respond to :predicate?" do
|
|
221
|
+
delegate = mock("delegate", :check_older_than => true)
|
|
222
|
+
lambda {
|
|
223
|
+
Object.new.should_not be_older_than(3) { |age| delegate.check_older_than(age) }
|
|
224
|
+
}.should raise_error(NameError)
|
|
225
|
+
end
|
|
226
|
+
end
|
|
227
|
+
|
|
120
228
|
describe "should be_true" do
|
|
121
|
-
it "should pass when actual equal(true)" do
|
|
229
|
+
it "should pass when actual equal?(true)" do
|
|
122
230
|
true.should be_true
|
|
123
231
|
end
|
|
124
232
|
|
|
125
|
-
it "should
|
|
233
|
+
it "should pass when actual is 1" do
|
|
234
|
+
1.should be_true
|
|
235
|
+
end
|
|
236
|
+
|
|
237
|
+
it "should fail when actual equal?(false)" do
|
|
126
238
|
lambda {
|
|
127
239
|
false.should be_true
|
|
128
|
-
}.should fail_with("expected
|
|
240
|
+
}.should fail_with("expected false to be true")
|
|
129
241
|
end
|
|
130
242
|
end
|
|
131
243
|
|
|
132
244
|
describe "should be_false" do
|
|
133
|
-
it "should pass when actual equal(false)" do
|
|
245
|
+
it "should pass when actual equal?(false)" do
|
|
134
246
|
false.should be_false
|
|
135
247
|
end
|
|
136
248
|
|
|
137
|
-
it "should
|
|
249
|
+
it "should pass when actual equal?(nil)" do
|
|
250
|
+
nil.should be_false
|
|
251
|
+
end
|
|
252
|
+
|
|
253
|
+
it "should fail when actual equal?(true)" do
|
|
138
254
|
lambda {
|
|
139
255
|
true.should be_false
|
|
140
|
-
}.should fail_with("expected
|
|
256
|
+
}.should fail_with("expected true to be false")
|
|
141
257
|
end
|
|
142
258
|
end
|
|
143
259
|
|
|
@@ -173,6 +289,10 @@ describe "should be <" do
|
|
|
173
289
|
it "should fail when < operator returns false" do
|
|
174
290
|
lambda { 3.should be < 3 }.should fail_with("expected < 3, got 3")
|
|
175
291
|
end
|
|
292
|
+
|
|
293
|
+
it "should describe itself" do
|
|
294
|
+
be.<(4).description.should == "be < 4"
|
|
295
|
+
end
|
|
176
296
|
end
|
|
177
297
|
|
|
178
298
|
describe "should be <=" do
|
|
@@ -236,17 +356,32 @@ describe "should_not with operators" do
|
|
|
236
356
|
end
|
|
237
357
|
|
|
238
358
|
describe "should be" do
|
|
239
|
-
it "should pass if actual is
|
|
359
|
+
it "should pass if actual is truthy" do
|
|
240
360
|
true.should be
|
|
241
361
|
1.should be
|
|
242
362
|
end
|
|
243
363
|
|
|
244
364
|
it "should fail if actual is false" do
|
|
245
|
-
lambda {false.should be}.should fail_with("expected
|
|
365
|
+
lambda {false.should be}.should fail_with("expected false to evaluate to true")
|
|
246
366
|
end
|
|
247
367
|
|
|
248
368
|
it "should fail if actual is nil" do
|
|
249
|
-
lambda {nil.should be}.should fail_with("expected
|
|
369
|
+
lambda {nil.should be}.should fail_with("expected nil to evaluate to true")
|
|
370
|
+
end
|
|
371
|
+
|
|
372
|
+
it "should describe itself" do
|
|
373
|
+
be.description.should == "be"
|
|
374
|
+
end
|
|
375
|
+
end
|
|
376
|
+
|
|
377
|
+
describe "should_not be" do
|
|
378
|
+
it "should pass if actual is falsy" do
|
|
379
|
+
false.should_not be
|
|
380
|
+
nil.should_not be
|
|
381
|
+
end
|
|
382
|
+
|
|
383
|
+
it "should fail on true" do
|
|
384
|
+
lambda {true.should_not be}.should fail_with("expected true to evaluate to false")
|
|
250
385
|
end
|
|
251
386
|
end
|
|
252
387
|
|
|
@@ -254,9 +389,23 @@ describe "should be(value)" do
|
|
|
254
389
|
it "should pass if actual.equal?(value)" do
|
|
255
390
|
5.should be(5)
|
|
256
391
|
end
|
|
392
|
+
|
|
257
393
|
it "should fail if !actual.equal?(value)" do
|
|
258
394
|
lambda { 5.should be(6) }.should fail_with("expected 6, got 5")
|
|
259
395
|
end
|
|
396
|
+
|
|
397
|
+
it "should describe itself" do
|
|
398
|
+
be(5).description.should == "be 5"
|
|
399
|
+
end
|
|
400
|
+
end
|
|
401
|
+
|
|
402
|
+
describe "should_not be(value)" do
|
|
403
|
+
it "should pass if !actual.equal?(value)" do
|
|
404
|
+
5.should_not be(6)
|
|
405
|
+
end
|
|
406
|
+
it "should fail if !actual.equal?(value)" do
|
|
407
|
+
lambda { 5.should_not be(5) }.should fail_with("expected not 5, got 5")
|
|
408
|
+
end
|
|
260
409
|
end
|
|
261
410
|
|
|
262
411
|
describe "'should be' with operator" do
|
|
@@ -308,4 +457,4 @@ describe "be_an_instance_of" do
|
|
|
308
457
|
it "fails when class is higher up hierarchy" do
|
|
309
458
|
5.should_not be_an_instance_of(Numeric)
|
|
310
459
|
end
|
|
311
|
-
end
|
|
460
|
+
end
|
|
@@ -70,6 +70,115 @@ describe "should_not have_sym(*args)" do
|
|
|
70
70
|
end
|
|
71
71
|
end
|
|
72
72
|
|
|
73
|
+
describe "should have_sym(&block)" do
|
|
74
|
+
it "should pass when actual returns true for :has_sym?(&block)" do
|
|
75
|
+
actual = mock("actual")
|
|
76
|
+
delegate = mock("delegate")
|
|
77
|
+
actual.should_receive(:has_foo?).and_yield
|
|
78
|
+
delegate.should_receive(:check_has_foo).and_return(true)
|
|
79
|
+
actual.should have_foo { delegate.check_has_foo }
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
it "should fail when actual returns false for :has_sym?(&block)" do
|
|
83
|
+
actual = mock("actual")
|
|
84
|
+
delegate = mock("delegate")
|
|
85
|
+
actual.should_receive(:has_foo?).and_yield
|
|
86
|
+
delegate.should_receive(:check_has_foo).and_return(false)
|
|
87
|
+
lambda {
|
|
88
|
+
actual.should have_foo { delegate.check_has_foo }
|
|
89
|
+
}.should fail_with("expected #has_foo?(nil) to return true, got false")
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
it "should fail when actual does not respond to :has_sym?" do
|
|
93
|
+
delegate = mock("delegate", :check_has_foo => true)
|
|
94
|
+
lambda {
|
|
95
|
+
Object.new.should have_foo { delegate.check_has_foo }
|
|
96
|
+
}.should raise_error(NameError)
|
|
97
|
+
end
|
|
98
|
+
end
|
|
99
|
+
|
|
100
|
+
describe "should_not have_sym(&block)" do
|
|
101
|
+
it "should pass when actual returns false for :has_sym?(&block)" do
|
|
102
|
+
actual = mock("actual")
|
|
103
|
+
delegate = mock("delegate")
|
|
104
|
+
actual.should_receive(:has_foo?).and_yield
|
|
105
|
+
delegate.should_receive(:check_has_foo).and_return(false)
|
|
106
|
+
actual.should_not have_foo { delegate.check_has_foo }
|
|
107
|
+
end
|
|
108
|
+
|
|
109
|
+
it "should fail when actual returns true for :has_sym?(&block)" do
|
|
110
|
+
actual = mock("actual")
|
|
111
|
+
delegate = mock("delegate")
|
|
112
|
+
actual.should_receive(:has_foo?).and_yield
|
|
113
|
+
delegate.should_receive(:check_has_foo).and_return(true)
|
|
114
|
+
lambda {
|
|
115
|
+
actual.should_not have_foo { delegate.check_has_foo }
|
|
116
|
+
}.should fail_with("expected #has_foo?(nil) to return false, got true")
|
|
117
|
+
end
|
|
118
|
+
|
|
119
|
+
it "should fail when actual does not respond to :has_sym?" do
|
|
120
|
+
delegate = mock("delegate", :check_has_foo => true)
|
|
121
|
+
lambda {
|
|
122
|
+
Object.new.should_not have_foo { delegate.check_has_foo }
|
|
123
|
+
}.should raise_error(NameError)
|
|
124
|
+
end
|
|
125
|
+
end
|
|
126
|
+
|
|
127
|
+
describe "should have_sym(*args, &block)" do
|
|
128
|
+
it "should pass when actual returns true for :has_sym?(*args, &block)" do
|
|
129
|
+
actual = mock("actual")
|
|
130
|
+
delegate = mock("delegate")
|
|
131
|
+
actual.should_receive(:has_foo?).with(:a).and_yield(:a)
|
|
132
|
+
delegate.should_receive(:check_has_foo).with(:a).and_return(true)
|
|
133
|
+
actual.should have_foo(:a) { |foo| delegate.check_has_foo(foo) }
|
|
134
|
+
end
|
|
135
|
+
|
|
136
|
+
it "should fail when actual returns false for :has_sym?(*args, &block)" do
|
|
137
|
+
actual = mock("actual")
|
|
138
|
+
delegate = mock("delegate")
|
|
139
|
+
actual.should_receive(:has_foo?).with(:a).and_yield(:a)
|
|
140
|
+
delegate.should_receive(:check_has_foo).with(:a).and_return(false)
|
|
141
|
+
lambda {
|
|
142
|
+
actual.should have_foo(:a) { |foo| delegate.check_has_foo(foo) }
|
|
143
|
+
}.should fail_with("expected #has_foo?(:a) to return true, got false")
|
|
144
|
+
end
|
|
145
|
+
|
|
146
|
+
it "should fail when actual does not respond to :has_sym?" do
|
|
147
|
+
delegate = mock("delegate", :check_has_foo => true)
|
|
148
|
+
lambda {
|
|
149
|
+
Object.new.should have_foo(:a) { |foo| delegate.check_has_foo(foo) }
|
|
150
|
+
}.should raise_error(NameError)
|
|
151
|
+
end
|
|
152
|
+
end
|
|
153
|
+
|
|
154
|
+
describe "should_not have_sym(*args, &block)" do
|
|
155
|
+
it "should pass when actual returns false for :has_sym?(*args, &block)" do
|
|
156
|
+
actual = mock("actual")
|
|
157
|
+
delegate = mock("delegate")
|
|
158
|
+
actual.should_receive(:has_foo?).with(:a).and_yield(:a)
|
|
159
|
+
delegate.should_receive(:check_has_foo).with(:a).and_return(false)
|
|
160
|
+
actual.should_not have_foo(:a) { |foo| delegate.check_has_foo(foo) }
|
|
161
|
+
end
|
|
162
|
+
|
|
163
|
+
it "should fail when actual returns true for :has_sym?(*args, &block)" do
|
|
164
|
+
actual = mock("actual")
|
|
165
|
+
delegate = mock("delegate")
|
|
166
|
+
actual.should_receive(:has_foo?).with(:a).and_yield(:a)
|
|
167
|
+
delegate.should_receive(:check_has_foo).with(:a).and_return(true)
|
|
168
|
+
lambda {
|
|
169
|
+
actual.should_not have_foo(:a) { |foo| delegate.check_has_foo(foo) }
|
|
170
|
+
}.should fail_with("expected #has_foo?(:a) to return false, got true")
|
|
171
|
+
end
|
|
172
|
+
|
|
173
|
+
it "should fail when actual does not respond to :has_sym?" do
|
|
174
|
+
delegate = mock("delegate", :check_has_foo => true)
|
|
175
|
+
lambda {
|
|
176
|
+
Object.new.should_not have_foo(:a) { |foo| delegate.check_has_foo(foo) }
|
|
177
|
+
}.should raise_error(NameError)
|
|
178
|
+
end
|
|
179
|
+
end
|
|
180
|
+
|
|
181
|
+
|
|
73
182
|
describe "has" do
|
|
74
183
|
it "should work when the target implements #send" do
|
|
75
184
|
o = {:a => "A"}
|