rspec-core 2.12.2 → 2.13.0

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 (95) hide show
  1. data/Changelog.md +31 -0
  2. data/README.md +11 -10
  3. data/features/command_line/example_name_option.feature +6 -10
  4. data/features/command_line/tag.feature +15 -8
  5. data/features/configuration/backtrace_clean_patterns.feature +102 -0
  6. data/features/configuration/failure_exit_code.feature +36 -0
  7. data/features/configuration/order_and_seed.feature +3 -0
  8. data/features/configuration/output_stream.feature +24 -0
  9. data/features/configuration/pattern.feature +30 -0
  10. data/features/configuration/profile.feature +163 -0
  11. data/features/configuration/run_all_when_everything_filtered.feature +60 -0
  12. data/features/configuration/show_failures_in_pending_blocks.feature +61 -0
  13. data/features/configuration/treat_symbols_as_metadata_keys_with_true_values.feature +52 -0
  14. data/features/filtering/exclusion_filters.feature +1 -2
  15. data/features/formatters/configurable_colors.feature +31 -0
  16. data/features/step_definitions/additional_cli_steps.rb +21 -0
  17. data/features/subject/explicit_subject.feature +19 -0
  18. data/lib/autotest/rspec2.rb +1 -1
  19. data/lib/rspec/core.rb +1 -2
  20. data/lib/rspec/core/configuration.rb +33 -3
  21. data/lib/rspec/core/configuration_options.rb +5 -5
  22. data/lib/rspec/core/deprecation.rb +1 -1
  23. data/lib/rspec/core/example.rb +2 -2
  24. data/lib/rspec/core/example_group.rb +1 -3
  25. data/lib/rspec/core/formatters/base_text_formatter.rb +93 -27
  26. data/lib/rspec/core/formatters/documentation_formatter.rb +3 -3
  27. data/lib/rspec/core/formatters/progress_formatter.rb +3 -3
  28. data/lib/rspec/core/memoized_helpers.rb +425 -0
  29. data/lib/rspec/core/metadata.rb +6 -2
  30. data/lib/rspec/core/option_parser.rb +8 -2
  31. data/lib/rspec/core/pending.rb +7 -0
  32. data/lib/rspec/core/shared_context.rb +1 -1
  33. data/lib/rspec/core/version.rb +1 -1
  34. data/spec/autotest/failed_results_re_spec.rb +4 -4
  35. data/spec/autotest/rspec_spec.rb +25 -20
  36. data/spec/command_line/order_spec.rb +21 -21
  37. data/spec/rspec/core/command_line_spec.rb +6 -6
  38. data/spec/rspec/core/configuration_options_spec.rb +86 -72
  39. data/spec/rspec/core/configuration_spec.rb +161 -156
  40. data/spec/rspec/core/deprecations_spec.rb +4 -4
  41. data/spec/rspec/core/drb_command_line_spec.rb +9 -9
  42. data/spec/rspec/core/drb_options_spec.rb +46 -33
  43. data/spec/rspec/core/dsl_spec.rb +3 -3
  44. data/spec/rspec/core/example_group_spec.rb +156 -124
  45. data/spec/rspec/core/example_spec.rb +68 -52
  46. data/spec/rspec/core/filter_manager_spec.rb +36 -36
  47. data/spec/rspec/core/formatters/base_formatter_spec.rb +9 -9
  48. data/spec/rspec/core/formatters/base_text_formatter_spec.rb +104 -42
  49. data/spec/rspec/core/formatters/documentation_formatter_spec.rb +4 -4
  50. data/spec/rspec/core/formatters/helpers_spec.rb +13 -13
  51. data/spec/rspec/core/formatters/html_formatted-1.8.7-jruby.html +5 -17
  52. data/spec/rspec/core/formatters/html_formatted-1.8.7-rbx.html +159 -44
  53. data/spec/rspec/core/formatters/html_formatted-1.8.7.html +14 -14
  54. data/spec/rspec/core/formatters/html_formatted-1.9.2.html +20 -20
  55. data/spec/rspec/core/formatters/html_formatted-1.9.3-jruby.html +5 -5
  56. data/spec/rspec/core/formatters/html_formatted-1.9.3-rbx.html +159 -44
  57. data/spec/rspec/core/formatters/html_formatted-1.9.3.html +20 -20
  58. data/spec/rspec/core/formatters/{html_formatted-1.9.2-jruby.html → html_formatted-2.0.0.html} +24 -18
  59. data/spec/rspec/core/formatters/html_formatter_spec.rb +9 -5
  60. data/spec/rspec/core/formatters/json_formatter_spec.rb +9 -9
  61. data/spec/rspec/core/formatters/progress_formatter_spec.rb +4 -4
  62. data/spec/rspec/core/formatters/snippet_extractor_spec.rb +3 -3
  63. data/spec/rspec/core/formatters/text_mate_formatted-1.8.7-jruby.html +5 -17
  64. data/spec/rspec/core/formatters/text_mate_formatted-1.8.7-rbx.html +159 -44
  65. data/spec/rspec/core/formatters/text_mate_formatted-1.8.7.html +16 -16
  66. data/spec/rspec/core/formatters/text_mate_formatted-1.9.2.html +23 -23
  67. data/spec/rspec/core/formatters/text_mate_formatted-1.9.3-jruby.html +5 -17
  68. data/spec/rspec/core/formatters/text_mate_formatted-1.9.3-rbx.html +159 -44
  69. data/spec/rspec/core/formatters/text_mate_formatted-1.9.3.html +23 -23
  70. data/spec/rspec/core/formatters/{text_mate_formatted-1.9.2-jruby.html → text_mate_formatted-2.0.0.html} +25 -19
  71. data/spec/rspec/core/formatters/text_mate_formatter_spec.rb +8 -4
  72. data/spec/rspec/core/hooks_filtering_spec.rb +16 -16
  73. data/spec/rspec/core/hooks_spec.rb +11 -11
  74. data/spec/rspec/core/kernel_extensions_spec.rb +1 -1
  75. data/spec/rspec/core/memoized_helpers_spec.rb +458 -0
  76. data/spec/rspec/core/metadata_spec.rb +74 -74
  77. data/spec/rspec/core/option_parser_spec.rb +27 -27
  78. data/spec/rspec/core/pending_example_spec.rb +32 -32
  79. data/spec/rspec/core/project_initializer_spec.rb +8 -8
  80. data/spec/rspec/core/rake_task_spec.rb +16 -16
  81. data/spec/rspec/core/reporter_spec.rb +3 -3
  82. data/spec/rspec/core/resources/formatter_specs.rb +4 -4
  83. data/spec/rspec/core/ruby_project_spec.rb +4 -2
  84. data/spec/rspec/core/shared_context_spec.rb +34 -7
  85. data/spec/rspec/core/shared_example_group_spec.rb +14 -14
  86. data/spec/rspec/core/world_spec.rb +9 -9
  87. data/spec/rspec/core_spec.rb +5 -5
  88. data/spec/spec_helper.rb +4 -0
  89. data/spec/support/shared_example_groups.rb +4 -4
  90. data/spec/support/spec_files.rb +2 -2
  91. metadata +158 -150
  92. data/lib/rspec/core/let.rb +0 -110
  93. data/lib/rspec/core/subject.rb +0 -223
  94. data/spec/rspec/core/let_spec.rb +0 -55
  95. data/spec/rspec/core/subject_spec.rb +0 -255
@@ -319,15 +319,17 @@ a {
319
319
  <span class="duration">n.nnnns</span>
320
320
  <div class="failure" id="failure_1">
321
321
  <div class="message"><pre>RSpec::Core::Pending::PendingExampleFixedError</pre></div>
322
- <div class="backtrace"><pre><a href="txmt://open?url=file:///Users/alindeman/workspace/rspec-dev/repos/rspec-core/spec/rspec/core/resources/formatter_specs.rb&line=18">./spec/rspec/core/resources/formatter_specs.rb:18</a> :in `(root)'
323
- <a href="txmt://open?url=file:///Users/alindeman/workspace/rspec-dev/repos/rspec-core/spec/rspec/core/formatters/text_mate_formatter_spec.rb&line=31">./spec/rspec/core/formatters/text_mate_formatter_spec.rb:31</a> :in `Formatters'
324
- <a href="txmt://open?url=file:///Users/alindeman/workspace/rspec-dev/repos/rspec-core/spec/rspec/core/formatters/text_mate_formatter_spec.rb&line=53">./spec/rspec/core/formatters/text_mate_formatter_spec.rb:53</a> :in `Formatters'
325
- <a href="txmt://open?url=file:///Users/alindeman/workspace/rspec-dev/repos/rspec-core/spec/rspec/core/formatters/text_mate_formatter_spec.rb&line=53">./spec/rspec/core/formatters/text_mate_formatter_spec.rb:53</a> :in `Formatters'
326
- <a href="txmt://open?url=file:///Users/alindeman/workspace/rspec-dev/repos/rspec-core/spec/rspec/core/formatters/text_mate_formatter_spec.rb&line=52">./spec/rspec/core/formatters/text_mate_formatter_spec.rb:52</a> :in `Formatters'</pre></div>
322
+ <div class="backtrace"><pre><a href="txmt://open?url=file:///Users/myron/code/rspec-dev/repos/rspec-core/spec/rspec/core/resources/formatter_specs.rb&line=18">./spec/rspec/core/resources/formatter_specs.rb:18</a> :in `block (3 levels) in &lt;top (required)&gt;&#39;
323
+ <a href="txmt://open?url=file:///Users/myron/code/rspec-dev/repos/rspec-core/spec/rspec/core/formatters/text_mate_formatter_spec.rb&line=36">./spec/rspec/core/formatters/text_mate_formatter_spec.rb:36</a> :in `block (2 levels) in &lt;module:Formatters&gt;&#39;
324
+ <a href="txmt://open?url=file:///Users/myron/code/rspec-dev/repos/rspec-core/spec/rspec/core/formatters/text_mate_formatter_spec.rb&line=58">./spec/rspec/core/formatters/text_mate_formatter_spec.rb:58</a> :in `block (5 levels) in &lt;module:Formatters&gt;&#39;
325
+ <a href="txmt://open?url=file:///Users/myron/code/rspec-dev/repos/rspec-core/spec/rspec/core/formatters/text_mate_formatter_spec.rb&line=58">./spec/rspec/core/formatters/text_mate_formatter_spec.rb:58</a> :in `open&#39;
326
+ <a href="txmt://open?url=file:///Users/myron/code/rspec-dev/repos/rspec-core/spec/rspec/core/formatters/text_mate_formatter_spec.rb&line=58">./spec/rspec/core/formatters/text_mate_formatter_spec.rb:58</a> :in `block (4 levels) in &lt;module:Formatters&gt;&#39;
327
+ <a href="txmt://open?url=file:///Users/myron/code/rspec-dev/repos/rspec-core/spec/rspec/core/formatters/text_mate_formatter_spec.rb&line=57">./spec/rspec/core/formatters/text_mate_formatter_spec.rb:57</a> :in `chdir&#39;
328
+ <a href="txmt://open?url=file:///Users/myron/code/rspec-dev/repos/rspec-core/spec/rspec/core/formatters/text_mate_formatter_spec.rb&line=57">./spec/rspec/core/formatters/text_mate_formatter_spec.rb:57</a> :in `block (3 levels) in &lt;module:Formatters&gt;&#39;</pre></div>
327
329
  <pre class="ruby"><code><span class="linenum">16</span> <span class="ident">context</span> <span class="punct">&quot;</span><span class="string">with content that would pass</span><span class="punct">&quot;</span> <span class="keyword">do</span>
328
330
  <span class="linenum">17</span> <span class="ident">it</span> <span class="punct">&quot;</span><span class="string">fails</span><span class="punct">&quot;</span> <span class="keyword">do</span>
329
331
  <span class="offending"><span class="linenum">18</span> <span class="ident">pending</span> <span class="keyword">do</span></span>
330
- <span class="linenum">19</span> <span class="number">1</span><span class="punct">.</span><span class="ident">should</span> <span class="ident">eq</span><span class="punct">(</span><span class="number">1</span><span class="punct">)</span>
332
+ <span class="linenum">19</span> <span class="ident">expect</span><span class="punct">(</span><span class="number">1</span><span class="punct">).</span><span class="ident">to</span> <span class="ident">eq</span><span class="punct">(</span><span class="number">1</span><span class="punct">)</span>
331
333
  <span class="linenum">20</span> <span class="keyword">end</span></code></pre>
332
334
  </div>
333
335
  </dd>
@@ -356,14 +358,16 @@ expected: 2
356
358
 
357
359
  (compared using ==)
358
360
  </pre></div>
359
- <div class="backtrace"><pre><a href="txmt://open?url=file:///Users/alindeman/workspace/rspec-dev/repos/rspec-core/spec/rspec/core/resources/formatter_specs.rb&line=33">./spec/rspec/core/resources/formatter_specs.rb:33</a> :in `(root)'
360
- <a href="txmt://open?url=file:///Users/alindeman/workspace/rspec-dev/repos/rspec-core/spec/rspec/core/formatters/text_mate_formatter_spec.rb&line=31">./spec/rspec/core/formatters/text_mate_formatter_spec.rb:31</a> :in `Formatters'
361
- <a href="txmt://open?url=file:///Users/alindeman/workspace/rspec-dev/repos/rspec-core/spec/rspec/core/formatters/text_mate_formatter_spec.rb&line=53">./spec/rspec/core/formatters/text_mate_formatter_spec.rb:53</a> :in `Formatters'
362
- <a href="txmt://open?url=file:///Users/alindeman/workspace/rspec-dev/repos/rspec-core/spec/rspec/core/formatters/text_mate_formatter_spec.rb&line=53">./spec/rspec/core/formatters/text_mate_formatter_spec.rb:53</a> :in `Formatters'
363
- <a href="txmt://open?url=file:///Users/alindeman/workspace/rspec-dev/repos/rspec-core/spec/rspec/core/formatters/text_mate_formatter_spec.rb&line=52">./spec/rspec/core/formatters/text_mate_formatter_spec.rb:52</a> :in `Formatters'</pre></div>
361
+ <div class="backtrace"><pre><a href="txmt://open?url=file:///Users/myron/code/rspec-dev/repos/rspec-core/spec/rspec/core/resources/formatter_specs.rb&line=33">./spec/rspec/core/resources/formatter_specs.rb:33</a> :in `block (2 levels) in &lt;top (required)&gt;&#39;
362
+ <a href="txmt://open?url=file:///Users/myron/code/rspec-dev/repos/rspec-core/spec/rspec/core/formatters/text_mate_formatter_spec.rb&line=36">./spec/rspec/core/formatters/text_mate_formatter_spec.rb:36</a> :in `block (2 levels) in &lt;module:Formatters&gt;&#39;
363
+ <a href="txmt://open?url=file:///Users/myron/code/rspec-dev/repos/rspec-core/spec/rspec/core/formatters/text_mate_formatter_spec.rb&line=58">./spec/rspec/core/formatters/text_mate_formatter_spec.rb:58</a> :in `block (5 levels) in &lt;module:Formatters&gt;&#39;
364
+ <a href="txmt://open?url=file:///Users/myron/code/rspec-dev/repos/rspec-core/spec/rspec/core/formatters/text_mate_formatter_spec.rb&line=58">./spec/rspec/core/formatters/text_mate_formatter_spec.rb:58</a> :in `open&#39;
365
+ <a href="txmt://open?url=file:///Users/myron/code/rspec-dev/repos/rspec-core/spec/rspec/core/formatters/text_mate_formatter_spec.rb&line=58">./spec/rspec/core/formatters/text_mate_formatter_spec.rb:58</a> :in `block (4 levels) in &lt;module:Formatters&gt;&#39;
366
+ <a href="txmt://open?url=file:///Users/myron/code/rspec-dev/repos/rspec-core/spec/rspec/core/formatters/text_mate_formatter_spec.rb&line=57">./spec/rspec/core/formatters/text_mate_formatter_spec.rb:57</a> :in `chdir&#39;
367
+ <a href="txmt://open?url=file:///Users/myron/code/rspec-dev/repos/rspec-core/spec/rspec/core/formatters/text_mate_formatter_spec.rb&line=57">./spec/rspec/core/formatters/text_mate_formatter_spec.rb:57</a> :in `block (3 levels) in &lt;module:Formatters&gt;&#39;</pre></div>
364
368
  <pre class="ruby"><code><span class="linenum">31</span><span class="ident">describe</span> <span class="punct">&quot;</span><span class="string">failing spec</span><span class="punct">&quot;</span> <span class="keyword">do</span>
365
369
  <span class="linenum">32</span> <span class="ident">it</span> <span class="punct">&quot;</span><span class="string">fails</span><span class="punct">&quot;</span> <span class="keyword">do</span>
366
- <span class="offending"><span class="linenum">33</span> <span class="number">1</span><span class="punct">.</span><span class="ident">should</span> <span class="ident">eq</span><span class="punct">(</span><span class="number">2</span><span class="punct">)</span></span>
370
+ <span class="offending"><span class="linenum">33</span> <span class="ident">expect</span><span class="punct">(</span><span class="number">1</span><span class="punct">).</span><span class="ident">to</span> <span class="ident">eq</span><span class="punct">(</span><span class="number">2</span><span class="punct">)</span></span>
367
371
  <span class="linenum">34</span> <span class="keyword">end</span>
368
372
  <span class="linenum">35</span><span class="keyword">end</span></code></pre>
369
373
  </div>
@@ -381,12 +385,14 @@ expected: 2
381
385
  <span class="duration">n.nnnns</span>
382
386
  <div class="failure" id="failure_3">
383
387
  <div class="message"><pre>foo</pre></div>
384
- <div class="backtrace"><pre>(erb):1:in `result'
385
- <a href="txmt://open?url=file:///Users/alindeman/workspace/rspec-dev/repos/rspec-core/spec/rspec/core/resources/formatter_specs.rb&line=41">./spec/rspec/core/resources/formatter_specs.rb:41</a> :in `(root)'
386
- <a href="txmt://open?url=file:///Users/alindeman/workspace/rspec-dev/repos/rspec-core/spec/rspec/core/formatters/text_mate_formatter_spec.rb&line=31">./spec/rspec/core/formatters/text_mate_formatter_spec.rb:31</a> :in `Formatters'
387
- <a href="txmt://open?url=file:///Users/alindeman/workspace/rspec-dev/repos/rspec-core/spec/rspec/core/formatters/text_mate_formatter_spec.rb&line=53">./spec/rspec/core/formatters/text_mate_formatter_spec.rb:53</a> :in `Formatters'
388
- <a href="txmt://open?url=file:///Users/alindeman/workspace/rspec-dev/repos/rspec-core/spec/rspec/core/formatters/text_mate_formatter_spec.rb&line=53">./spec/rspec/core/formatters/text_mate_formatter_spec.rb:53</a> :in `Formatters'
389
- <a href="txmt://open?url=file:///Users/alindeman/workspace/rspec-dev/repos/rspec-core/spec/rspec/core/formatters/text_mate_formatter_spec.rb&line=52">./spec/rspec/core/formatters/text_mate_formatter_spec.rb:52</a> :in `Formatters'</pre></div>
388
+ <div class="backtrace"><pre>(erb):1:in `&lt;main&gt;&#39;
389
+ <a href="txmt://open?url=file:///Users/myron/code/rspec-dev/repos/rspec-core/spec/rspec/core/resources/formatter_specs.rb&line=41">./spec/rspec/core/resources/formatter_specs.rb:41</a> :in `block (2 levels) in &lt;top (required)&gt;&#39;
390
+ <a href="txmt://open?url=file:///Users/myron/code/rspec-dev/repos/rspec-core/spec/rspec/core/formatters/text_mate_formatter_spec.rb&line=36">./spec/rspec/core/formatters/text_mate_formatter_spec.rb:36</a> :in `block (2 levels) in &lt;module:Formatters&gt;&#39;
391
+ <a href="txmt://open?url=file:///Users/myron/code/rspec-dev/repos/rspec-core/spec/rspec/core/formatters/text_mate_formatter_spec.rb&line=58">./spec/rspec/core/formatters/text_mate_formatter_spec.rb:58</a> :in `block (5 levels) in &lt;module:Formatters&gt;&#39;
392
+ <a href="txmt://open?url=file:///Users/myron/code/rspec-dev/repos/rspec-core/spec/rspec/core/formatters/text_mate_formatter_spec.rb&line=58">./spec/rspec/core/formatters/text_mate_formatter_spec.rb:58</a> :in `open&#39;
393
+ <a href="txmt://open?url=file:///Users/myron/code/rspec-dev/repos/rspec-core/spec/rspec/core/formatters/text_mate_formatter_spec.rb&line=58">./spec/rspec/core/formatters/text_mate_formatter_spec.rb:58</a> :in `block (4 levels) in &lt;module:Formatters&gt;&#39;
394
+ <a href="txmt://open?url=file:///Users/myron/code/rspec-dev/repos/rspec-core/spec/rspec/core/formatters/text_mate_formatter_spec.rb&line=57">./spec/rspec/core/formatters/text_mate_formatter_spec.rb:57</a> :in `chdir&#39;
395
+ <a href="txmt://open?url=file:///Users/myron/code/rspec-dev/repos/rspec-core/spec/rspec/core/formatters/text_mate_formatter_spec.rb&line=57">./spec/rspec/core/formatters/text_mate_formatter_spec.rb:57</a> :in `block (3 levels) in &lt;module:Formatters&gt;&#39;</pre></div>
390
396
  <pre class="ruby"><code><span class="linenum">-1</span><span class="comment"># Couldn't get snippet for (erb)</span></code></pre>
391
397
  </div>
392
398
  </dd>
@@ -396,7 +402,7 @@ expected: 2
396
402
  <span class="duration">n.nnnns</span>
397
403
  <div class="failure" id="failure_4">
398
404
  <div class="message"><pre>Exception</pre></div>
399
- <div class="backtrace"><pre><a href="txmt://open?url=file:///foo.html.erb&line=1">/foo.html.erb:1</a> :in `&lt;main&gt;': foo (RuntimeError)</pre></div>
405
+ <div class="backtrace"><pre><a href="txmt://open?url=file:///foo.html.erb&line=1">/foo.html.erb:1</a> :in `&lt;main&gt;&#39;: foo (RuntimeError)</pre></div>
400
406
  <pre class="ruby"><code><span class="linenum">-1</span><span class="comment"># Couldn't get snippet for /foo.html.erb</span></code></pre>
401
407
  </div>
402
408
  </dd>
@@ -27,7 +27,11 @@ module RSpec
27
27
  %w[spec/rspec/core/resources/formatter_specs.rb --format textmate --order default]
28
28
  )
29
29
  options.parse_options
30
+
30
31
  err, out = StringIO.new, StringIO.new
32
+ err.set_encoding("utf-8") if err.respond_to?(:set_encoding)
33
+ out.set_encoding("utf-8") if out.respond_to?(:set_encoding)
34
+
31
35
  command_line = RSpec::Core::CommandLine.new(options)
32
36
  command_line.run(err, out)
33
37
  out.string.gsub(/\d+\.\d+(s| seconds)/, "n.nnnn\\1")
@@ -65,10 +69,10 @@ module RSpec
65
69
  expected_doc = Nokogiri::HTML(expected_html)
66
70
  expected_doc.search("div.backtrace").remove
67
71
 
68
- actual_doc.inner_html.should eq(expected_doc.inner_html)
72
+ expect(actual_doc.inner_html).to eq(expected_doc.inner_html)
69
73
 
70
74
  backtrace_lines.each do |backtrace_line|
71
- backtrace_line['href'].should include("txmt://open?url=")
75
+ expect(backtrace_line['href']).to include("txmt://open?url=")
72
76
  end
73
77
  end
74
78
  end
@@ -77,12 +81,12 @@ module RSpec
77
81
  Dir.chdir(root) do
78
82
  actual_doc = Nokogiri::HTML(generated_html)
79
83
 
80
- actual_doc.inner_html.should include('(erb):1')
84
+ expect(actual_doc.inner_html).to include('(erb):1')
81
85
  end
82
86
  end
83
87
 
84
88
  it "has a backtrace line from a erb source file we forced to appear" do
85
- generated_html.should include('open?url=file:///foo.html.erb')
89
+ expect(generated_html).to include('open?url=file:///foo.html.erb')
86
90
  end
87
91
 
88
92
  end
@@ -15,7 +15,7 @@ module RSpec::Core
15
15
  group = ExampleGroup.describe
16
16
  group.example("example") {}
17
17
  group.run
18
- filters.should eq([
18
+ expect(filters).to eq([
19
19
  "before all in config",
20
20
  "around each in config",
21
21
  "before each in config",
@@ -38,7 +38,7 @@ module RSpec::Core
38
38
  group = ExampleGroup.describe(:match => true)
39
39
  group.example("example") {}
40
40
  group.run
41
- filters.should eq([
41
+ expect(filters).to eq([
42
42
  "around each in config",
43
43
  "before each in config",
44
44
  "after each in config"
@@ -58,7 +58,7 @@ module RSpec::Core
58
58
  group = ExampleGroup.describe(:match => true)
59
59
  group.example("example") {}
60
60
  group.run
61
- filters.should eq([
61
+ expect(filters).to eq([
62
62
  "before all in config",
63
63
  "around each in config",
64
64
  "before each in config",
@@ -84,9 +84,9 @@ module RSpec::Core
84
84
  end
85
85
  group.run
86
86
 
87
- example_1_filters.should be_empty
88
- example_2_filters.should eq([:before_all])
89
- filters.should eq([:before_all, :after_all])
87
+ expect(example_1_filters).to be_empty
88
+ expect(example_2_filters).to eq([:before_all])
89
+ expect(filters).to eq([:before_all, :after_all])
90
90
  end
91
91
 
92
92
  it "runs before|after :all hooks only on the highest level group that matches the filter" do
@@ -109,11 +109,11 @@ module RSpec::Core
109
109
  end
110
110
  group.run
111
111
 
112
- example_1_filters.should eq([:before_all])
113
- example_2_filters.should eq([:before_all])
114
- example_3_filters.should eq([:before_all])
112
+ expect(example_1_filters).to eq([:before_all])
113
+ expect(example_2_filters).to eq([:before_all])
114
+ expect(example_3_filters).to eq([:before_all])
115
115
 
116
- filters.should eq([:before_all, :after_all])
116
+ expect(filters).to eq([:before_all, :after_all])
117
117
  end
118
118
 
119
119
  it "does not run if the filter doesn't match the example group's filter" do
@@ -128,7 +128,7 @@ module RSpec::Core
128
128
  group = ExampleGroup.describe(:match => true)
129
129
  group.example("example") {}
130
130
  group.run
131
- filters.should eq([])
131
+ expect(filters).to eq([])
132
132
  end
133
133
 
134
134
  context "when the hook filters apply to individual examples instead of example groups" do
@@ -164,7 +164,7 @@ module RSpec::Core
164
164
  let(:example_metadata) { { :foo => :bar } }
165
165
 
166
166
  it "runs the `:each` hooks" do
167
- each_filters.should eq([
167
+ expect(each_filters).to eq([
168
168
  'around each in config',
169
169
  'before each in config',
170
170
  'after each in config'
@@ -172,7 +172,7 @@ module RSpec::Core
172
172
  end
173
173
 
174
174
  it "does not run the `:all` hooks" do
175
- all_filters.should be_empty
175
+ expect(all_filters).to be_empty
176
176
  end
177
177
  end
178
178
 
@@ -180,7 +180,7 @@ module RSpec::Core
180
180
  let(:example_metadata) { { :foo => :bazz } }
181
181
 
182
182
  it "does not run any of the hooks" do
183
- filters.should be_empty
183
+ expect(filters).to be_empty
184
184
  end
185
185
  end
186
186
  end
@@ -199,7 +199,7 @@ module RSpec::Core
199
199
  group = ExampleGroup.describe(:one => 1, :two => 2, :three => 3)
200
200
  group.example("example") {}
201
201
  group.run
202
- filters.should eq([
202
+ expect(filters).to eq([
203
203
  "before all in config",
204
204
  "around each in config",
205
205
  "before each in config",
@@ -220,7 +220,7 @@ module RSpec::Core
220
220
  group = ExampleGroup.describe(:one => 1, :two => 2, :three => 3)
221
221
  group.example("example") {}
222
222
  group.run
223
- filters.should eq([])
223
+ expect(filters).to eq([])
224
224
  end
225
225
  end
226
226
  end
@@ -35,13 +35,13 @@ module RSpec::Core
35
35
  it "defaults to :each scope if no arguments are given" do
36
36
  hooks = instance.send(type) {}
37
37
  hook = hooks.first
38
- instance.hooks[type][:each].should include(hook)
38
+ expect(instance.hooks[type][:each]).to include(hook)
39
39
  end
40
40
 
41
41
  it "defaults to :each scope if the only argument is a metadata hash" do
42
42
  hooks = instance.send(type, :foo => :bar) {}
43
43
  hook = hooks.first
44
- instance.hooks[type][:each].should include(hook)
44
+ expect(instance.hooks[type][:each]).to include(hook)
45
45
  end
46
46
 
47
47
  it "raises an error if only metadata symbols are given as arguments" do
@@ -68,11 +68,11 @@ module RSpec::Core
68
68
  end
69
69
 
70
70
  it "does not make #{scope.inspect} a metadata key" do
71
- hook.options.should be_empty
71
+ expect(hook.options).to be_empty
72
72
  end
73
73
 
74
74
  it "is scoped to #{scope.inspect}" do
75
- instance.hooks[type][scope].should include(hook)
75
+ expect(instance.hooks[type][scope]).to include(hook)
76
76
  end
77
77
  end
78
78
  end
@@ -92,7 +92,7 @@ module RSpec::Core
92
92
  end
93
93
  end
94
94
  group.run
95
- examples.should have(0).example
95
+ expect(examples).to have(0).example
96
96
  end
97
97
  end
98
98
 
@@ -108,7 +108,7 @@ module RSpec::Core
108
108
  end
109
109
  end
110
110
  group.run
111
- examples.should have(1).example
111
+ expect(examples).to have(1).example
112
112
  end
113
113
  end
114
114
 
@@ -128,7 +128,7 @@ module RSpec::Core
128
128
  end
129
129
  end
130
130
  group.run
131
- examples.should have(1).example
131
+ expect(examples).to have(1).example
132
132
  end
133
133
  end
134
134
  end
@@ -151,7 +151,7 @@ module RSpec::Core
151
151
 
152
152
  group.run
153
153
 
154
- messages.should eq([
154
+ expect(messages).to eq([
155
155
  'group 1',
156
156
  'group 2',
157
157
  'config 1',
@@ -179,7 +179,7 @@ module RSpec::Core
179
179
 
180
180
  group.run
181
181
 
182
- messages.should eq([
182
+ expect(messages).to eq([
183
183
  'config 1',
184
184
  'config 2',
185
185
  'config 3',
@@ -205,7 +205,7 @@ module RSpec::Core
205
205
 
206
206
  group.run
207
207
 
208
- messages.should eq([
208
+ expect(messages).to eq([
209
209
  'group 1',
210
210
  'group 2',
211
211
  'group 3',
@@ -233,7 +233,7 @@ module RSpec::Core
233
233
 
234
234
  group.run
235
235
 
236
- messages.should eq([
236
+ expect(messages).to eq([
237
237
  'group 1',
238
238
  'group 2',
239
239
  'config 1',
@@ -3,7 +3,7 @@ require 'spec_helper'
3
3
  describe "extensions" do
4
4
  describe "debugger" do
5
5
  it "is defined on Kernel" do
6
- Kernel.should respond_to(:debugger)
6
+ expect(Kernel).to respond_to(:debugger)
7
7
  end
8
8
  end
9
9
  end
@@ -0,0 +1,458 @@
1
+ require 'spec_helper'
2
+
3
+ module RSpec::Core
4
+ describe MemoizedHelpers do
5
+ before(:each) { RSpec.configuration.configure_expectation_framework }
6
+
7
+ def subject_value_for(describe_arg, &block)
8
+ group = ExampleGroup.describe(describe_arg, &block)
9
+ subject_value = nil
10
+ group.example { subject_value = subject }
11
+ group.run
12
+ subject_value
13
+ end
14
+
15
+ describe "implicit subject" do
16
+ describe "with a class" do
17
+ it "returns an instance of the class" do
18
+ expect(subject_value_for(Array)).to eq([])
19
+ end
20
+ end
21
+
22
+ describe "with a Module" do
23
+ it "returns the Module" do
24
+ expect(subject_value_for(Enumerable)).to eq(Enumerable)
25
+ end
26
+ end
27
+
28
+ describe "with a string" do
29
+ it "returns the string" do
30
+ expect(subject_value_for("Foo")).to eq("Foo")
31
+ end
32
+ end
33
+
34
+ describe "with a number" do
35
+ it "returns the number" do
36
+ expect(subject_value_for(15)).to eq(15)
37
+ end
38
+ end
39
+
40
+ it "can be overriden and super'd to from a nested group" do
41
+ outer_subject_value = inner_subject_value = nil
42
+
43
+ ExampleGroup.describe(Array) do
44
+ subject { super() << :parent_group }
45
+ example { outer_subject_value = subject }
46
+
47
+ context "nested" do
48
+ subject { super() << :child_group }
49
+ example { inner_subject_value = subject }
50
+ end
51
+ end.run
52
+
53
+ expect(outer_subject_value).to eq([:parent_group])
54
+ expect(inner_subject_value).to eq([:parent_group, :child_group])
55
+ end
56
+ end
57
+
58
+ describe "explicit subject" do
59
+ [false, nil].each do |falsy_value|
60
+ context "with a value of #{falsy_value.inspect}" do
61
+ it "is evaluated once per example" do
62
+ group = ExampleGroup.describe(Array)
63
+ group.before do
64
+ Object.should_receive(:this_question?).once.and_return(falsy_value)
65
+ end
66
+ group.subject do
67
+ Object.this_question?
68
+ end
69
+ group.example do
70
+ subject
71
+ subject
72
+ end
73
+ expect(group.run).to be_true, "expected subject block to be evaluated only once"
74
+ end
75
+ end
76
+ end
77
+
78
+ describe "defined in a top level group" do
79
+ it "replaces the implicit subject in that group" do
80
+ subject_value = subject_value_for(Array) do
81
+ subject { [1, 2, 3] }
82
+ end
83
+ expect(subject_value).to eq([1, 2, 3])
84
+ end
85
+ end
86
+
87
+ describe "defined in a top level group" do
88
+ let(:group) do
89
+ ExampleGroup.describe do
90
+ subject{ [4, 5, 6] }
91
+ end
92
+ end
93
+
94
+ it "is available in a nested group (subclass)" do
95
+ subject_value = nil
96
+ group.describe("I'm nested!") do
97
+ example { subject_value = subject }
98
+ end.run
99
+
100
+ expect(subject_value).to eq([4, 5, 6])
101
+ end
102
+
103
+ it "is available in a doubly nested group (subclass)" do
104
+ subject_value = nil
105
+ group.describe("Nesting level 1") do
106
+ describe("Nesting level 2") do
107
+ example { subject_value = subject }
108
+ end
109
+ end.run
110
+
111
+ expect(subject_value).to eq([4, 5, 6])
112
+ end
113
+
114
+ it "can be overriden and super'd to from a nested group" do
115
+ subject_value = nil
116
+ group.describe("Nested") do
117
+ subject { super() + [:override] }
118
+ example { subject_value = subject }
119
+ end.run
120
+
121
+ expect(subject_value).to eq([4, 5, 6, :override])
122
+ end
123
+ end
124
+
125
+ describe "with a name" do
126
+ it "defines a method that returns the memoized subject" do
127
+ list_value_1 = list_value_2 = subject_value_1 = subject_value_2 = nil
128
+
129
+ ExampleGroup.describe do
130
+ subject(:list) { [1, 2, 3] }
131
+ example do
132
+ list_value_1 = list
133
+ list_value_2 = list
134
+ subject_value_1 = subject
135
+ subject_value_2 = subject
136
+ end
137
+ end.run
138
+
139
+ expect(list_value_1).to eq([1, 2, 3])
140
+ expect(list_value_1).to equal(list_value_2)
141
+
142
+ expect(subject_value_1).to equal(subject_value_2)
143
+ expect(subject_value_1).to equal(list_value_1)
144
+ end
145
+
146
+ it "is referred from inside subject by the name" do
147
+ inner_subject_value = nil
148
+
149
+ ExampleGroup.describe do
150
+ subject(:list) { [1, 2, 3] }
151
+ describe 'first' do
152
+ subject(:first_element) { list.first }
153
+ example { inner_subject_value = subject }
154
+ end
155
+ end.run
156
+
157
+ expect(inner_subject_value).to eq(1)
158
+ end
159
+
160
+ context 'when `super` is used' do
161
+ it "delegates to the parent context's `subject`, not the named mehtod" do
162
+ inner_subject_value = nil
163
+
164
+ ExampleGroup.describe do
165
+ let(:list) { ["a", "b", "c"] }
166
+ subject { [1, 2, 3] }
167
+
168
+ describe 'first' do
169
+ subject(:list) { super().first(2) }
170
+ example { inner_subject_value = subject }
171
+ end
172
+ end.run
173
+
174
+ expect(inner_subject_value).to eq([1, 2])
175
+ end
176
+ end
177
+ end
178
+ end
179
+
180
+ context "using 'self' as an explicit subject" do
181
+ it "delegates matcher to the ExampleGroup" do
182
+ group = ExampleGroup.describe("group") do
183
+ subject { self }
184
+ def ok?; true; end
185
+ def not_ok?; false; end
186
+
187
+ it { should eq(self) }
188
+ it { should be_ok }
189
+ it { should_not be_not_ok }
190
+ end
191
+
192
+ expect(group.run).to be_true
193
+ end
194
+ end
195
+
196
+ describe "#its" do
197
+ subject do
198
+ Class.new do
199
+ def initialize
200
+ @call_count = 0
201
+ end
202
+
203
+ def call_count
204
+ @call_count += 1
205
+ end
206
+ end.new
207
+ end
208
+
209
+ context "with a call counter" do
210
+ its(:call_count) { should eq(1) }
211
+ end
212
+
213
+ context "with nil value" do
214
+ subject do
215
+ Class.new do
216
+ def nil_value
217
+ nil
218
+ end
219
+ end.new
220
+ end
221
+ its(:nil_value) { should be_nil }
222
+ end
223
+
224
+ context "with nested attributes" do
225
+ subject do
226
+ Class.new do
227
+ def name
228
+ "John"
229
+ end
230
+ end.new
231
+ end
232
+ its("name") { should eq("John") }
233
+ its("name.size") { should eq(4) }
234
+ its("name.size.class") { should eq(Fixnum) }
235
+ end
236
+
237
+ context "when it responds to #[]" do
238
+ subject do
239
+ Class.new do
240
+ def [](*objects)
241
+ objects.map do |object|
242
+ "#{object.class}: #{object.to_s}"
243
+ end.join("; ")
244
+ end
245
+
246
+ def name
247
+ "George"
248
+ end
249
+ end.new
250
+ end
251
+ its([:a]) { should eq("Symbol: a") }
252
+ its(['a']) { should eq("String: a") }
253
+ its([:b, 'c', 4]) { should eq("Symbol: b; String: c; Fixnum: 4") }
254
+ its(:name) { should eq("George") }
255
+ context "when referring to an attribute without the proper array syntax" do
256
+ context "it raises an error" do
257
+ its(:age) do
258
+ expect do
259
+ should eq(64)
260
+ end.to raise_error(NoMethodError)
261
+ end
262
+ end
263
+ end
264
+ end
265
+
266
+ context "when it does not respond to #[]" do
267
+ subject { Object.new }
268
+
269
+ context "it raises an error" do
270
+ its([:a]) do
271
+ expect do
272
+ should eq("Symbol: a")
273
+ end.to raise_error(NoMethodError)
274
+ end
275
+ end
276
+ end
277
+
278
+ context "calling and overriding super" do
279
+ it "calls to the subject defined in the parent group" do
280
+ group = ExampleGroup.describe(Array) do
281
+ subject { [1, 'a'] }
282
+
283
+ its(:last) { should eq("a") }
284
+
285
+ describe '.first' do
286
+ def subject; super().first; end
287
+
288
+ its(:next) { should eq(2) }
289
+ end
290
+ end
291
+
292
+ expect(group.run).to be_true
293
+ end
294
+ end
295
+
296
+ context "with nil subject" do
297
+ subject do
298
+ Class.new do
299
+ def initialize
300
+ @counter = -1
301
+ end
302
+ def nil_if_first_time
303
+ @counter += 1
304
+ @counter == 0 ? nil : true
305
+ end
306
+ end.new
307
+ end
308
+ its(:nil_if_first_time) { should be(nil) }
309
+ end
310
+
311
+ context "with false subject" do
312
+ subject do
313
+ Class.new do
314
+ def initialize
315
+ @counter = -1
316
+ end
317
+ def false_if_first_time
318
+ @counter += 1
319
+ @counter > 0
320
+ end
321
+ end.new
322
+ end
323
+ its(:false_if_first_time) { should be(false) }
324
+ end
325
+
326
+ describe 'accessing `subject` in `before` and `let`' do
327
+ subject { 'my subject' }
328
+ before { @subject_in_before = subject }
329
+ let(:subject_in_let) { subject }
330
+ let!(:eager_loaded_subject_in_let) { subject }
331
+
332
+ # These examples read weird, because we're actually
333
+ # specifying the behaviour of `its` itself
334
+ its(nil) { expect(subject).to eq('my subject') }
335
+ its(nil) { expect(@subject_in_before).to eq('my subject') }
336
+ its(nil) { expect(subject_in_let).to eq('my subject') }
337
+ its(nil) { expect(eager_loaded_subject_in_let).to eq('my subject') }
338
+ end
339
+ end
340
+
341
+ describe '#subject!' do
342
+ let(:prepared_array) { [1,2,3] }
343
+ subject! { prepared_array.pop }
344
+
345
+ it "evaluates subject before example" do
346
+ expect(prepared_array).to eq([1,2])
347
+ end
348
+
349
+ it "returns memoized value from first invocation" do
350
+ expect(subject).to eq(3)
351
+ end
352
+ end
353
+ end
354
+
355
+ describe "#let" do
356
+ let(:counter) do
357
+ Class.new do
358
+ def initialize
359
+ @count = 0
360
+ end
361
+ def count
362
+ @count += 1
363
+ end
364
+ end.new
365
+ end
366
+
367
+ let(:nil_value) do
368
+ @nil_value_count += 1
369
+ nil
370
+ end
371
+
372
+ it "generates an instance method" do
373
+ expect(counter.count).to eq(1)
374
+ end
375
+
376
+ it "caches the value" do
377
+ expect(counter.count).to eq(1)
378
+ expect(counter.count).to eq(2)
379
+ end
380
+
381
+ it "caches a nil value" do
382
+ @nil_value_count = 0
383
+ nil_value
384
+ nil_value
385
+
386
+ expect(@nil_value_count).to eq(1)
387
+ end
388
+
389
+ let(:a_value) { "a string" }
390
+
391
+ context 'when overriding let in a nested context' do
392
+ let(:a_value) { super() + " (modified)" }
393
+
394
+ it 'can use `super` to reference the parent context value' do
395
+ expect(a_value).to eq("a string (modified)")
396
+ end
397
+ end
398
+
399
+ context 'when the declaration uses `return`' do
400
+ let(:value) do
401
+ return :early_exit if @early_exit
402
+ :late_exit
403
+ end
404
+
405
+ it 'can exit the let declaration early' do
406
+ @early_exit = true
407
+ expect(value).to eq(:early_exit)
408
+ end
409
+
410
+ it 'can get past a conditional `return` statement' do
411
+ @early_exit = false
412
+ expect(value).to eq(:late_exit)
413
+ end
414
+ end
415
+ end
416
+
417
+ describe "#let!" do
418
+ subject { [1,2,3] }
419
+ let!(:popped) { subject.pop }
420
+
421
+ it "evaluates the value non-lazily" do
422
+ expect(subject).to eq([1,2])
423
+ end
424
+
425
+ it "returns memoized value from first invocation" do
426
+ expect(popped).to eq(3)
427
+ end
428
+ end
429
+
430
+ describe 'using subject in before and let blocks' do
431
+ shared_examples_for 'a subject' do
432
+ let(:subject_id_in_let) { subject.object_id }
433
+ before { @subject_id_in_before = subject.object_id }
434
+
435
+ it 'should be memoized' do
436
+ expect(subject_id_in_let).to eq(@subject_id_in_before)
437
+ end
438
+
439
+ it { should eq(subject) }
440
+ end
441
+
442
+ describe Object do
443
+ context 'with implicit subject' do
444
+ it_should_behave_like 'a subject'
445
+ end
446
+
447
+ context 'with explicit subject' do
448
+ subject { Object.new }
449
+ it_should_behave_like 'a subject'
450
+ end
451
+
452
+ context 'with a constant subject'do
453
+ subject { 123 }
454
+ it_should_behave_like 'a subject'
455
+ end
456
+ end
457
+ end
458
+ end