rspec-core 2.0.0.beta.22 → 2.0.0.rc

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.
Files changed (67) hide show
  1. data/Gemfile +2 -2
  2. data/{History.md → History.markdown} +24 -2
  3. data/Rakefile +1 -0
  4. data/Upgrade.markdown +36 -3
  5. data/bin/rspec +1 -2
  6. data/features/command_line/configure.feature +4 -4
  7. data/features/command_line/example_name_option.feature +17 -3
  8. data/features/command_line/exit_status.feature +13 -28
  9. data/features/command_line/line_number_appended_to_path.feature +12 -16
  10. data/features/command_line/line_number_option.feature +4 -5
  11. data/features/command_line/rake_task.feature +68 -0
  12. data/features/configuration/custom_settings.feature +2 -4
  13. data/features/configuration/fail_fast.feature +77 -0
  14. data/features/configuration/read_options_from_file.feature +2 -5
  15. data/features/example_groups/basic_structure.feature +54 -0
  16. data/features/example_groups/shared_example_group.feature +38 -27
  17. data/features/filtering/exclusion_filters.feature +40 -4
  18. data/features/filtering/inclusion_filters.feature +36 -27
  19. data/features/filtering/run_all_when_everything_filtered.feature +46 -0
  20. data/features/hooks/before_and_after_hooks.feature +21 -1
  21. data/features/pending/pending_examples.feature +24 -5
  22. data/lib/rspec/autorun.rb +2 -0
  23. data/lib/rspec/core.rb +6 -4
  24. data/lib/rspec/core/configuration.rb +69 -23
  25. data/lib/rspec/core/configuration_options.rb +1 -0
  26. data/lib/rspec/core/example.rb +0 -1
  27. data/lib/rspec/core/example_group.rb +23 -8
  28. data/lib/rspec/core/formatters/base_formatter.rb +14 -4
  29. data/lib/rspec/core/formatters/base_text_formatter.rb +2 -0
  30. data/lib/rspec/core/formatters/documentation_formatter.rb +2 -0
  31. data/lib/rspec/core/formatters/progress_formatter.rb +1 -0
  32. data/lib/rspec/core/metadata.rb +18 -11
  33. data/lib/rspec/core/option_parser.rb +6 -1
  34. data/lib/rspec/core/rake_task.rb +10 -10
  35. data/lib/rspec/core/runner.rb +20 -1
  36. data/lib/rspec/core/subject.rb +26 -3
  37. data/lib/rspec/core/version.rb +1 -1
  38. data/lib/rspec/core/world.rb +2 -1
  39. data/spec/autotest/failed_results_re_spec.rb +1 -1
  40. data/spec/rspec/core/configuration_spec.rb +13 -0
  41. data/spec/rspec/core/example_group_spec.rb +107 -26
  42. data/spec/rspec/core/example_spec.rb +11 -24
  43. data/spec/rspec/core/formatters/base_formatter_spec.rb +17 -1
  44. data/spec/rspec/core/formatters/base_text_formatter_spec.rb +6 -5
  45. data/spec/rspec/core/formatters/documentation_formatter_spec.rb +3 -2
  46. data/spec/rspec/core/formatters/html_formatted-1.8.7-jruby.html +25 -22
  47. data/spec/rspec/core/formatters/html_formatted-1.8.7.html +23 -20
  48. data/spec/rspec/core/formatters/html_formatted-1.9.1.html +25 -22
  49. data/spec/rspec/core/formatters/html_formatted-1.9.2.html +25 -2
  50. data/spec/rspec/core/formatters/html_formatter_spec.rb +10 -2
  51. data/spec/rspec/core/formatters/progress_formatter_spec.rb +1 -0
  52. data/spec/rspec/core/formatters/text_mate_formatter_spec.rb +1 -0
  53. data/spec/rspec/core/hooks_filtering_spec.rb +5 -5
  54. data/spec/rspec/core/hooks_spec.rb +4 -4
  55. data/spec/rspec/core/metadata_spec.rb +20 -0
  56. data/spec/rspec/core/option_parser_spec.rb +16 -0
  57. data/spec/rspec/core/rake_task_spec.rb +0 -1
  58. data/spec/rspec/core/reporter_spec.rb +1 -1
  59. data/spec/rspec/core/runner_spec.rb +18 -0
  60. data/spec/rspec/core/shared_example_group_spec.rb +2 -2
  61. data/spec/spec_helper.rb +14 -3
  62. metadata +54 -45
  63. data/.rspec +0 -1
  64. data/features/example_groups/describe_aliases.feature +0 -25
  65. data/features/example_groups/nested_groups.feature +0 -44
  66. data/lib/rspec/core/around_proxy.rb +0 -14
  67. data/lib/rspec/core/formatters.rb +0 -8
@@ -1,10 +1,8 @@
1
1
  Feature: custom settings
2
2
 
3
- In order to seamlessly provide users more configuration settings
4
- As an RSpec extenstion-library author
5
- I want to define new settings on the RSpec.configuration object
3
+ Extensions like rspec-rails can add their own configuration settings.
6
4
 
7
- Scenario: simple setting
5
+ Scenario: simple setting (with defaults)
8
6
  Given a file named "additional_setting_spec.rb" with:
9
7
  """
10
8
  RSpec.configure do |c|
@@ -0,0 +1,77 @@
1
+ Feature: fail fast
2
+
3
+ Use the fail_fast option to tell RSpec to abort the run on first failure.
4
+
5
+ RSpec.configure {|c| c.fail_fast = true}
6
+
7
+ Background:
8
+ Given a file named "spec/spec_helper.rb" with:
9
+ """
10
+ RSpec.configure {|c| c.fail_fast = true}
11
+ """
12
+
13
+ Scenario: fail_fast with no failures (runs all examples)
14
+ Given a file named "spec/example_spec.rb" with:
15
+ """
16
+ describe "something" do
17
+ it "passes" do
18
+ end
19
+
20
+ it "passes too" do
21
+ end
22
+ end
23
+ """
24
+ When I run "rspec spec/example_spec.rb"
25
+ Then the output should contain "2 examples, 0 failures"
26
+
27
+ Scenario: fail_fast with first example failing (only runs the one example)
28
+ Given a file named "spec/example_spec.rb" with:
29
+ """
30
+ require "spec_helper"
31
+ describe "something" do
32
+ it "fails" do
33
+ fail
34
+ end
35
+
36
+ it "passes" do
37
+ end
38
+ end
39
+ """
40
+ When I run "rspec spec/example_spec.rb -fd"
41
+ Then the output should contain "1 example, 1 failure"
42
+
43
+ Scenario: fail_fast with multiple files, second example failing (only runs the first two examples)
44
+ Given a file named "spec/example_1_spec.rb" with:
45
+ """
46
+ require "spec_helper"
47
+ describe "something" do
48
+ it "passes" do
49
+ end
50
+
51
+ it "fails" do
52
+ fail
53
+ end
54
+ end
55
+
56
+ describe "something else" do
57
+ it "fails" do
58
+ fail
59
+ end
60
+ end
61
+ """
62
+ And a file named "spec/example_2_spec.rb" with:
63
+ """
64
+ require "spec_helper"
65
+ describe "something" do
66
+ it "passes" do
67
+ end
68
+ end
69
+
70
+ describe "something else" do
71
+ it "fails" do
72
+ fail
73
+ end
74
+ end
75
+ """
76
+ When I run "rspec spec"
77
+ Then the output should contain "2 examples, 1 failure"
@@ -1,7 +1,7 @@
1
1
  Feature: read command line configuration options from files
2
2
 
3
- RSpec will read command line configuration options from files in
4
- two different locations:
3
+ RSpec reads command line configuration options from files in two different
4
+ locations:
5
5
 
6
6
  Local: "./.rspec" (i.e. in the project's root directory)
7
7
  Global: "~/.rspec" (i.e. in the user's home directory)
@@ -9,9 +9,6 @@ Feature: read command line configuration options from files
9
9
  Options declared in the local file override those in the global file, while
10
10
  those declared in RSpec.configure will override any ".rspec" file.
11
11
 
12
- NOTE: For backwards compatibility with rspec-1, you can write command line
13
- options in a "spec/spec.opts" file and it will be loaded automatically.
14
-
15
12
  Scenario: color set in .rspec
16
13
  Given a file named ".rspec" with:
17
14
  """
@@ -0,0 +1,54 @@
1
+ Feature: basic structure
2
+
3
+ RSpec provides a DSL for creating executable examples of how code is expected
4
+ to behave, organized in groups. It uses the words "describe" and "it" so we can
5
+ express concepts like a conversation:
6
+
7
+ "Describe an account when it is first opened."
8
+ "It has a balance of zero."
9
+
10
+ Use the describe() method to declare an example group. This defines a
11
+ subclass of RSpec's ExampleGroup class. Within a group, you can declare
12
+ nested groups using the describe() or context() methods.
13
+
14
+ Use the it() method to declare an example. This, effectively, defines a
15
+ method that is run in an instance of the group in which it is declared.
16
+
17
+ Scenario: one group, one example
18
+ Given a file named "sample_spec.rb" with:
19
+ """
20
+ describe "something" do
21
+ it "does something" do
22
+ end
23
+ end
24
+ """
25
+ When I run "rspec sample_spec.rb -fn"
26
+ Then the output should contain:
27
+ """
28
+ something
29
+ does something
30
+ """
31
+
32
+ Scenario: nested example groups (using context)
33
+ Given a file named "nested_example_groups_spec.rb" with:
34
+ """
35
+ describe "something" do
36
+ context "in one context" do
37
+ it "does one thing" do
38
+ end
39
+ end
40
+ context "in another context" do
41
+ it "does another thing" do
42
+ end
43
+ end
44
+ end
45
+ """
46
+ When I run "rspec nested_example_groups_spec.rb -fdoc"
47
+ Then the output should contain:
48
+ """
49
+ something
50
+ in one context
51
+ does one thing
52
+ in another context
53
+ does another thing
54
+ """
@@ -1,64 +1,76 @@
1
1
  Feature: Shared example group
2
2
 
3
- As an RSpec user
4
- I want to share my examples
5
- In order to reduce duplication in my specs
3
+ Shared example groups let you describe behaviour of types or modules. When
4
+ declared, a shared group's content is stored. It is only realized in the
5
+ context of another example group, which provides any context the shared group
6
+ needs to run.
6
7
 
7
- Scenario: Using a shared example group
8
- Given a file named "shared_example_group_spec.rb" with:
8
+ A shared group is included in another group using the it_behaves_like() or
9
+ it_should_behave_like() methods.
10
+
11
+ Scenario: shared example group applied to two groups
12
+ Given a file named "collection_spec.rb" with:
9
13
  """
10
14
  require "set"
11
15
 
12
- shared_examples_for "a collection object" do
13
- before(:each) do
14
- @instance = described_class.new([7, 2, 4])
15
- end
16
+ shared_examples_for "a collection" do
17
+ let(:collection) { described_class.new([7, 2, 4]) }
16
18
 
17
19
  context "initialized with 3 items" do
18
- it "has three items" do
19
- @instance.size.should == 3
20
+ it "says it has three items" do
21
+ collection.size.should eq(3)
20
22
  end
21
23
  end
22
24
 
23
25
  describe "#include?" do
24
- context "with an an item in the collection" do
26
+ context "with an an item that is in the collection" do
25
27
  it "returns true" do
26
- @instance.include?(7).should be_true
28
+ collection.include?(7).should be_true
29
+ end
30
+ end
31
+
32
+ context "with an an item that is not in the collection" do
33
+ it "returns false" do
34
+ collection.include?(9).should be_false
27
35
  end
28
36
  end
29
37
  end
30
38
  end
31
39
 
32
40
  describe Array do
33
- it_should_behave_like "a collection object"
41
+ it_behaves_like "a collection"
34
42
  end
35
43
 
36
44
  describe Set do
37
- it_should_behave_like "a collection object"
45
+ it_behaves_like "a collection"
38
46
  end
39
47
  """
40
- When I run "rspec shared_example_group_spec.rb --format documentation"
41
- Then the output should contain "4 examples, 0 failures"
48
+ When I run "rspec collection_spec.rb --format documentation"
49
+ Then the output should contain "6 examples, 0 failures"
42
50
  And the output should contain:
43
51
  """
44
52
  Array
45
- it should behave like a collection object
53
+ behaves like a collection
46
54
  initialized with 3 items
47
- has three items
55
+ says it has three items
48
56
  #include?
49
- with an an item in the collection
57
+ with an an item that is in the collection
50
58
  returns true
59
+ with an an item that is not in the collection
60
+ returns false
51
61
 
52
62
  Set
53
- it should behave like a collection object
63
+ behaves like a collection
54
64
  initialized with 3 items
55
- has three items
65
+ says it has three items
56
66
  #include?
57
- with an an item in the collection
67
+ with an an item that is in the collection
58
68
  returns true
69
+ with an an item that is not in the collection
70
+ returns false
59
71
  """
60
72
 
61
- Scenario: Using a shared example group with a block
73
+ Scenario: Providing context to a shared group using a block
62
74
  Given a file named "shared_example_group_spec.rb" with:
63
75
  """
64
76
  require "set"
@@ -100,7 +112,6 @@ Feature: Shared example group
100
112
  adds objects to the end of the collection
101
113
  """
102
114
 
103
- @wip
104
115
  Scenario: Passing parameters to a shared example group
105
116
  Given a file named "shared_example_group_params_spec.rb" with:
106
117
  """
@@ -145,7 +156,7 @@ Feature: Shared example group
145
156
  end
146
157
 
147
158
  shared_examples_for 'sortability' do
148
- it 'responds to <==>' do
159
+ it 'responds to <=>' do
149
160
  sortable.should respond_to(:<=>)
150
161
  end
151
162
  end
@@ -162,5 +173,5 @@ Feature: Shared example group
162
173
  """
163
174
  String
164
175
  has behavior: sortability
165
- responds to <==>
176
+ responds to <=>
166
177
  """
@@ -1,9 +1,13 @@
1
1
  Feature: exclusion filters
2
+
3
+ You can exclude examples from a run by declaring an exclusion filter and
4
+ then tagging examples, or entire groups, with that filter.
2
5
 
3
- Scenario: exclude one example
6
+ Scenario: exclude an example
4
7
  Given a file named "spec/sample_spec.rb" with:
5
8
  """
6
9
  RSpec.configure do |c|
10
+ # declare an exclusion filter
7
11
  c.filter_run_excluding :broken => true
8
12
  end
9
13
 
@@ -11,6 +15,7 @@ Feature: exclusion filters
11
15
  it "does one thing" do
12
16
  end
13
17
 
18
+ # tag example for exclusion by adding metadata
14
19
  it "does another thing", :broken => true do
15
20
  end
16
21
  end
@@ -19,7 +24,7 @@ Feature: exclusion filters
19
24
  Then the output should contain "does one thing"
20
25
  And the output should not contain "does another thing"
21
26
 
22
- Scenario: exclude one group
27
+ Scenario: exclude a group
23
28
  Given a file named "spec/sample_spec.rb" with:
24
29
  """
25
30
  RSpec.configure do |c|
@@ -44,7 +49,7 @@ Feature: exclusion filters
44
49
  And the output should not contain "group 1 example 1"
45
50
  And the output should not contain "group 1 example 2"
46
51
 
47
- Scenario: exclude all groups
52
+ Scenario: exclude multiple groups
48
53
  Given a file named "spec/sample_spec.rb" with:
49
54
  """
50
55
  RSpec.configure do |c|
@@ -76,4 +81,35 @@ Feature: exclusion filters
76
81
  Then the output should contain "No examples were matched. Perhaps {:broken=>true} is excluding everything?"
77
82
  And the output should contain "0 examples, 0 failures"
78
83
  And the output should not contain "group 1"
79
- And the output should not contain "group 2"
84
+ And the output should not contain "group 2"
85
+
86
+ Scenario: before/after(:all) hooks in excluded example group are not run
87
+ Given a file named "spec/before_after_all_exclusion_filter_spec.rb" with:
88
+ """
89
+ RSpec.configure do |c|
90
+ c.filter_run_excluding :broken => true
91
+ end
92
+
93
+ describe "group 1" do
94
+ before(:all) { puts "before all in included group" }
95
+ after(:all) { puts "after all in included group" }
96
+
97
+ it "group 1 example" do
98
+ end
99
+ end
100
+
101
+ describe "group 2", :broken => true do
102
+ before(:all) { puts "before all in excluded group" }
103
+ after(:all) { puts "after all in excluded group" }
104
+
105
+ context "context 1" do
106
+ it "group 2 context 1 example 1" do
107
+ end
108
+ end
109
+ end
110
+ """
111
+ When I run "rspec ./spec/before_after_all_exclusion_filter_spec.rb"
112
+ Then the output should contain "before all in included group"
113
+ And the output should contain "after all in included group"
114
+ And the output should not contain "before all in excluded group"
115
+ And the output should not contain "after all in excluded group"
@@ -1,11 +1,22 @@
1
1
  Feature: inclusion filters
2
-
3
- Scenario: focus on one example
4
- Given a file named "spec/sample_spec.rb" with:
2
+
3
+ You can restrict which examples are run by declaring an inclusion filter. The
4
+ most common use case is to focus on a subset of examples as you're focused on
5
+ a particular problem.
6
+
7
+ Background:
8
+ Given a file named "spec/spec_helper.rb" with:
5
9
  """
6
10
  RSpec.configure do |c|
11
+ # filter_run is short-form alias for filter_run_including
7
12
  c.filter_run :focus => true
8
13
  end
14
+ """
15
+
16
+ Scenario: focus on an example
17
+ Given a file named "spec/sample_spec.rb" with:
18
+ """
19
+ require "spec_helper"
9
20
 
10
21
  describe "something" do
11
22
  it "does one thing" do
@@ -15,16 +26,14 @@ Feature: inclusion filters
15
26
  end
16
27
  end
17
28
  """
18
- When I run "rspec ./spec/sample_spec.rb --format doc"
29
+ When I run "rspec spec/sample_spec.rb --format doc"
19
30
  Then the output should contain "does another thing"
20
31
  And the output should not contain "does one thing"
21
32
 
22
- Scenario: focus on one group
33
+ Scenario: focus on a group
23
34
  Given a file named "spec/sample_spec.rb" with:
24
35
  """
25
- RSpec.configure do |c|
26
- c.filter_run :focus => true
27
- end
36
+ require "spec_helper"
28
37
 
29
38
  describe "group 1", :focus => true do
30
39
  it "group 1 example 1" do
@@ -39,36 +48,36 @@ Feature: inclusion filters
39
48
  end
40
49
  end
41
50
  """
42
- When I run "rspec ./spec/sample_spec.rb --format doc"
51
+ When I run "rspec spec/sample_spec.rb --format doc"
43
52
  Then the output should contain "group 1 example 1"
44
53
  And the output should contain "group 1 example 2"
45
54
  And the output should not contain "group 2 example 1"
46
55
 
47
- Scenario: no examples match filter
48
- Given a file named "spec/sample_spec.rb" with:
56
+ Scenario: before/after(:all) hooks in unmatched example group are not run
57
+ Given a file named "spec/before_after_all_inclusion_filter_spec.rb" with:
49
58
  """
50
- RSpec.configure do |c|
51
- c.filter_run :focus => true
52
- c.run_all_when_everything_filtered = true
53
- end
59
+ require "spec_helper"
54
60
 
55
- describe "group 1" do
56
- it "group 1 example 1" do
57
- end
61
+ describe "group 1", :focus => true do
62
+ before(:all) { puts "before all in focused group" }
63
+ after(:all) { puts "after all in focused group" }
58
64
 
59
- it "group 1 example 2" do
65
+ it "group 1 example" do
60
66
  end
61
67
  end
62
68
 
63
69
  describe "group 2" do
64
- it "group 2 example 1" do
70
+ before(:all) { puts "before all in unfocused group" }
71
+ after(:all) { puts "after all in unfocused group" }
72
+
73
+ context "context 1" do
74
+ it "group 2 context 1 example 1" do
75
+ end
65
76
  end
66
77
  end
67
78
  """
68
- When I run "rspec ./spec/sample_spec.rb --format doc"
69
- Then the output should contain "No examples were matched by {:focus=>true}, running all"
70
- And the output should contain "group 1 example 1"
71
- And the output should contain "group 1 example 2"
72
- And the output should contain "group 2 example 1"
73
- And the output should contain "3 examples, 0 failures"
74
-
79
+ When I run "rspec ./spec/before_after_all_inclusion_filter_spec.rb"
80
+ Then the output should contain "before all in focused group"
81
+ And the output should contain "after all in focused group"
82
+ And the output should not contain "before all in unfocused group"
83
+ And the output should not contain "after all in unfocused group"