rspec-core 2.0.0.beta.17 → 2.0.0.beta.18

Sign up to get free protection for your applications and to get access to all the features.
Files changed (70) hide show
  1. data/README.markdown +5 -1
  2. data/Rakefile +4 -1
  3. data/Upgrade.markdown +28 -2
  4. data/VERSION +1 -1
  5. data/autotest/discover.rb +1 -1
  6. data/features/command_line/configure.feature +19 -0
  7. data/features/example_groups/shared_example_group.feature +125 -0
  8. data/features/hooks/around_hooks.feature +11 -2
  9. data/features/pending/pending_examples.feature +18 -6
  10. data/lib/autotest/rspec2.rb +1 -1
  11. data/lib/rspec/core.rb +1 -0
  12. data/lib/rspec/core/command_line_configuration.rb +62 -0
  13. data/lib/rspec/core/configuration.rb +39 -12
  14. data/lib/rspec/core/configuration_options.rb +5 -5
  15. data/lib/rspec/core/deprecation.rb +6 -6
  16. data/lib/rspec/core/errors.rb +1 -1
  17. data/lib/rspec/core/example.rb +25 -25
  18. data/lib/rspec/core/example_group.rb +30 -14
  19. data/lib/rspec/core/formatters/base_formatter.rb +25 -25
  20. data/lib/rspec/core/formatters/base_text_formatter.rb +11 -10
  21. data/lib/rspec/core/formatters/documentation_formatter.rb +2 -2
  22. data/lib/rspec/core/formatters/helpers.rb +6 -6
  23. data/lib/rspec/core/formatters/html_formatter.rb +13 -12
  24. data/lib/rspec/core/formatters/progress_formatter.rb +1 -1
  25. data/lib/rspec/core/formatters/snippet_extractor.rb +5 -5
  26. data/lib/rspec/core/hooks.rb +3 -3
  27. data/lib/rspec/core/kernel_extensions.rb +1 -1
  28. data/lib/rspec/core/let.rb +5 -5
  29. data/lib/rspec/core/metadata.rb +2 -2
  30. data/lib/rspec/core/mocking/with_absolutely_nothing.rb +3 -3
  31. data/lib/rspec/core/mocking/with_mocha.rb +5 -5
  32. data/lib/rspec/core/mocking/with_rr.rb +3 -3
  33. data/lib/rspec/core/mocking/with_rspec.rb +3 -3
  34. data/lib/rspec/core/option_parser.rb +8 -4
  35. data/lib/rspec/core/rake_task.rb +5 -0
  36. data/lib/rspec/core/ruby_project.rb +1 -1
  37. data/lib/rspec/core/shared_example_group.rb +2 -2
  38. data/lib/rspec/core/subject.rb +10 -4
  39. data/lib/rspec/core/world.rb +5 -5
  40. data/rspec-core.gemspec +19 -11
  41. data/spec/autotest/rspec_spec.rb +14 -14
  42. data/spec/rspec/core/command_line_configuration_spec.rb +26 -0
  43. data/spec/rspec/core/command_line_spec.rb +5 -5
  44. data/spec/rspec/core/configuration_options_spec.rb +20 -20
  45. data/spec/rspec/core/configuration_spec.rb +10 -10
  46. data/spec/rspec/core/core_spec.rb +8 -8
  47. data/spec/rspec/core/deprecations_spec.rb +2 -2
  48. data/spec/rspec/core/drb_command_line_spec.rb +10 -10
  49. data/spec/rspec/core/example_group_spec.rb +46 -10
  50. data/spec/rspec/core/example_spec.rb +46 -12
  51. data/spec/rspec/core/formatters/base_formatter_spec.rb +2 -46
  52. data/spec/rspec/core/formatters/base_text_formatter_spec.rb +4 -3
  53. data/spec/rspec/core/formatters/documentation_formatter_spec.rb +1 -1
  54. data/spec/rspec/core/formatters/helpers_spec.rb +2 -2
  55. data/spec/rspec/core/formatters/html_formatted-1.8.7.html +1 -1
  56. data/spec/rspec/core/formatters/html_formatted-1.9.1.html +1 -1
  57. data/spec/rspec/core/formatters/html_formatted-1.9.2.html +1 -1
  58. data/spec/rspec/core/formatters/progress_formatter_spec.rb +10 -9
  59. data/spec/rspec/core/formatters/text_mate_formatted-1.8.7.html +13 -13
  60. data/spec/rspec/core/formatters/text_mate_formatted-1.9.2.html +1 -1
  61. data/spec/rspec/core/let_spec.rb +1 -1
  62. data/spec/rspec/core/metadata_spec.rb +9 -9
  63. data/spec/rspec/core/option_parser_spec.rb +3 -3
  64. data/spec/rspec/core/pending_example_spec.rb +1 -1
  65. data/spec/rspec/core/resources/custom_example_group_runner.rb +1 -1
  66. data/spec/rspec/core/runner_spec.rb +4 -4
  67. data/spec/rspec/core/shared_example_group_spec.rb +66 -162
  68. data/spec/rspec/core/subject_spec.rb +4 -4
  69. data/spec/rspec/core/world_spec.rb +38 -38
  70. metadata +21 -13
@@ -4,7 +4,7 @@ Behaviour Driven Development for Ruby
4
4
 
5
5
  ## Upgrading from rspec-1.x
6
6
 
7
- See Upgrade.markdown
7
+ See [Upgrade.markdown](http://github.com/rspec/rspec-core/blob/master/Upgrade.markdown)
8
8
 
9
9
  ## Install
10
10
 
@@ -63,6 +63,10 @@ Use the documentation formatter to see the resulting spec:
63
63
  Finished in 0.000379 seconds
64
64
  1 example, 0 failures
65
65
 
66
+ ## Known issues
67
+
68
+ See [http://github.com/rspec/rspec-core/issues](http://github.com/rspec/rspec-core/issues)
69
+
66
70
  ## Learn more
67
71
 
68
72
  While not comprehensive yet, you can learn quite a lot from the Cucumber
data/Rakefile CHANGED
@@ -31,7 +31,10 @@ begin
31
31
  #{"*"*50}
32
32
 
33
33
  Thank you for installing #{gem.summary}
34
-
34
+
35
+ Please be sure to look at Upgrade.markdown to see what might have changed
36
+ since the last release.
37
+
35
38
  #{"*"*50}
36
39
  EOM
37
40
  end
@@ -12,12 +12,20 @@ The command to run specs is now `rspec` instead of `spec`.
12
12
 
13
13
  RSpec-2 works with autotest as follows:
14
14
 
15
- # in ./autotest/discover.rb
15
+ rspec --configure autotest
16
+
17
+ This adds `./autotest/discover.rb` with:
18
+
16
19
  Autotest.add_discovery { "rspec2" }
17
20
 
18
- # command line
21
+ Now, on the command line just type:
22
+
19
23
  $ autotest
20
24
 
25
+ Or, if you're using bundler:
26
+
27
+ $ bundle exec autotest
28
+
21
29
  The `autospec` command is a thing of the past.
22
30
 
23
31
  ### RSpec
@@ -116,3 +124,21 @@ right version:
116
124
  In this case, we're using `exclusion_filter` instead of `filter_run` or
117
125
  `filter`, which indicate _inclusion_ filters. So each of those examples is
118
126
  excluded if we're _not_ running the version of Ruby they work with.
127
+
128
+ ### Shared example groups
129
+
130
+ Shared example groups are now run in a nested group within the including group
131
+ (they used to be run in the same group). Nested groups inherit `before`, `after`,
132
+ `around`, and `let` hooks, as well as any methods that are defined in the parent
133
+ group.
134
+
135
+ This new approach provides better encapsulation, better output, and an
136
+ opportunity to add contextual information to the shared group via a block
137
+ passed to `it_should_behave_like`.
138
+
139
+ See [features/example\_groups/shared\_example\_group.feature](http://github.com/rspec/rspec-core/blob/master/features/example_groups/shared_example_group.feature) for more information.
140
+
141
+ NOTICE: The including example groups no longer have access to any of the
142
+ methods, hooks, or state defined inside a shared group. This will break specs
143
+ that were using shared example groups to extend the behavior of including
144
+ groups in any way besides their intended purpose: to add examples to a group.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 2.0.0.beta.17
1
+ 2.0.0.beta.18
@@ -1,2 +1,2 @@
1
1
  Autotest.add_discovery { "rspec2" }
2
-
2
+
@@ -0,0 +1,19 @@
1
+ Feature: configure
2
+
3
+ Use --configure to generate configuration files.
4
+
5
+ Currently, the only supported argument is "autotest", which creates
6
+ a autotest/discover.rb file in your project root directory.
7
+
8
+ Background:
9
+ Given a directory named "rspec_project"
10
+ And I cd to "rspec_project"
11
+
12
+ Scenario: generate autotest directory and discover file
13
+ When I run "rspec --configure autotest"
14
+ Then the following directories should exist:
15
+ | autotest |
16
+ And the following files should exist:
17
+ | autotest/discover.rb |
18
+ And the file "autotest/discover.rb" should contain "Autotest.add_discovery"
19
+ And the stdout should contain "autotest/discover.rb has been added"
@@ -0,0 +1,125 @@
1
+ Feature: Shared example group
2
+
3
+ As an RSpec user
4
+ I want to share my examples
5
+ In order to reduce duplication in my specs
6
+
7
+ Scenario: Using a shared example group
8
+ Given a file named "shared_example_group_spec.rb" with:
9
+ """
10
+ require "set"
11
+
12
+ shared_examples_for "a collection object" do
13
+ before(:each) do
14
+ @instance = described_class.new([7, 2, 4])
15
+ end
16
+
17
+ context "initialized with 3 items" do
18
+ it "has three items" do
19
+ @instance.size.should == 3
20
+ end
21
+ end
22
+
23
+ describe "#first" do
24
+ it "returns the first item" do
25
+ @instance.first.should == 7
26
+ end
27
+ end
28
+ end
29
+
30
+ describe Array do
31
+ it_should_behave_like "a collection object"
32
+ end
33
+
34
+ describe Set do
35
+ it_should_behave_like "a collection object"
36
+ end
37
+ """
38
+ When I run "rspec shared_example_group_spec.rb --format documentation"
39
+ Then the output should contain "4 examples, 0 failures"
40
+ And the output should contain:
41
+ """
42
+ Array
43
+ it should behave like a collection object
44
+ initialized with 3 items
45
+ has three items
46
+ #first
47
+ returns the first item
48
+
49
+ Set
50
+ it should behave like a collection object
51
+ initialized with 3 items
52
+ has three items
53
+ #first
54
+ returns the first item
55
+ """
56
+
57
+ Scenario: Using a shared example group with a block
58
+ Given a file named "shared_example_group_spec.rb" with:
59
+ """
60
+ require "set"
61
+
62
+ shared_examples_for "a collection object" do
63
+ describe "<<" do
64
+ it "adds objects to the end of the collection" do
65
+ collection << 1
66
+ collection << 2
67
+ collection.to_a.should eq([1,2])
68
+ end
69
+ end
70
+ end
71
+
72
+ describe Array do
73
+ it_should_behave_like "a collection object" do
74
+ let(:collection) { Array.new }
75
+ end
76
+ end
77
+
78
+ describe Set do
79
+ it_should_behave_like "a collection object" do
80
+ let(:collection) { Set.new }
81
+ end
82
+ end
83
+ """
84
+ When I run "rspec shared_example_group_spec.rb --format documentation"
85
+ Then the output should contain "2 examples, 0 failures"
86
+ And the output should contain:
87
+ """
88
+ Array
89
+ it should behave like a collection object
90
+ <<
91
+ adds objects to the end of the collection
92
+
93
+ Set
94
+ it should behave like a collection object
95
+ <<
96
+ adds objects to the end of the collection
97
+ """
98
+
99
+ Scenario: Aliasing "it_should_behave_like" to "it_has_behavior"
100
+ Given a file named "shared_example_group_spec.rb" with:
101
+ """
102
+ RSpec.configure do |c|
103
+ c.alias_it_should_behave_like_to :it_has_behavior, 'has behavior:'
104
+ end
105
+
106
+ shared_examples_for 'sortability' do
107
+ it 'responds to <==>' do
108
+ sortable.should respond_to(:<=>)
109
+ end
110
+ end
111
+
112
+ describe String do
113
+ it_has_behavior 'sortability' do
114
+ let(:sortable) { 'sample string' }
115
+ end
116
+ end
117
+ """
118
+ When I run "rspec shared_example_group_spec.rb --format documentation"
119
+ Then the output should contain "1 example, 0 failures"
120
+ And the output should contain:
121
+ """
122
+ String
123
+ has behavior: sortability
124
+ responds to <==>
125
+ """
@@ -155,7 +155,12 @@ Feature: around hooks
155
155
  """
156
156
  When I run "rspec ./around_block_with_implicit_pending_example.rb"
157
157
  Then the output should contain "1 example, 0 failures, 1 pending"
158
- And the output should contain "implicit pending example should be detected as Not Yet Implemented (Not Yet Implemented)"
158
+ And the output should contain:
159
+ """
160
+ Pending:
161
+ implicit pending example should be detected as Not Yet Implemented
162
+ # Not Yet Implemented
163
+ """
159
164
 
160
165
 
161
166
  Scenario: explicitly pending examples should be detected as pending
@@ -173,7 +178,11 @@ Feature: around hooks
173
178
  """
174
179
  When I run "rspec ./around_block_with_explicit_pending_example.rb"
175
180
  Then the output should contain "1 example, 0 failures, 1 pending"
176
- And the output should contain "explicit pending example should be detected as pending (No reason given)"
181
+ And the output should contain:
182
+ """
183
+ explicit pending example should be detected as pending
184
+ # No reason given
185
+ """
177
186
 
178
187
  Scenario: multiple around hooks in the same scope are all run
179
188
  Given a file named "around_hooks_in_same_scope.rb" with:
@@ -28,9 +28,15 @@ Feature: pending examples
28
28
  """
29
29
  When I run "rspec ./pending_without_block_spec.rb"
30
30
  Then the exit status should be 0
31
- And the output should contain "1 example, 0 failures, 1 pending"
32
- And the output should contain "(something else getting finished)"
33
- And the output should contain "pending_without_block_spec.rb:2"
31
+ And the output should contain:
32
+ """
33
+ 1 example, 0 failures, 1 pending
34
+
35
+ Pending:
36
+ an example is implemented but waiting
37
+ # something else getting finished
38
+ # ./pending_without_block_spec.rb:2
39
+ """
34
40
 
35
41
  Scenario: pending any arbitary reason, with a block that fails
36
42
  Given a file named "pending_with_failing_block_spec.rb" with:
@@ -45,9 +51,15 @@ Feature: pending examples
45
51
  """
46
52
  When I run "rspec ./pending_with_failing_block_spec.rb"
47
53
  Then the exit status should be 0
48
- And the output should contain "1 example, 0 failures, 1 pending"
49
- And the output should contain "(something else getting finished)"
50
- And the output should contain "pending_with_failing_block_spec.rb:2"
54
+ And the output should contain:
55
+ """
56
+ 1 example, 0 failures, 1 pending
57
+
58
+ Pending:
59
+ an example is implemented but waiting
60
+ # something else getting finished
61
+ # ./pending_with_failing_block_spec.rb:2
62
+ """
51
63
 
52
64
  Scenario: pending any arbitary reason, with a block that passes
53
65
  Given a file named "pending_with_passing_block_spec.rb" with:
@@ -17,7 +17,7 @@ end
17
17
  class RSpecCommandError < StandardError; end
18
18
 
19
19
  class Autotest::Rspec2 < Autotest
20
-
20
+
21
21
  SPEC_PROGRAM = File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'bin', 'rspec'))
22
22
 
23
23
  def initialize
@@ -13,6 +13,7 @@ require 'rspec/core/pending'
13
13
  require 'rspec/core/around_proxy'
14
14
  require 'rspec/core/world'
15
15
  require 'rspec/core/configuration'
16
+ require 'rspec/core/command_line_configuration'
16
17
  require 'rspec/core/option_parser'
17
18
  require 'rspec/core/configuration_options'
18
19
  require 'rspec/core/command_line'
@@ -0,0 +1,62 @@
1
+ module RSpec
2
+ module Core
3
+ class CommandLineConfiguration
4
+ attr_reader :command
5
+
6
+ def initialize(cmd)
7
+ @command = cmd
8
+ end
9
+
10
+ def run
11
+ case @command
12
+ when 'autotest' then Autotest.generate
13
+ else raise ArgumentError, <<-MESSAGE
14
+
15
+ #{"*"*50}
16
+ "#{@command}" is not valid a valid argument to "rspec --configure".
17
+ Supported options are:
18
+
19
+ rspec --configure autotest # generates configuration to run autotest with rspec
20
+
21
+ #{"*"*50}
22
+ MESSAGE
23
+ end
24
+ end
25
+
26
+ class Autotest
27
+ class << self
28
+ def generate
29
+ create_autotest_directory
30
+ create_discover_file
31
+ puts "autotest/discover.rb has been added"
32
+ end
33
+
34
+ def create_autotest_directory
35
+ Dir.mkdir('autotest') unless File.exist?('autotest')
36
+ end
37
+
38
+ def create_discover_file
39
+ optionally_remove_discover_file if discover_file_exists?
40
+ File.open(discover_file_path, 'w') do |file|
41
+ file << 'Autotest.add_discovery { "rspec2" }'
42
+ end
43
+ end
44
+
45
+ def optionally_remove_discover_file
46
+ print "Discover file already exists, overwrite [y/N]? "
47
+ exit if gets !~ /y/i
48
+ FileUtils.rm_rf(discover_file_path)
49
+ end
50
+
51
+ def discover_file_exists?
52
+ File.exist?(discover_file_path)
53
+ end
54
+
55
+ def discover_file_path
56
+ File.join('autotest', 'discover.rb')
57
+ end
58
+ end
59
+ end
60
+ end
61
+ end
62
+ end
@@ -33,10 +33,10 @@ module RSpec
33
33
  add_setting :include_or_extend_modules, :default => []
34
34
  add_setting :formatter_class, :default => RSpec::Core::Formatters::ProgressFormatter
35
35
  add_setting :backtrace_clean_patterns, :default => [
36
- /\/lib\/ruby\//,
37
- /bin\/rcov:/,
38
- /vendor\/rails/,
39
- /bin\/rspec/,
36
+ /\/lib\/ruby\//,
37
+ /bin\/rcov:/,
38
+ /vendor\/rails/,
39
+ /bin\/rspec/,
40
40
  /bin\/spec/,
41
41
  /lib\/rspec\/(core|expectations|matchers|mocks)/
42
42
  ]
@@ -46,7 +46,7 @@ module RSpec
46
46
  # add_setting(:name, :default => "default_value")
47
47
  # add_setting(:name, :alias => :other_setting)
48
48
  #
49
- # Use this to add custom settings to the RSpec.configuration object.
49
+ # Use this to add custom settings to the RSpec.configuration object.
50
50
  #
51
51
  # RSpec.configuration.add_setting :foo
52
52
  #
@@ -66,7 +66,7 @@ module RSpec
66
66
  # end
67
67
  #
68
68
  # == Options
69
- #
69
+ #
70
70
  # +add_setting+ takes an optional hash that supports the following
71
71
  # keys:
72
72
  #
@@ -115,13 +115,15 @@ module RSpec
115
115
  'rspec/core/mocking/with_flexmock'
116
116
  else
117
117
  'rspec/core/mocking/with_absolutely_nothing'
118
- end
118
+ end
119
119
  end
120
120
 
121
121
  def full_backtrace=(bool)
122
122
  settings[:backtrace_clean_patterns] = []
123
123
  end
124
124
 
125
+ remove_method :color_enabled=
126
+
125
127
  def color_enabled=(bool)
126
128
  return unless bool
127
129
  settings[:color_enabled] = true
@@ -171,7 +173,7 @@ EOM
171
173
  def full_description=(description)
172
174
  filter_run :full_description => /#{description}/
173
175
  end
174
-
176
+
175
177
  def formatter=(formatter_to_use)
176
178
  if string_const?(formatter_to_use) && (class_name = eval(formatter_to_use)).is_a?(Class)
177
179
  formatter_class = class_name
@@ -185,19 +187,19 @@ EOM
185
187
  RSpec::Core::Formatters::HtmlFormatter
186
188
  when 't', 'textmate'
187
189
  RSpec::Core::Formatters::TextMateFormatter
188
- when 'progress'
190
+ when 'p', 'progress'
189
191
  RSpec::Core::Formatters::ProgressFormatter
190
- else
192
+ else
191
193
  raise ArgumentError, "Formatter '#{formatter_to_use}' unknown - maybe you meant 'documentation' or 'progress'?."
192
194
  end
193
195
  end
194
196
  self.formatter_class = formatter_class
195
197
  end
196
-
198
+
197
199
  def string_const?(str)
198
200
  str.is_a?(String) && /\A[A-Z][a-zA-Z0-9_:]*\z/ =~ str
199
201
  end
200
-
202
+
201
203
  def formatter
202
204
  @formatter ||= formatter_class.new(output)
203
205
  end
@@ -227,6 +229,31 @@ EOM
227
229
  RSpec::Core::ExampleGroup.alias_example_to(new_name, extra_options)
228
230
  end
229
231
 
232
+ # Define an alias for it_should_behave_like that allows different
233
+ # language (like "it_has_behavior" or "it_behaves_like") to be
234
+ # employed when including shared examples.
235
+ #
236
+ # Example:
237
+ #
238
+ # alias_it_should_behave_like_to(:it_has_behavior, 'has behavior:')
239
+ #
240
+ # allows the user to include a shared example group like:
241
+ #
242
+ # describe Entity do
243
+ # it_has_behavior 'sortability' do
244
+ # let(:sortable) { Entity.new }
245
+ # end
246
+ # end
247
+ #
248
+ # which is reported in the output as:
249
+ #
250
+ # Entity
251
+ # has behavior: sortability
252
+ # # sortability examples here
253
+ def alias_it_should_behave_like_to(new_name, report_label = '')
254
+ RSpec::Core::ExampleGroup.alias_it_should_behave_like_to(new_name, report_label)
255
+ end
256
+
230
257
  def filter_run_including(options={})
231
258
  # TODO (DC 2010-07-03) this should probably warn when the unless clause returns true
232
259
  self.filter = options unless filter and filter[:line_number] || filter[:full_description]