rspec-core 2.6.4 → 2.7.0.rc1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (107) hide show
  1. data/README.md +1 -1
  2. data/{bin → exe}/autospec +0 -0
  3. data/{bin → exe}/rspec +0 -0
  4. data/features/Upgrade.md +11 -0
  5. data/features/command_line/exit_status.feature +20 -3
  6. data/features/command_line/format_option.feature +8 -0
  7. data/features/command_line/line_number_appended_to_path.feature +35 -1
  8. data/features/command_line/line_number_option.feature +16 -3
  9. data/features/command_line/pattern_option.feature +31 -0
  10. data/features/command_line/rake_task.feature +1 -1
  11. data/features/command_line/ruby.feature +22 -0
  12. data/features/configuration/default_path.feature +38 -0
  13. data/features/example_groups/{shared_example_group.feature → shared_examples.feature} +49 -26
  14. data/features/expectation_framework_integration/configure_expectation_framework.feature +1 -1
  15. data/features/filtering/inclusion_filters.feature +4 -5
  16. data/features/formatters/text_formatter.feature +16 -13
  17. data/features/helper_methods/let.feature +4 -4
  18. data/features/hooks/around_hooks.feature +1 -1
  19. data/features/hooks/before_and_after_hooks.feature +3 -3
  20. data/features/hooks/filtering.feature +13 -6
  21. data/features/metadata/user_defined.feature +12 -10
  22. data/features/pending/pending_examples.feature +21 -8
  23. data/features/step_definitions/additional_cli_steps.rb +1 -1
  24. data/features/subject/attribute_of_subject.feature +2 -2
  25. data/features/support/env.rb +1 -2
  26. data/lib/rspec/core.rb +1 -23
  27. data/lib/rspec/core/configuration.rb +64 -16
  28. data/lib/rspec/core/configuration_options.rb +11 -4
  29. data/lib/rspec/core/example.rb +10 -7
  30. data/lib/rspec/core/example_group.rb +34 -18
  31. data/lib/rspec/core/formatters/base_text_formatter.rb +10 -2
  32. data/lib/rspec/core/formatters/html_formatter.rb +3 -1
  33. data/lib/rspec/core/formatters/snippet_extractor.rb +9 -3
  34. data/lib/rspec/core/formatters/text_mate_formatter.rb +20 -6
  35. data/lib/rspec/core/hooks.rb +2 -2
  36. data/lib/rspec/core/let.rb +5 -5
  37. data/lib/rspec/core/metadata.rb +136 -94
  38. data/lib/rspec/core/option_parser.rb +10 -5
  39. data/lib/rspec/core/pending.rb +2 -1
  40. data/lib/rspec/core/rake_task.rb +26 -15
  41. data/lib/rspec/core/reporter.rb +2 -3
  42. data/lib/rspec/core/runner.rb +1 -1
  43. data/lib/rspec/core/shared_example_group.rb +4 -4
  44. data/lib/rspec/core/subject.rb +7 -7
  45. data/lib/rspec/core/version.rb +1 -1
  46. data/lib/rspec/core/world.rb +4 -8
  47. data/spec/autotest/discover_spec.rb +2 -2
  48. data/spec/autotest/failed_results_re_spec.rb +29 -21
  49. data/spec/autotest/rspec_spec.rb +3 -3
  50. data/spec/rspec/core/command_line_spec.rb +1 -6
  51. data/spec/rspec/core/configuration_options_spec.rb +65 -13
  52. data/spec/rspec/core/configuration_spec.rb +148 -37
  53. data/spec/rspec/core/deprecations_spec.rb +2 -2
  54. data/spec/rspec/core/drb_command_line_spec.rb +6 -6
  55. data/spec/rspec/core/example_group_spec.rb +197 -61
  56. data/spec/rspec/core/example_spec.rb +33 -16
  57. data/spec/rspec/core/formatters/base_formatter_spec.rb +3 -3
  58. data/spec/rspec/core/formatters/base_text_formatter_spec.rb +149 -1
  59. data/spec/rspec/core/formatters/helpers_spec.rb +8 -8
  60. data/spec/rspec/core/formatters/html_formatted-1.8.7-jruby.html +85 -17
  61. data/spec/rspec/core/formatters/html_formatted-1.8.7.html +12 -11
  62. data/spec/rspec/core/formatters/html_formatted-1.9.2.html +12 -11
  63. data/spec/rspec/core/formatters/{html_formatted-1.9.1.html → html_formatted-1.9.3.html} +12 -11
  64. data/spec/rspec/core/formatters/html_formatter_spec.rb +5 -5
  65. data/spec/rspec/core/formatters/progress_formatter_spec.rb +2 -2
  66. data/spec/rspec/core/formatters/snippet_extractor_spec.rb +2 -2
  67. data/spec/rspec/core/formatters/text_mate_formatted-1.8.7-jruby.html +86 -18
  68. data/spec/rspec/core/formatters/text_mate_formatted-1.8.7.html +13 -12
  69. data/spec/rspec/core/formatters/text_mate_formatted-1.9.2.html +29 -28
  70. data/spec/rspec/core/formatters/{text_mate_formatted-1.9.1.html → text_mate_formatted-1.9.3.html} +29 -28
  71. data/spec/rspec/core/formatters/text_mate_formatter_spec.rb +2 -2
  72. data/spec/rspec/core/hooks_filtering_spec.rb +18 -18
  73. data/spec/rspec/core/let_spec.rb +19 -6
  74. data/spec/rspec/core/metadata_spec.rb +146 -61
  75. data/spec/rspec/core/pending_example_spec.rb +4 -4
  76. data/spec/rspec/core/rake_task_spec.rb +71 -50
  77. data/spec/rspec/core/reporter_spec.rb +2 -2
  78. data/spec/rspec/core/ruby_project_spec.rb +2 -2
  79. data/spec/rspec/core/runner_spec.rb +4 -1
  80. data/spec/rspec/core/shared_example_group_spec.rb +15 -119
  81. data/spec/rspec/core/subject_spec.rb +13 -13
  82. data/spec/rspec/core/world_spec.rb +31 -22
  83. data/spec/rspec/core_spec.rb +1 -29
  84. data/spec/spec_helper.rb +51 -49
  85. data/spec/support/shared_example_groups.rb +3 -3
  86. data/spec/support/spec_files.rb +8 -8
  87. metadata +79 -93
  88. data/.document +0 -5
  89. data/.gitignore +0 -12
  90. data/.rspec +0 -0
  91. data/.travis.yml +0 -9
  92. data/Changelog.md +0 -305
  93. data/Gemfile +0 -49
  94. data/Guardfile +0 -5
  95. data/License.txt +0 -23
  96. data/Rakefile +0 -93
  97. data/cucumber.yml +0 -2
  98. data/features/.nav +0 -57
  99. data/rspec-core.gemspec +0 -24
  100. data/script/FullBuildRakeFile +0 -63
  101. data/script/console +0 -8
  102. data/script/cucumber +0 -1
  103. data/script/full_build +0 -1
  104. data/script/spec +0 -1
  105. data/spec.txt +0 -1126
  106. data/spec/rspec/core/formatters/html_formatted-1.8.6.html +0 -398
  107. data/spec/rspec/core/formatters/text_mate_formatted-1.8.6.html +0 -398
data/README.md CHANGED
@@ -3,7 +3,7 @@
3
3
  RSpec Core provides the structure for writing executable examples of how your
4
4
  code should behave.
5
5
 
6
- [![build status](http://travis-ci.org/rspec/rspec-core.png)](http://travis-ci.org/rspec/rspec-core)
6
+ [![build status](https://secure.travis-ci.org/rspec/rspec-core.png)](http://travis-ci.org/rspec/rspec-core)
7
7
 
8
8
  ## Documentation
9
9
 
File without changes
File without changes
@@ -1,3 +1,14 @@
1
+ # rspec-core-2.7 (not yet released - coming soon)
2
+
3
+ ## `--default_path`
4
+
5
+ Add the following to `.rspec`:
6
+
7
+ # in .rspec
8
+ --default_path spec
9
+
10
+ And now you can just type `rspec` to run all the specs in the `spec` directory.
11
+
1
12
  # rspec-core-2.6
2
13
 
3
14
  ## new APIs for sharing content
@@ -1,7 +1,7 @@
1
1
  Feature: exit status
2
2
 
3
- In order to fail the build when it should, the spec CLI exits with an
4
- appropriate exit status
3
+ The rspec command exits with an exit status of 0 if all examples pass,
4
+ and 1 if any examples fail.
5
5
 
6
6
  Scenario: exit with 0 when all examples pass
7
7
  Given a file named "ok_spec.rb" with:
@@ -42,7 +42,7 @@ Feature: exit status
42
42
  When I run `rspec nested_ko_spec.rb`
43
43
  Then the exit status should be 1
44
44
  And the output should contain "1 example, 1 failure"
45
-
45
+
46
46
  Scenario: exit with 0 when no examples are run
47
47
  Given a file named "a_no_examples_spec.rb" with:
48
48
  """
@@ -50,3 +50,20 @@ Feature: exit status
50
50
  When I run `rspec a_no_examples_spec.rb`
51
51
  Then the exit status should be 0
52
52
  And the output should contain "0 examples"
53
+
54
+ @wip
55
+ Scenario: exit with rspec's exit code when an at_exit hook is added upstream
56
+ Given a file named "exit_at_spec.rb" with:
57
+ """
58
+ require 'rspec/autorun'
59
+
60
+ describe "exit 0 at_exit" do
61
+ it "does not interfere with rspec's exit code" do
62
+ at_exit { exit 0 }
63
+ fail
64
+ end
65
+ end
66
+ """
67
+ When I run `rspec exit_at_spec.rb`
68
+ Then the exit status should be 1
69
+ And the output should contain "1 example, 1 failure"
@@ -19,6 +19,14 @@ Feature: --format option
19
19
 
20
20
  $ rspec spec --format documentation:rspec.output.txt
21
21
 
22
+ `rspec --help` lists available formatters:
23
+
24
+ [p]rogress (default - dots)
25
+ [d]ocumentation (group and example names)
26
+ [h]tml
27
+ [t]extmate
28
+ custom formatter class name
29
+
22
30
  Background:
23
31
  Given a file named "example_spec.rb" with:
24
32
  """
@@ -1,6 +1,6 @@
1
1
  Feature: line number appended to file path
2
2
 
3
- To run a single example or group, you can append the line number to the path, e.g.
3
+ To run one or more examples or groups, you can append the line number to the path, e.g.
4
4
 
5
5
  rspec path/to/example_spec.rb:37
6
6
 
@@ -27,6 +27,15 @@ Feature: line number appended to file path
27
27
 
28
28
  end
29
29
  """
30
+ And a file named "example2_spec.rb" with:
31
+ """
32
+ describe "yet another group" do
33
+ it "first example in second file" do
34
+ end
35
+ it "second example in second file" do
36
+ end
37
+ end
38
+ """
30
39
 
31
40
  Scenario: nested groups - outer group on declaration line
32
41
  When I run `rspec example_spec.rb:1 --format doc`
@@ -104,3 +113,28 @@ Feature: line number appended to file path
104
113
  And the output should contain "second example in outer group"
105
114
  But the output should not contain "first example in outer group"
106
115
  And the output should not contain "example in nested group"
116
+
117
+ Scenario: specified multiple times for different files
118
+ When I run `rspec example_spec.rb:7 example2_spec.rb:4 --format doc`
119
+ Then the examples should all pass
120
+ And the output should contain "second example in outer group"
121
+ And the output should contain "second example in second file"
122
+ But the output should not contain "first example in outer group"
123
+ And the output should not contain "nested group"
124
+ And the output should not contain "first example in second file"
125
+
126
+ Scenario: specified multiple times for the same file with multiple arguments
127
+ When I run `rspec example_spec.rb:7 example_spec.rb:11 --format doc`
128
+ Then the examples should all pass
129
+ And the output should contain "second example in outer group"
130
+ And the output should contain "nested group"
131
+ But the output should not contain "first example in outer group"
132
+ And the output should not contain "second file"
133
+
134
+ Scenario: specified multiple times for the same file with a single argument
135
+ When I run `rspec example_spec.rb:7:11 --format doc`
136
+ Then the examples should all pass
137
+ And the output should contain "second example in outer group"
138
+ And the output should contain "nested group"
139
+ But the output should not contain "first example in outer group"
140
+ And the output should not contain "second file"
@@ -1,9 +1,11 @@
1
1
  Feature: --line_number option
2
2
 
3
- To run a single example or group, you can use the --line_number option:
3
+ To run a examples or groups by line numbers, one can use the --line_number option:
4
4
 
5
5
  rspec path/to/example_spec.rb --line_number 37
6
6
 
7
+ This option can be specified multiple times.
8
+
7
9
  Scenario: standard examples
8
10
  Given a file named "example_spec.rb" with:
9
11
  """
@@ -18,13 +20,24 @@ Feature: --line_number option
18
20
  it "should be < 10" do
19
21
  9.should be < 10
20
22
  end
21
-
23
+
24
+ it "should be 3 squared" do
25
+ 9.should be 3*3
26
+ end
27
+
22
28
  end
23
29
  """
24
30
  When I run `rspec example_spec.rb --line_number 5 --format doc`
25
31
  Then the examples should all pass
26
- Then the output should contain "should be > 8"
32
+ And the output should contain "should be > 8"
27
33
  But the output should not contain "should be < 10"
34
+ And the output should not contain "should be 3*3"
35
+
36
+ When I run `rspec example_spec.rb --line_number 5 --line_number 9 --format doc`
37
+ Then the examples should all pass
38
+ And the output should contain "should be > 8"
39
+ And the output should contain "should be < 10"
40
+ But the output should not contain "should be 3*3"
28
41
 
29
42
  Scenario: one liner
30
43
  Given a file named "example_spec.rb" with:
@@ -0,0 +1,31 @@
1
+ Feature: pattern option
2
+
3
+ By default, RSpec loads files matching the pattern:
4
+
5
+ "spec/**/*_spec.rb"
6
+
7
+ Use the `--pattern` option to declare a different pattern.
8
+
9
+ Scenario: default pattern
10
+ Given a file named "spec/example_spec.rb" with:
11
+ """
12
+ describe "addition" do
13
+ it "adds things" do
14
+ (1 + 2).should eq(3)
15
+ end
16
+ end
17
+ """
18
+ When I run `rspec`
19
+ Then the output should contain "1 example, 0 failures"
20
+
21
+ Scenario: override the default pattern on the command line
22
+ Given a file named "spec/example.spec" with:
23
+ """
24
+ describe "addition" do
25
+ it "adds things" do
26
+ (1 + 2).should eq(3)
27
+ end
28
+ end
29
+ """
30
+ When I run `rspec --pattern "spec/**/*.spec"`
31
+ Then the output should contain "1 example, 0 failures"
@@ -20,7 +20,7 @@ Feature: rake task
20
20
  end
21
21
  """
22
22
  When I run `rake`
23
- Then the stderr should contain "ruby -S rspec"
23
+ Then the output should contain "ruby -S rspec"
24
24
  Then the exit status should be 0
25
25
 
26
26
  Scenario: default options with failing spec (exit status is 1)
@@ -0,0 +1,22 @@
1
+ Feature: run with ruby command
2
+
3
+ You can use the `ruby` command to run specs. You just need to require
4
+ `rspec/autorun`.
5
+
6
+ Generally speaking, you're better off using the `rspec` command, which
7
+ requires `rspec/autorun` for you, but some tools only work with the `ruby`
8
+ command.
9
+
10
+ Scenario:
11
+ Given a file named "example_spec.rb" with:
12
+ """
13
+ require 'rspec/autorun'
14
+
15
+ describe 1 do
16
+ it "is < 2" do
17
+ 1.should be < 2
18
+ end
19
+ end
20
+ """
21
+ When I run `ruby example_spec.rb`
22
+ Then the output should contain "1 example, 0 failures"
@@ -0,0 +1,38 @@
1
+ Feature: default_path
2
+
3
+ As of rspec-2.7 (not yet released), you can just type `rspec` to run all
4
+ specs that live in the `spec` directory.
5
+
6
+ This is supported by a `--default_path` option, which is set to `spec` by
7
+ default. If you prefer to keep your specs in a different directory, or assign
8
+ an individual file to `--default_path`, you can do so on the command line or
9
+ in a configuration file (`.rspec`, `~/.rspec`, or a custom file).
10
+
11
+ NOTE: this option is not supported on `RSpec.configuration`, as it needs to
12
+ be set before spec files are loaded.
13
+
14
+ Scenario: run `rspec` with default default_path (`spec` directory)
15
+ Given a file named "spec/example_spec.rb" with:
16
+ """
17
+ describe "an example" do
18
+ it "passes" do
19
+ end
20
+ end
21
+ """
22
+ When I run `rspec`
23
+ Then the output should contain "1 example, 0 failures"
24
+
25
+ Scenario: run `rspec` with customized default_path
26
+ Given a file named ".rspec" with:
27
+ """
28
+ --default_path behavior
29
+ """
30
+ Given a file named "behavior/example_spec.rb" with:
31
+ """
32
+ describe "an example" do
33
+ it "passes" do
34
+ end
35
+ end
36
+ """
37
+ When I run `rspec`
38
+ Then the output should contain "1 example, 0 failures"
@@ -8,47 +8,70 @@ Feature: shared examples
8
8
  A shared group is included in another group using any of:
9
9
 
10
10
  include_examples "name" # include the examples in the current context
11
-
12
11
  it_behaves_like "name" # include the examples in a nested context
13
12
  it_should_behave_like "name" # include the examples in a nested context
14
13
 
15
- Scenario: shared examples group included in two groups
14
+ WARNING: Files containing shared groups must be loaded before the files that
15
+ use them. While there are conventions to handle this, RSpec does _not_ do
16
+ anything special (like autoload). Doing so would require a strict naming
17
+ convention for files that would break existing suites.
18
+
19
+ CONVENTIONS:
20
+
21
+ 1. The simplest approach is to require files with shared examples explicitly
22
+ from the files that use them. Keep in mind that RSpec adds the `spec`
23
+ directory to the `LOAD_PATH`, so you can say `require
24
+ 'shared_examples_for_widgets'` to require a file at
25
+ `#{PROJECT_ROOT}/spec/shared_examples_for_widgets.rb`.
26
+
27
+ 2. Put files containing shared examples in `spec/support/` and require files
28
+ in that directory from `spec/spec_helper.rb`:
29
+
30
+ Dir["spec/support/**/*.rb"].each {|f| require f}
31
+
32
+ This is included in the generated `spec/spec_helper.rb` file in
33
+ `rspec-rails`
34
+
35
+ 3. When all of the groups that include the shared group, just declare
36
+ the shared group in the same file.
37
+
38
+ Scenario: shared examples group included in two groups in one file
16
39
  Given a file named "collection_spec.rb" with:
17
- """
18
- require "set"
40
+ """
41
+ require "set"
19
42
 
20
- shared_examples "a collection" do
21
- let(:collection) { described_class.new([7, 2, 4]) }
43
+ shared_examples "a collection" do
44
+ let(:collection) { described_class.new([7, 2, 4]) }
22
45
 
23
- context "initialized with 3 items" do
24
- it "says it has three items" do
25
- collection.size.should eq(3)
46
+ context "initialized with 3 items" do
47
+ it "says it has three items" do
48
+ collection.size.should eq(3)
49
+ end
26
50
  end
27
- end
28
51
 
29
- describe "#include?" do
30
- context "with an an item that is in the collection" do
31
- it "returns true" do
32
- collection.include?(7).should be_true
52
+ describe "#include?" do
53
+ context "with an an item that is in the collection" do
54
+ it "returns true" do
55
+ collection.include?(7).should be_true
56
+ end
33
57
  end
34
- end
35
58
 
36
- context "with an an item that is not in the collection" do
37
- it "returns false" do
38
- collection.include?(9).should be_false
59
+ context "with an an item that is not in the collection" do
60
+ it "returns false" do
61
+ collection.include?(9).should be_false
62
+ end
39
63
  end
40
64
  end
41
65
  end
42
- end
43
66
 
44
- describe Array do
45
- it_behaves_like "a collection"
46
- end
67
+ describe Array do
68
+ it_behaves_like "a collection"
69
+ end
47
70
 
48
- describe Set do
49
- it_behaves_like "a collection"
50
- end
51
- """
71
+ describe Set do
72
+ it_behaves_like "a collection"
73
+ end
74
+ """
52
75
  When I run `rspec collection_spec.rb --format documentation`
53
76
  Then the examples should all pass
54
77
  And the output should contain:
@@ -64,7 +64,7 @@ Feature: configure expectation framework
64
64
  assert 5 > 4, "expected 5 to be greater than 4"
65
65
  end
66
66
 
67
- it "is less than 4" do
67
+ it "is less than 6" do
68
68
  5.should be < 6
69
69
  end
70
70
  end
@@ -1,18 +1,17 @@
1
1
  Feature: inclusion filters
2
2
 
3
- You can restrict which examples are run by declaring an inclusion filter. The
3
+ You can constrain which examples are run by declaring an inclusion filter. The
4
4
  most common use case is to focus on a subset of examples as you're focused on
5
5
  a particular problem.
6
6
 
7
- If you set the `treat_symbols_as_metadata_keys_with_true_values` config option
8
- to `true`, you can specify metadata using only symbols.
7
+ You can specify metadata using only symbols if you set the
8
+ `treat_symbols_as_metadata_keys_with_true_values` config option to `true`.
9
9
 
10
10
  Background:
11
11
  Given a file named "spec/spec_helper.rb" with:
12
12
  """
13
13
  RSpec.configure do |c|
14
- # filter_run is short-form alias for filter_run_including
15
- c.filter_run :focus => true
14
+ c.filter_run_including :focus => true
16
15
  end
17
16
  """
18
17
 
@@ -9,35 +9,38 @@ Feature: text formatter
9
9
  """
10
10
  describe String do
11
11
  it "has a failing example" do
12
- "foo".reverse.should == "ofo"
12
+ "foo".reverse.should eq("ofo")
13
13
  end
14
14
  end
15
15
  """
16
16
  And a file named "integer_spec.rb" with:
17
17
  """
18
- require 'rspec/autorun'
19
-
20
18
  describe Integer do
21
19
  it "has a failing example" do
22
- (7 + 5).should == 11
20
+ (7 + 5).should eq(11)
23
21
  end
24
22
  end
25
23
  """
26
- When I run `ruby ./integer_spec.rb ./string_spec.rb`
24
+ When I run `rspec integer_spec.rb string_spec.rb`
27
25
  Then the backtrace-normalized output should contain:
28
26
  """
29
27
  Failures:
30
-
28
+
31
29
  1) Integer has a failing example
32
- Failure/Error: (7 + 5).should == 11
30
+ Failure/Error: (7 + 5).should eq(11)
31
+
33
32
  expected: 11
34
- got: 12 (using ==)
35
- # ./integer_spec.rb:5
36
-
33
+ got: 12
34
+
35
+ (compared using ==)
36
+ # ./integer_spec.rb:3
37
+
37
38
  2) String has a failing example
38
- Failure/Error: "foo".reverse.should == "ofo"
39
+ Failure/Error: "foo".reverse.should eq("ofo")
40
+
39
41
  expected: "ofo"
40
- got: "oof" (using ==)
42
+ got: "oof"
43
+
44
+ (compared using ==)
41
45
  # ./string_spec.rb:3
42
46
  """
43
-