rspec 1.2.2 → 1.2.3
Sign up to get free protection for your applications and to get access to all the features.
- data/History.rdoc +31 -1
- data/Manifest.txt +14 -12
- data/Rakefile +1 -1
- data/Upgrade.rdoc +43 -3
- data/examples/failing/failing_implicit_docstrings_example.rb +5 -5
- data/examples/passing/implicit_docstrings_example.rb +3 -3
- data/features/before_and_after_blocks/before_and_after_blocks.feature +20 -21
- data/features/example_groups/example_group_with_should_methods.feature +20 -8
- data/features/example_groups/implicit_docstrings.feature +36 -20
- data/features/example_groups/nested_groups.feature +25 -10
- data/features/extensions/custom_example_group.feature +19 -0
- data/features/formatters/custom_formatter.feature +30 -0
- data/features/heckle/heckle.feature +7 -7
- data/features/interop/examples_and_tests_together.feature +63 -14
- data/features/interop/rspec_output.feature +25 -0
- data/features/interop/test_but_not_test_unit.feature +19 -7
- data/features/interop/test_case_with_should_methods.feature +37 -8
- data/features/matchers/{create_matcher.feature → define_matcher.feature} +54 -30
- data/features/matchers/{create_matcher_outside_rspec.feature → define_matcher_outside_rspec.feature} +7 -7
- data/features/mock_framework_integration/use_flexmock.feature +3 -3
- data/features/mock_framework_integration/use_mocha.feature +3 -3
- data/features/mock_framework_integration/use_rr.feature +3 -3
- data/features/mocks/mix_stubs_and_mocks.feature +4 -4
- data/features/pending/pending_examples.feature +18 -18
- data/features/runner/specify_line_number.feature +32 -0
- data/features/step_definitions/running_rspec_steps.rb +41 -0
- data/features/subject/explicit_subject.feature +4 -4
- data/features/subject/implicit_subject.feature +4 -4
- data/features/support/env.rb +64 -11
- data/features/support/matchers/smart_match.rb +10 -35
- data/lib/spec.rb +1 -0
- data/lib/spec/deprecation.rb +40 -0
- data/lib/spec/dsl/main.rb +10 -5
- data/lib/spec/example.rb +1 -27
- data/lib/spec/example/args_and_options.rb +27 -0
- data/lib/spec/example/before_and_after_hooks.rb +30 -21
- data/lib/spec/example/errors.rb +8 -18
- data/lib/spec/example/example_group_factory.rb +0 -4
- data/lib/spec/example/example_group_methods.rb +27 -41
- data/lib/spec/example/example_group_proxy.rb +12 -22
- data/lib/spec/example/example_methods.rb +8 -18
- data/lib/spec/example/example_proxy.rb +4 -4
- data/lib/spec/example/pending.rb +3 -4
- data/lib/spec/example/predicate_matchers.rb +1 -1
- data/lib/spec/example/subject.rb +2 -0
- data/lib/spec/expectations.rb +1 -26
- data/lib/spec/expectations/extensions.rb +1 -1
- data/lib/spec/expectations/extensions/kernel.rb +52 -0
- data/lib/spec/expectations/handler.rb +21 -10
- data/lib/spec/matchers/be.rb +3 -3
- data/lib/spec/matchers/be_close.rb +17 -21
- data/lib/spec/matchers/be_instance_of.rb +7 -26
- data/lib/spec/matchers/be_kind_of.rb +7 -26
- data/lib/spec/matchers/dsl.rb +9 -4
- data/lib/spec/matchers/eql.rb +24 -25
- data/lib/spec/matchers/equal.rb +25 -25
- data/lib/spec/matchers/exist.rb +5 -21
- data/lib/spec/matchers/include.rb +22 -44
- data/lib/spec/matchers/match.rb +5 -25
- data/lib/spec/matchers/match_array.rb +8 -4
- data/lib/spec/matchers/matcher.rb +13 -2
- data/lib/spec/matchers/pretty.rb +1 -0
- data/lib/spec/matchers/simple_matcher.rb +2 -2
- data/lib/spec/mocks/mock.rb +10 -10
- data/lib/spec/mocks/spec_methods.rb +1 -1
- data/lib/spec/runner/configuration.rb +53 -42
- data/lib/spec/{expectations → runner}/differs/default.rb +0 -0
- data/lib/spec/{expectations → runner}/differs/load-diff-lcs.rb +0 -0
- data/lib/spec/runner/drb_command_line.rb +1 -1
- data/lib/spec/runner/example_group_runner.rb +0 -12
- data/lib/spec/runner/formatter/base_formatter.rb +77 -30
- data/lib/spec/runner/formatter/base_text_formatter.rb +19 -24
- data/lib/spec/runner/formatter/failing_example_groups_formatter.rb +1 -1
- data/lib/spec/runner/formatter/html_formatter.rb +4 -6
- data/lib/spec/runner/formatter/nested_text_formatter.rb +2 -2
- data/lib/spec/runner/formatter/no_op_method_missing.rb +21 -0
- data/lib/spec/runner/formatter/profile_formatter.rb +0 -4
- data/lib/spec/runner/formatter/progress_bar_formatter.rb +4 -5
- data/lib/spec/runner/formatter/silent_formatter.rb +10 -0
- data/lib/spec/runner/formatter/specdoc_formatter.rb +2 -2
- data/lib/spec/runner/option_parser.rb +14 -7
- data/lib/spec/runner/options.rb +17 -7
- data/lib/spec/runner/reporter.rb +69 -64
- data/lib/spec/version.rb +1 -1
- data/spec/spec/dsl/main_spec.rb +7 -0
- data/spec/spec/example/example_group_methods_spec.rb +16 -32
- data/spec/spec/example/example_group_proxy_spec.rb +25 -5
- data/spec/spec/example/example_group_spec.rb +2 -2
- data/spec/spec/example/example_methods_spec.rb +19 -24
- data/spec/spec/example/example_proxy_spec.rb +11 -1
- data/spec/spec/example/pending_module_spec.rb +2 -108
- data/spec/spec/example/predicate_matcher_spec.rb +23 -3
- data/spec/spec/expectations/extensions/object_spec.rb +9 -9
- data/spec/spec/expectations/fail_with_spec.rb +13 -13
- data/spec/spec/expectations/handler_spec.rb +44 -15
- data/spec/spec/matchers/be_close_spec.rb +9 -0
- data/spec/spec/matchers/be_instance_of_spec.rb +6 -4
- data/spec/spec/matchers/be_kind_of_spec.rb +5 -3
- data/spec/spec/matchers/be_spec.rb +1 -5
- data/spec/spec/matchers/compatibility_spec.rb +1 -1
- data/spec/spec/matchers/dsl_spec.rb +10 -1
- data/spec/spec/matchers/eql_spec.rb +8 -4
- data/spec/spec/matchers/equal_spec.rb +8 -4
- data/spec/spec/matchers/exist_spec.rb +1 -1
- data/spec/spec/matchers/include_spec.rb +1 -1
- data/spec/spec/matchers/match_array_spec.rb +26 -1
- data/spec/spec/matchers/match_spec.rb +2 -2
- data/spec/spec/matchers/matcher_methods_spec.rb +0 -3
- data/spec/spec/matchers/matcher_spec.rb +53 -0
- data/spec/spec/matchers/operator_matcher_spec.rb +1 -1
- data/spec/spec/mocks/mock_spec.rb +6 -0
- data/spec/spec/runner/configuration_spec.rb +11 -1
- data/spec/spec/runner/drb_command_line_spec.rb +13 -1
- data/spec/spec/runner/example_group_runner_spec.rb +0 -7
- data/spec/spec/runner/formatter/base_formatter_spec.rb +19 -12
- data/spec/spec/runner/formatter/base_text_formatter_spec.rb +2 -2
- data/spec/spec/runner/formatter/failing_example_groups_formatter_spec.rb +4 -4
- data/spec/spec/runner/formatter/failing_examples_formatter_spec.rb +2 -2
- data/spec/spec/runner/formatter/html_formatted-1.8.6.html +31 -34
- data/spec/spec/runner/formatter/html_formatter_spec.rb +20 -0
- data/spec/spec/runner/formatter/nested_text_formatter_spec.rb +20 -20
- data/spec/spec/runner/formatter/profile_formatter_spec.rb +22 -3
- data/spec/spec/runner/formatter/progress_bar_formatter_spec.rb +24 -3
- data/spec/spec/runner/formatter/specdoc_formatter_spec.rb +6 -6
- data/spec/spec/runner/formatter/text_mate_formatted-1.8.6.html +25 -28
- data/spec/spec/runner/formatter/text_mate_formatter_spec.rb +2 -2
- data/spec/spec/runner/option_parser_spec.rb +108 -40
- data/spec/spec/runner/reporter_spec.rb +16 -17
- data/spec/spec_helper.rb +4 -1
- metadata +20 -18
- data/features/example_groups/output.feature +0 -20
- data/features/step_definitions/running_rspec.rb +0 -69
- data/lib/spec/expectations/extensions/object.rb +0 -63
- data/resources/spec/example_group_with_should_methods.rb +0 -12
- data/resources/spec/simple_spec.rb +0 -8
- data/resources/test/spec_and_test_together.rb +0 -56
- data/resources/test/spec_including_test_but_not_unit.rb +0 -11
- data/resources/test/test_case_with_should_methods.rb +0 -29
data/features/matchers/{create_matcher_outside_rspec.feature → define_matcher_outside_rspec.feature}
RENAMED
@@ -1,17 +1,17 @@
|
|
1
|
-
Feature:
|
1
|
+
Feature: define matcher outside rspec
|
2
2
|
|
3
3
|
In order to express my domain clearly in my code examples
|
4
4
|
As a non-rspec user
|
5
|
-
I want a shortcut
|
5
|
+
I want a shortcut to define custom matchers
|
6
6
|
|
7
|
-
Scenario:
|
8
|
-
Given a file named test_multiples.rb with:
|
7
|
+
Scenario: define a matcher with default messages
|
8
|
+
Given a file named "test_multiples.rb" with:
|
9
9
|
"""
|
10
|
-
$:.unshift File.join(File.dirname(__FILE__), "
|
10
|
+
$:.unshift File.join(File.dirname(__FILE__), "/../../lib")
|
11
11
|
require 'test/unit'
|
12
12
|
require 'spec/expectations'
|
13
13
|
|
14
|
-
Spec::Matchers.
|
14
|
+
Spec::Matchers.define :be_a_multiple_of do |expected|
|
15
15
|
match do |actual|
|
16
16
|
actual % expected == 0
|
17
17
|
end
|
@@ -33,7 +33,7 @@ Feature: custom matcher shortcut
|
|
33
33
|
|
34
34
|
end
|
35
35
|
"""
|
36
|
-
When I run
|
36
|
+
When I run "ruby test_multiples.rb"
|
37
37
|
Then the exit code should be 256
|
38
38
|
And the stdout should match "expected 9 to be a multiple of 4"
|
39
39
|
And the stdout should match "2 tests, 0 assertions, 1 failures, 0 errors"
|
@@ -4,7 +4,7 @@ Feature: mock with flexmock
|
|
4
4
|
I want to be able to use flexmock without rspec mocks interfering
|
5
5
|
|
6
6
|
Scenario: Mock with flexmock
|
7
|
-
Given
|
7
|
+
Given a file named "flexmock_example_spec.rb" with:
|
8
8
|
"""
|
9
9
|
Spec::Runner.configure do |config|
|
10
10
|
config.mock_with :flexmock
|
@@ -22,6 +22,6 @@ Feature: mock with flexmock
|
|
22
22
|
end
|
23
23
|
end
|
24
24
|
"""
|
25
|
-
When I run
|
25
|
+
When I run "spec flexmock_example_spec.rb"
|
26
26
|
Then the exit code should be 0
|
27
|
-
And the stdout should match "2 examples, 0 failures"
|
27
|
+
And the stdout should match "2 examples, 0 failures"
|
@@ -4,7 +4,7 @@ Feature: mock with mocha
|
|
4
4
|
I want to be able to use mocha without rspec mocks interfering
|
5
5
|
|
6
6
|
Scenario: Mock with mocha
|
7
|
-
Given
|
7
|
+
Given a file named "mocha_example_spec.rb" with:
|
8
8
|
"""
|
9
9
|
Spec::Runner.configure do |config|
|
10
10
|
config.mock_with :mocha
|
@@ -22,6 +22,6 @@ Feature: mock with mocha
|
|
22
22
|
end
|
23
23
|
end
|
24
24
|
"""
|
25
|
-
When I run
|
25
|
+
When I run "spec mocha_example_spec.rb"
|
26
26
|
Then the exit code should be 0
|
27
|
-
And the stdout should match "2 examples, 0 failures"
|
27
|
+
And the stdout should match "2 examples, 0 failures"
|
@@ -4,7 +4,7 @@ Feature: mock with rr
|
|
4
4
|
I want to be able to use rr without rspec mocks interfering
|
5
5
|
|
6
6
|
Scenario: Mock with rr
|
7
|
-
Given
|
7
|
+
Given a file named "rr_example_spec.rb" with:
|
8
8
|
"""
|
9
9
|
Spec::Runner.configure do |config|
|
10
10
|
config.mock_with :rr
|
@@ -22,6 +22,6 @@ Feature: mock with rr
|
|
22
22
|
end
|
23
23
|
end
|
24
24
|
"""
|
25
|
-
When I run
|
25
|
+
When I run "spec rr_example_spec.rb"
|
26
26
|
Then the exit code should be 0
|
27
|
-
And the stdout should match "2 examples, 0 failures"
|
27
|
+
And the stdout should match "2 examples, 0 failures"
|
@@ -4,13 +4,13 @@ Feature: Spec and test together
|
|
4
4
|
I want to use stubs and mocks together
|
5
5
|
|
6
6
|
Scenario: stub in before
|
7
|
-
Given
|
7
|
+
Given a file named "stub_and_mocks_spec.rb" with:
|
8
8
|
"""
|
9
9
|
describe "a stub in before" do
|
10
10
|
before(:each) do
|
11
11
|
@messenger = mock('messenger').as_null_object
|
12
12
|
end
|
13
|
-
|
13
|
+
|
14
14
|
it "a" do
|
15
15
|
@messenger.should_receive(:foo).with('first')
|
16
16
|
@messenger.foo('second')
|
@@ -18,5 +18,5 @@ Feature: Spec and test together
|
|
18
18
|
end
|
19
19
|
end
|
20
20
|
"""
|
21
|
-
When I run
|
22
|
-
Then the stdout should match "expected :foo with (\"first\") but received it with ([\"second\"], [\"third\"])"
|
21
|
+
When I run "spec stub_and_mocks_spec.rb --format nested"
|
22
|
+
Then the stdout should match "expected :foo with (\"first\") but received it with ([\"second\"], [\"third\"])"
|
@@ -2,36 +2,36 @@ Feature: pending examples
|
|
2
2
|
|
3
3
|
RSpec offers three ways to indicate that an example is disabled pending
|
4
4
|
some action.
|
5
|
-
|
5
|
+
|
6
6
|
Scenario: pending implementation
|
7
|
-
Given
|
7
|
+
Given a file named "example_without_block_spec.rb" with:
|
8
8
|
"""
|
9
9
|
describe "an example" do
|
10
10
|
it "has not yet been implemented"
|
11
11
|
end
|
12
12
|
"""
|
13
|
-
When I run
|
13
|
+
When I run "spec example_without_block_spec.rb"
|
14
14
|
Then the exit code should be 0
|
15
15
|
And the stdout should match "1 example, 0 failures, 1 pending"
|
16
16
|
And the stdout should match "Not Yet Implemented"
|
17
|
-
And the stdout should match "
|
18
|
-
|
17
|
+
And the stdout should match "example_without_block_spec.rb:2"
|
18
|
+
|
19
19
|
Scenario: pending implementation with spec/test/unit
|
20
|
-
Given
|
20
|
+
Given a file named "example_without_block_spec.rb" with:
|
21
21
|
"""
|
22
22
|
require 'spec/test/unit'
|
23
23
|
describe "an example" do
|
24
24
|
it "has not yet been implemented"
|
25
25
|
end
|
26
26
|
"""
|
27
|
-
When I run
|
27
|
+
When I run "spec example_without_block_spec.rb"
|
28
28
|
Then the exit code should be 0
|
29
29
|
And the stdout should match "1 example, 0 failures, 1 pending"
|
30
30
|
And the stdout should match "Not Yet Implemented"
|
31
|
-
And the stdout should match "
|
31
|
+
And the stdout should match "example_without_block_spec.rb:3"
|
32
32
|
|
33
33
|
Scenario: pending any arbitary reason, with no block
|
34
|
-
Given
|
34
|
+
Given a file named "pending_without_block_spec.rb" with:
|
35
35
|
"""
|
36
36
|
describe "an example" do
|
37
37
|
it "is implemented but waiting" do
|
@@ -39,14 +39,14 @@ Feature: pending examples
|
|
39
39
|
end
|
40
40
|
end
|
41
41
|
"""
|
42
|
-
When I run
|
42
|
+
When I run "spec pending_without_block_spec.rb"
|
43
43
|
Then the exit code should be 0
|
44
44
|
And the stdout should match "1 example, 0 failures, 1 pending"
|
45
45
|
And the stdout should match "(something else getting finished)"
|
46
|
-
And the stdout should match "
|
46
|
+
And the stdout should match "pending_without_block_spec.rb:2"
|
47
47
|
|
48
|
-
Scenario: pending any arbitary reason, with a block
|
49
|
-
Given
|
48
|
+
Scenario: pending any arbitary reason, with a block that fails
|
49
|
+
Given a file named "pending_with_failing_block_spec.rb" with:
|
50
50
|
"""
|
51
51
|
describe "an example" do
|
52
52
|
it "is implemented but waiting" do
|
@@ -56,14 +56,14 @@ Feature: pending examples
|
|
56
56
|
end
|
57
57
|
end
|
58
58
|
"""
|
59
|
-
When I run
|
59
|
+
When I run "spec pending_with_failing_block_spec.rb"
|
60
60
|
Then the exit code should be 0
|
61
61
|
And the stdout should match "1 example, 0 failures, 1 pending"
|
62
62
|
And the stdout should match "(something else getting finished)"
|
63
|
-
And the stdout should match "
|
63
|
+
And the stdout should match "pending_with_failing_block_spec.rb:2"
|
64
64
|
|
65
65
|
Scenario: pending any arbitary reason, with a block that passes
|
66
|
-
Given
|
66
|
+
Given a file named "pending_with_passing_block_spec.rb" with:
|
67
67
|
"""
|
68
68
|
describe "an example" do
|
69
69
|
it "is implemented but waiting" do
|
@@ -73,9 +73,9 @@ Feature: pending examples
|
|
73
73
|
end
|
74
74
|
end
|
75
75
|
"""
|
76
|
-
When I run
|
76
|
+
When I run "spec pending_with_passing_block_spec.rb"
|
77
77
|
Then the exit code should be 256
|
78
78
|
And the stdout should match "1 example, 1 failure"
|
79
79
|
And the stdout should match "FIXED"
|
80
80
|
And the stdout should match "Expected pending 'something else getting finished' to fail. No Error was raised."
|
81
|
-
And the stdout should match "
|
81
|
+
And the stdout should match "pending_with_passing_block_spec.rb:3"
|
@@ -0,0 +1,32 @@
|
|
1
|
+
Feature: run specific examples by line number
|
2
|
+
|
3
|
+
In order to run a single example from command line
|
4
|
+
RSpec allows you to specify the line number of the example(s) to run
|
5
|
+
|
6
|
+
Scenario: --line syntax on single example
|
7
|
+
Given a file named "example_spec.rb" with:
|
8
|
+
"""
|
9
|
+
describe "an example" do
|
10
|
+
it "has not yet been implemented"
|
11
|
+
it "has been implemented" do
|
12
|
+
true
|
13
|
+
end
|
14
|
+
end
|
15
|
+
"""
|
16
|
+
When I run "spec example_spec.rb --line 2"
|
17
|
+
Then the stdout should match "1 example, 0 failures, 1 pending"
|
18
|
+
And the stdout should match "example_spec.rb:2"
|
19
|
+
|
20
|
+
Scenario: colon line syntax on single example
|
21
|
+
Given a file named "example_spec.rb" with:
|
22
|
+
"""
|
23
|
+
describe "an example" do
|
24
|
+
it "has not yet been implemented"
|
25
|
+
it "has been implemented" do
|
26
|
+
true
|
27
|
+
end
|
28
|
+
end
|
29
|
+
"""
|
30
|
+
When I run "spec example_spec.rb:2"
|
31
|
+
Then the stdout should match "1 example, 0 failures, 1 pending"
|
32
|
+
And the stdout should match "example_spec.rb:2"
|
@@ -0,0 +1,41 @@
|
|
1
|
+
Given %r{^a file named "([^"]+)" with:$} do |file_name, code|
|
2
|
+
create_file(file_name, code)
|
3
|
+
end
|
4
|
+
|
5
|
+
|
6
|
+
When %r{^I run "spec ([^"]+)"$} do |file_and_args|
|
7
|
+
spec(file_and_args)
|
8
|
+
end
|
9
|
+
|
10
|
+
When %r{^I run "ruby ([^"]+)"$} do |file_and_args|
|
11
|
+
ruby(file_and_args)
|
12
|
+
end
|
13
|
+
|
14
|
+
When %r{^I run "cmdline.rb ([^"]+)"$} do |file_and_args|
|
15
|
+
cmdline(file_and_args)
|
16
|
+
end
|
17
|
+
|
18
|
+
|
19
|
+
Then /^the (.*) should match (.*)$/ do |stream, string_or_regex|
|
20
|
+
written = case(stream)
|
21
|
+
when 'stdout' then last_stdout
|
22
|
+
when 'stderr' then last_stderr
|
23
|
+
else raise "Unknown stream: #{stream}"
|
24
|
+
end
|
25
|
+
written.should smart_match(string_or_regex)
|
26
|
+
end
|
27
|
+
|
28
|
+
Then /^the (.*) should not match (.*)$/ do |stream, string_or_regex|
|
29
|
+
written = case(stream)
|
30
|
+
when 'stdout' then last_stdout
|
31
|
+
when 'stderr' then last_stderr
|
32
|
+
else raise "Unknown stream: #{stream}"
|
33
|
+
end
|
34
|
+
written.should_not smart_match(string_or_regex)
|
35
|
+
end
|
36
|
+
|
37
|
+
Then /^the exit code should be (\d+)$/ do |exit_code|
|
38
|
+
if last_exit_code != exit_code.to_i
|
39
|
+
raise "Did not exit with #{exit_code}, but with #{last_exit_code}. Standard error:\n#{last_stderr}"
|
40
|
+
end
|
41
|
+
end
|
@@ -3,7 +3,7 @@ Feature: explicit subject
|
|
3
3
|
You can override the implicit subject using the subject() method.
|
4
4
|
|
5
5
|
Scenario: subject in top level group
|
6
|
-
Given
|
6
|
+
Given a file named "top_level_subject_spec.rb" with:
|
7
7
|
"""
|
8
8
|
describe Array, "with some elements" do
|
9
9
|
subject { [1,2,3] }
|
@@ -12,11 +12,11 @@ Feature: explicit subject
|
|
12
12
|
end
|
13
13
|
end
|
14
14
|
"""
|
15
|
-
When I run
|
15
|
+
When I run "spec top_level_subject_spec.rb"
|
16
16
|
Then the stdout should match "1 example, 0 failures"
|
17
17
|
|
18
18
|
Scenario: subject in a nested group
|
19
|
-
Given
|
19
|
+
Given a file named "nested_subject_spec.rb" with:
|
20
20
|
"""
|
21
21
|
describe Array do
|
22
22
|
subject { [1,2,3] }
|
@@ -27,5 +27,5 @@ Feature: explicit subject
|
|
27
27
|
end
|
28
28
|
end
|
29
29
|
"""
|
30
|
-
When I run
|
30
|
+
When I run "spec nested_subject_spec.rb"
|
31
31
|
Then the stdout should match "1 example, 0 failures"
|
@@ -5,7 +5,7 @@ Feature: implicit subject
|
|
5
5
|
that example.
|
6
6
|
|
7
7
|
Scenario: subject in top level group
|
8
|
-
Given
|
8
|
+
Given a file named "top_level_subject_spec.rb" with:
|
9
9
|
"""
|
10
10
|
describe Array, "when first created" do
|
11
11
|
it "should be empty" do
|
@@ -13,11 +13,11 @@ Feature: implicit subject
|
|
13
13
|
end
|
14
14
|
end
|
15
15
|
"""
|
16
|
-
When I run
|
16
|
+
When I run "spec top_level_subject_spec.rb"
|
17
17
|
Then the stdout should match "1 example, 0 failures"
|
18
18
|
|
19
19
|
Scenario: subject in a nested group
|
20
|
-
Given
|
20
|
+
Given a file named "nested_subject_spec.rb" with:
|
21
21
|
"""
|
22
22
|
describe Array do
|
23
23
|
describe "when first created" do
|
@@ -27,5 +27,5 @@ Feature: implicit subject
|
|
27
27
|
end
|
28
28
|
end
|
29
29
|
"""
|
30
|
-
When I run
|
30
|
+
When I run "spec nested_subject_spec.rb"
|
31
31
|
Then the stdout should match "1 example, 0 failures"
|
data/features/support/env.rb
CHANGED
@@ -1,26 +1,79 @@
|
|
1
|
+
$:.unshift File.join(File.dirname(__FILE__), "/../../lib")
|
2
|
+
|
3
|
+
require 'spec/expectations'
|
4
|
+
require 'forwardable'
|
1
5
|
require 'tempfile'
|
2
6
|
require File.dirname(__FILE__) + '/../../spec/ruby_forker'
|
3
7
|
require File.dirname(__FILE__) + '/matchers/smart_match'
|
4
8
|
|
5
|
-
$:.push File.join(File.dirname(__FILE__), "/../../lib")
|
6
|
-
require 'spec/expectations'
|
7
|
-
require 'spec/matchers'
|
8
9
|
|
9
|
-
|
10
|
+
class RspecWorld
|
10
11
|
include Spec::Expectations
|
11
12
|
include Spec::Matchers
|
12
13
|
include RubyForker
|
13
14
|
|
14
|
-
|
15
|
-
|
15
|
+
extend Forwardable
|
16
|
+
def_delegators RspecWorld, :working_dir, :spec_command, :cmdline_file, :rspec_lib
|
17
|
+
|
18
|
+
def self.working_dir
|
19
|
+
@working_dir ||= File.expand_path(File.join(File.dirname(__FILE__), "/../../tmp/cucumber-generated-files"))
|
16
20
|
end
|
17
21
|
|
18
|
-
def
|
19
|
-
|
22
|
+
def self.spec_command
|
23
|
+
@spec_command ||= File.expand_path(File.join(File.dirname(__FILE__), "/../../bin/spec"))
|
20
24
|
end
|
25
|
+
|
26
|
+
def self.cmdline_file
|
27
|
+
@cmdline_file ||= File.expand_path(File.join(File.dirname(__FILE__), "/../../resources/helpers/cmdline.rb"))
|
28
|
+
end
|
29
|
+
|
30
|
+
def self.rspec_lib
|
31
|
+
@rspec_lib ||= File.join(working_dir, "/../../lib")
|
32
|
+
end
|
33
|
+
|
34
|
+
def spec(args)
|
35
|
+
ruby("#{spec_command} #{args}")
|
36
|
+
end
|
37
|
+
|
38
|
+
def cmdline(args)
|
39
|
+
ruby("#{cmdline_file} #{args}")
|
40
|
+
end
|
41
|
+
|
42
|
+
def create_file(file_name, contents)
|
43
|
+
file_path = File.join(working_dir, file_name)
|
44
|
+
File.open(file_path, "w") { |f| f << contents }
|
45
|
+
end
|
46
|
+
|
47
|
+
def last_stdout
|
48
|
+
@stdout
|
49
|
+
end
|
50
|
+
|
51
|
+
def last_stderr
|
52
|
+
@stderr
|
53
|
+
end
|
54
|
+
|
55
|
+
def last_exit_code
|
56
|
+
@exit_code
|
57
|
+
end
|
58
|
+
|
59
|
+
# it seems like this, and the last_* methods, could be moved into RubyForker-- is that being used anywhere but the features?
|
60
|
+
def ruby(args)
|
61
|
+
stderr_file = Tempfile.new('rspec')
|
62
|
+
stderr_file.close
|
63
|
+
Dir.chdir(working_dir) do
|
64
|
+
@stdout = super("-I #{rspec_lib} #{args}", stderr_file.path)
|
65
|
+
end
|
66
|
+
@stderr = IO.read(stderr_file.path)
|
67
|
+
@exit_code = $?.to_i
|
68
|
+
end
|
69
|
+
|
70
|
+
end
|
71
|
+
|
72
|
+
Before do
|
73
|
+
FileUtils.rm_rf RspecWorld.working_dir if test ?d, RspecWorld.working_dir
|
74
|
+
FileUtils.mkdir_p RspecWorld.working_dir
|
21
75
|
end
|
22
76
|
|
23
|
-
World do
|
24
|
-
|
25
|
-
world
|
77
|
+
World do
|
78
|
+
RspecWorld.new
|
26
79
|
end
|
@@ -1,37 +1,12 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
# Satisfy expectation here. Return false or raise an error if it's not met.
|
11
|
-
|
12
|
-
if @expected =~ /^\/.*\/?$/ || @expected =~ /^".*"$/
|
13
|
-
regex_or_string = eval(@expected)
|
14
|
-
if Regexp === regex_or_string
|
15
|
-
(@actual =~ regex_or_string) ? true : false
|
16
|
-
else
|
17
|
-
@actual.index(regex_or_string) != nil
|
18
|
-
end
|
19
|
-
else
|
20
|
-
false
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
def failure_message
|
25
|
-
"expected #{@actual} to smart_match #{@expected}"
|
26
|
-
end
|
27
|
-
|
28
|
-
def negative_failure_message
|
29
|
-
"expected #{@actual} not to smart_match #{@expected}"
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
def smart_match(expected)
|
34
|
-
SmartMatch.new(expected)
|
1
|
+
Spec::Matchers.define :smart_match do |expected|
|
2
|
+
match do |actual|
|
3
|
+
case expected
|
4
|
+
when /^\/.*\/?$/
|
5
|
+
actual =~ eval(expected)
|
6
|
+
when /^".*"$/
|
7
|
+
actual.index(eval(expected))
|
8
|
+
else
|
9
|
+
false
|
35
10
|
end
|
36
11
|
end
|
37
|
-
end
|
12
|
+
end
|