rspec-core 2.4.0 → 2.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (78) hide show
  1. data/.gitignore +1 -0
  2. data/Gemfile +9 -4
  3. data/Guardfile +3 -3
  4. data/README.md +1 -1
  5. data/features/.nav +7 -2
  6. data/features/{README.markdown → Autotest.md} +17 -20
  7. data/features/Changelog.md +57 -2
  8. data/features/README.md +17 -0
  9. data/features/Upgrade.md +8 -66
  10. data/features/command_line/configure.feature +2 -2
  11. data/features/command_line/example_name_option.feature +10 -10
  12. data/features/command_line/exit_status.feature +4 -4
  13. data/features/command_line/line_number_appended_to_path.feature +11 -11
  14. data/features/command_line/line_number_option.feature +9 -9
  15. data/features/command_line/tag.feature +9 -9
  16. data/features/configuration/custom_settings.feature +3 -3
  17. data/features/configuration/fail_fast.feature +3 -3
  18. data/features/configuration/read_options_from_file.feature +4 -4
  19. data/features/example_groups/shared_example_group.feature +4 -4
  20. data/features/expectation_framework_integration/configure_expectation_framework.feature +8 -9
  21. data/features/filtering/exclusion_filters.feature +1 -1
  22. data/features/filtering/run_all_when_everything_filtered.feature +1 -1
  23. data/features/formatters/custom_formatter.feature +17 -13
  24. data/features/helper_methods/arbitrary_methods.feature +40 -0
  25. data/features/helper_methods/let.feature +50 -0
  26. data/features/hooks/before_and_after_hooks.feature +10 -10
  27. data/features/hooks/filtering.feature +37 -20
  28. data/features/metadata/described_class.feature +1 -1
  29. data/features/mock_framework_integration/use_flexmock.feature +1 -1
  30. data/features/mock_framework_integration/use_mocha.feature +1 -1
  31. data/features/mock_framework_integration/use_rr.feature +1 -1
  32. data/features/mock_framework_integration/use_rspec.feature +1 -1
  33. data/features/spec_files/arbitrary_file_suffix.feature +1 -1
  34. data/features/step_definitions/additional_cli_steps.rb +1 -1
  35. data/features/subject/attribute_of_subject.feature +2 -2
  36. data/features/subject/explicit_subject.feature +5 -5
  37. data/features/subject/implicit_receiver.feature +2 -2
  38. data/features/subject/implicit_subject.feature +2 -2
  39. data/lib/autotest/rspec2.rb +63 -13
  40. data/lib/rspec/core/configuration.rb +0 -1
  41. data/lib/rspec/core/configuration_options.rb +15 -12
  42. data/lib/rspec/core/example.rb +14 -6
  43. data/lib/rspec/core/example_group.rb +5 -4
  44. data/lib/rspec/core/formatters/base_formatter.rb +1 -1
  45. data/lib/rspec/core/formatters/documentation_formatter.rb +1 -1
  46. data/lib/rspec/core/formatters/html_formatter.rb +131 -32
  47. data/lib/rspec/core/formatters/snippet_extractor.rb +1 -1
  48. data/lib/rspec/core/hooks.rb +16 -1
  49. data/lib/rspec/core/option_parser.rb +6 -6
  50. data/lib/rspec/core/rake_task.rb +1 -1
  51. data/lib/rspec/core/subject.rb +7 -7
  52. data/lib/rspec/core/version.rb +1 -1
  53. data/rspec-core.gemspec +0 -12
  54. data/script/FullBuildRakeFile +63 -0
  55. data/script/cucumber +1 -0
  56. data/script/full_build +1 -0
  57. data/script/spec +1 -0
  58. data/spec/autotest/failed_results_re_spec.rb +22 -5
  59. data/spec/autotest/rspec_spec.rb +132 -16
  60. data/spec/rspec/core/configuration_options_spec.rb +38 -6
  61. data/spec/rspec/core/example_group_spec.rb +15 -64
  62. data/spec/rspec/core/formatters/base_formatter_spec.rb +23 -0
  63. data/spec/rspec/core/formatters/html_formatted-1.8.6.html +150 -48
  64. data/spec/rspec/core/formatters/html_formatted-1.8.7-jruby.html +151 -49
  65. data/spec/rspec/core/formatters/html_formatted-1.8.7.html +150 -48
  66. data/spec/rspec/core/formatters/html_formatted-1.9.1.html +150 -48
  67. data/spec/rspec/core/formatters/html_formatted-1.9.2.html +150 -48
  68. data/spec/rspec/core/formatters/text_mate_formatted-1.8.6.html +150 -48
  69. data/spec/rspec/core/formatters/text_mate_formatted-1.8.7-jruby.html +151 -49
  70. data/spec/rspec/core/formatters/text_mate_formatted-1.8.7.html +150 -48
  71. data/spec/rspec/core/formatters/text_mate_formatted-1.9.1.html +150 -48
  72. data/spec/rspec/core/formatters/text_mate_formatted-1.9.2.html +150 -48
  73. data/spec/rspec/core/hooks_filtering_spec.rb +49 -0
  74. data/spec/rspec/core/rake_task_spec.rb +3 -3
  75. data/spec/rspec/core/subject_spec.rb +81 -0
  76. metadata +20 -22
  77. data/History.markdown +0 -186
  78. data/Upgrade.markdown +0 -345
@@ -0,0 +1,63 @@
1
+ # this is in a separate rakefile because our main one depends on the bundled gems
2
+ # already being installed. This must be able to run w/o bundled gems installed.
3
+
4
+ def rake(command = "")
5
+ sh "rake #{command}"
6
+ end
7
+
8
+ desc "Run a full build: install necessary gems with bundler, runs specs, run cukes"
9
+ task :build => :bundle_install do
10
+ rake
11
+ end
12
+
13
+ desc "Install necessary gems with bundler and runs specs"
14
+ task :spec => :bundle_install do
15
+ rake "spec"
16
+ end
17
+
18
+ desc "Install necessary gems with bundler and runs cukes"
19
+ task :cucumber => :bundle_install do
20
+ rake "cucumber"
21
+ end
22
+
23
+ desc "Prints description of current ruby interpreter"
24
+ task :print_ruby_description do
25
+ description = if defined?(RUBY_DESCRIPTION)
26
+ RUBY_DESCRIPTION
27
+ else
28
+ # RUBY_DESCRIPTION is undefined on 1.8.6
29
+ "ruby #{RUBY_VERSION} (#{RUBY_RELEASE_DATE} patchlevel #{RUBY_PATCHLEVEL}) [#{RUBY_PLATFORM}]"
30
+ end
31
+
32
+ puts
33
+ puts "=" * 80
34
+ puts "Using #{description}"
35
+ puts "=" * 80
36
+ puts
37
+ end
38
+
39
+ task :bundle_install => :ensure_bundler_installed do
40
+ # Unfortunately, there is no version of ruby-debug that installs cleanly on 1.9.1 and 1.9.2.
41
+ # Our Gemfile specifies different versions using conditionals, but we still need to bundle update
42
+ # to get bundler to use the different versions.
43
+ if RUBY_VERSION =~ /^1\.9/
44
+ sh "bundle update ruby-debug-base19"
45
+ end
46
+
47
+ sh "bundle install"
48
+ end
49
+
50
+ task :ensure_bundler_installed => :print_ruby_description do
51
+ installed = begin
52
+ require 'rubygems'
53
+ require 'bundler'
54
+ true
55
+ rescue LoadError
56
+ false
57
+ end
58
+
59
+ unless installed
60
+ sh "gem install bundler"
61
+ end
62
+ end
63
+
@@ -0,0 +1 @@
1
+ rvm 1.8.6,1.8.7,ree,1.9.1,1.9.2,jruby rake -f script/FullBuildRakeFile cucumber | tee tmp/cucumber.out
@@ -0,0 +1 @@
1
+ rvm 1.8.6,1.8.7,ree,1.9.1,1.9.2,jruby rake -f script/FullBuildRakeFile build | tee tmp/full_build.out
@@ -0,0 +1 @@
1
+ rvm 1.8.6,1.8.7,ree,1.9.1,1.9.2,jruby rake -f script/FullBuildRakeFile spec | tee tmp/spec.out
@@ -7,14 +7,31 @@ describe "failed_results_re for autotest" do
7
7
  group = RSpec::Core::ExampleGroup.describe("group name")
8
8
  group.example("example name") { "this".should eq("that") }
9
9
  group.run(formatter)
10
- RSpec.configuration.stub(:color_enabled?) { false }
11
10
  formatter.dump_failures
12
11
  output.string
13
12
  end
14
13
 
15
- it "matches a failure" do
16
- re = Autotest::Rspec2.new.failed_results_re
17
- example_output.should =~ re
18
- example_output[re, 2].should == __FILE__.sub(File.expand_path('.'),'.')
14
+ context "output does not have color enabled" do
15
+ before do
16
+ RSpec.configuration.stub(:color_enabled?) { false }
17
+ end
18
+
19
+ it "matches a failure" do
20
+ re = Autotest::Rspec2.new.failed_results_re
21
+ example_output.should =~ re
22
+ example_output[re, 2].should == __FILE__.sub(File.expand_path('.'),'.')
23
+ end
24
+ end
25
+
26
+ context "output has color enabled" do
27
+ before do
28
+ RSpec.configuration.stub(:color_enabled?) { true }
29
+ end
30
+
31
+ it "matches a failure" do
32
+ re = Autotest::Rspec2.new.failed_results_re
33
+ example_output.should =~ re
34
+ example_output[re, 2].should == __FILE__.sub(File.expand_path('.'),'.')
35
+ end
19
36
  end
20
37
  end
@@ -5,6 +5,138 @@ describe Autotest::Rspec2 do
5
5
  let(:spec_cmd) { File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'bin', 'rspec')) }
6
6
  let(:ruby_cmd) { "ruby" }
7
7
 
8
+ before do
9
+ RSpec.stub(:warn_deprecation)
10
+ File.stub(:exist?) { false }
11
+ @orig_argv = ARGV.dup; ARGV.clear
12
+ end
13
+
14
+ after { ARGV.clear; ARGV.concat(@orig_argv) }
15
+
16
+ context "with ARGV" do
17
+ it "passes ARGV to command" do
18
+ ARGV.concat(%w[-c -f d])
19
+ rspec_autotest.cl_args.should eq(%w[-c -f d --tty])
20
+ end
21
+
22
+ context "with --skip-bundler" do
23
+ before do
24
+ ARGV.concat(%w[--skip-bundler])
25
+ end
26
+ it "extracts --skip-bundler" do
27
+ rspec_autotest.cl_args.should eq(%w[--tty])
28
+ end
29
+
30
+ it "sets skip_bundler? true" do
31
+ rspec_autotest.skip_bundler?.should be_true
32
+ end
33
+ end
34
+ end
35
+
36
+ describe "handling bundler" do
37
+ context "gemfile, no prefix" do
38
+ before do
39
+ File.stub(:exist?).with("./Gemfile") { true }
40
+ end
41
+
42
+ it "warns of deprecation of implicit inclusion of 'bundle exec'" do
43
+ RSpec.should_receive(:warn_deprecation)
44
+ rspec_autotest.make_test_cmd({})
45
+ end
46
+
47
+ it "includes bundle exec" do
48
+ rspec_autotest.
49
+ make_test_cmd({'a' => 'b'}).should match(/bundle exec/)
50
+ end
51
+ end
52
+
53
+ context "gemfile, no prefix, --skip-bundler" do
54
+ before do
55
+ File.stub(:exist?).with("./Gemfile") { true }
56
+ ARGV.concat(%w[--skip-bundler])
57
+ end
58
+
59
+ it "does not warn" do
60
+ RSpec.should_not_receive(:warn_deprecation)
61
+ rspec_autotest.make_test_cmd({})
62
+ end
63
+
64
+ it "does not include bundle exec" do
65
+ rspec_autotest.
66
+ make_test_cmd({'a' => 'b'}).should_not match(/bundle exec/)
67
+ end
68
+ end
69
+
70
+ context "no gemfile, prefix" do
71
+ before do
72
+ File.stub(:exist?).with("./Gemfile") { false }
73
+ end
74
+
75
+ it "does not warn" do
76
+ RSpec.should_not_receive(:warn_deprecation)
77
+ rspec_autotest.make_test_cmd({'a' => 'b'})
78
+ end
79
+
80
+ it "includes bundle exec" do
81
+ rspec_autotest.prefix = "bundle exec "
82
+ rspec_autotest.
83
+ make_test_cmd({'a' => 'b'}).should match(/bundle exec/)
84
+ end
85
+ end
86
+
87
+ context "gemfile, prefix" do
88
+ before do
89
+ File.stub(:exist?).with("./Gemfile") { true }
90
+ rspec_autotest.prefix = "bundle exec "
91
+ end
92
+
93
+ it "does not warn" do
94
+ RSpec.should_not_receive(:warn_deprecation)
95
+ rspec_autotest.make_test_cmd({'a' => 'b'})
96
+ end
97
+
98
+ it "includes bundle exec" do
99
+ rspec_autotest.prefix = "bundle exec "
100
+ rspec_autotest.
101
+ make_test_cmd({'a' => 'b'}).should match(/bundle exec/)
102
+ end
103
+ end
104
+
105
+ context "gemfile, prefix, --skip-bundler" do
106
+ before do
107
+ File.stub(:exist?).with("./Gemfile") { true }
108
+ rspec_autotest.prefix = "bundle exec "
109
+ rspec_autotest.stub(:skip_bundler?) { true }
110
+ end
111
+
112
+ it "does not warn" do
113
+ RSpec.should_not_receive(:warn_deprecation)
114
+ rspec_autotest.make_test_cmd({'a' => 'b'})
115
+ end
116
+
117
+ it "does not include bundle exec" do
118
+ rspec_autotest.
119
+ make_test_cmd({'a' => 'b'}).should_not match(/bundle exec/)
120
+ end
121
+ end
122
+
123
+ context "no gemfile, no prefix" do
124
+ before do
125
+ File.stub(:exist?).with("./Gemfile") { false }
126
+ end
127
+
128
+ it "does not warn" do
129
+ RSpec.should_not_receive(:warn_deprecation)
130
+ rspec_autotest.make_test_cmd({'a' => 'b'})
131
+ end
132
+
133
+ it "does not include bundle exec" do
134
+ rspec_autotest.
135
+ make_test_cmd({'a' => 'b'}).should_not match(/bundle exec/)
136
+ end
137
+ end
138
+ end
139
+
8
140
  describe "commands" do
9
141
  before do
10
142
  rspec_autotest.stub(:ruby => ruby_cmd)
@@ -110,20 +242,4 @@ describe Autotest::Rspec2 do
110
242
  rspec_autotest.normalize(@files_to_test).should have(1).file
111
243
  end
112
244
  end
113
-
114
- describe "ruby command" do
115
- context "using bundler" do
116
- it "returns 'bundle exec'" do
117
- File.stub(:exists?).with("./Gemfile") { true }
118
- rspec_autotest.make_test_cmd({'a' => 'b'}).should =~ /bundle exec .*ruby/
119
- end
120
- end
121
-
122
- context "not using bundler" do
123
- it "returns the ruby command generated by Autotest" do
124
- File.stub(:exists?).with("./Gemfile") { false }
125
- rspec_autotest.make_test_cmd({'a' => 'b'}).should_not =~ /bundle exec/
126
- end
127
- end
128
- end
129
245
  end
@@ -162,6 +162,7 @@ describe RSpec::Core::ConfigurationOptions do
162
162
  it "does not send --drb back to the parser after parsing options" do
163
163
  config_options_object("--drb", "--color").drb_argv.should_not include("--drb")
164
164
  end
165
+
165
166
  end
166
167
 
167
168
  describe "files_or_directories_to_run" do
@@ -204,6 +205,38 @@ describe RSpec::Core::ConfigurationOptions do
204
205
  config_options_object(*%w[--options custom.opts]).drb_argv.should include("--options", "custom.opts")
205
206
  end
206
207
 
208
+ context "with tags" do
209
+ it "includes the tags" do
210
+ coo = config_options_object("--tag", "tag")
211
+ coo.drb_argv.should eq(["--tag", "tag"])
212
+ end
213
+
214
+ it "leaves tags intact" do
215
+ coo = config_options_object("--tag", "tag")
216
+ coo.drb_argv
217
+ coo.options[:filter].should eq( {:tag=>true} )
218
+ end
219
+ end
220
+
221
+ context "with formatters" do
222
+ it "includes the formatters" do
223
+ coo = config_options_object("--format", "d")
224
+ coo.drb_argv.should eq(["--format", "d"])
225
+ end
226
+
227
+ it "leaves formatters intact" do
228
+ coo = config_options_object("--format", "d")
229
+ coo.drb_argv
230
+ coo.options[:formatters].should eq([["d"]])
231
+ end
232
+
233
+ it "leaves output intact" do
234
+ coo = config_options_object("--format", "p", "--out", "foo.txt", "--format", "d")
235
+ coo.drb_argv
236
+ coo.options[:formatters].should eq([["p","foo.txt"],["d"]])
237
+ end
238
+ end
239
+
207
240
  context "--drb specified in ARGV" do
208
241
  it "renders all the original arguments except --drb" do
209
242
  config_options_object(*%w[ --drb --color --format s --line_number 1 --example pattern --profile --backtrace -I path/a -I path/b --require path/c --require path/d]).
@@ -239,7 +272,7 @@ describe RSpec::Core::ConfigurationOptions do
239
272
  end
240
273
  end
241
274
 
242
- describe "sources: ~/.rspec, ./.rspec, custom, SPEC_OPTS, and CLI" do
275
+ describe "sources: ~/.rspec, ./.rspec, custom, CLI, and SPEC_OPTS" do
243
276
  let(:local_options_file) { File.join(Dir.tmpdir, ".rspec-local") }
244
277
  let(:global_options_file) { File.join(Dir.tmpdir, ".rspec-global") }
245
278
  let(:custom_options_file) { File.join(Dir.tmpdir, "custom.options") }
@@ -280,16 +313,15 @@ describe RSpec::Core::ConfigurationOptions do
280
313
  options[:drb].should be_true
281
314
  end
282
315
 
283
- it "prefers CLI over SPEC_OPTS" do
316
+ it "prefers SPEC_OPTS over CLI" do
284
317
  ENV["SPEC_OPTS"] = "--format spec_opts"
285
- parse_options("--format", "cli")[:formatters].should eq([['cli']])
318
+ parse_options("--format", "cli")[:formatters].should eq([['spec_opts']])
286
319
  end
287
320
 
288
- it "prefers SPEC_OPTS over file options" do
321
+ it "prefers CLI over file options" do
289
322
  write_options(:local, "--format local")
290
323
  write_options(:global, "--format global")
291
- ENV["SPEC_OPTS"] = "--format spec_opts"
292
- parse_options[:formatters].should eq([['spec_opts']])
324
+ parse_options("--format", "cli")[:formatters].should eq([['cli']])
293
325
  end
294
326
 
295
327
  it "prefers local file options over global" do
@@ -228,6 +228,21 @@ module RSpec::Core
228
228
 
229
229
  end
230
230
 
231
+ [:focus, :focused].each do |example_alias|
232
+ describe "##{example_alias}" do
233
+ let(:group) { ExampleGroup.describe }
234
+ subject { group.send example_alias, "a focused example" }
235
+
236
+ it 'defines an example that can be filtered with :focused => true' do
237
+ subject.metadata.should include(:focused => true)
238
+ end
239
+
240
+ it 'defines an example that can be filtered with :focus => true' do
241
+ subject.metadata.should include(:focus => true)
242
+ end
243
+ end
244
+ end
245
+
231
246
  describe "#before, after, and around hooks" do
232
247
 
233
248
  it "runs the before alls in order" do
@@ -620,70 +635,6 @@ module RSpec::Core
620
635
  end
621
636
  end
622
637
 
623
- describe "#its" do
624
- context "with nil value" do
625
- subject do
626
- Class.new do
627
- def nil_value
628
- nil
629
- end
630
- end.new
631
- end
632
- its(:nil_value) { should be_nil }
633
- end
634
-
635
- context "with nested attributes" do
636
- subject do
637
- Class.new do
638
- def name
639
- "John"
640
- end
641
- end.new
642
- end
643
- its("name.size") { should == 4 }
644
- its("name.size.class") { should == Fixnum }
645
- end
646
-
647
- context "when it is a Hash" do
648
- subject do
649
- { :attribute => 'value',
650
- 'another_attribute' => 'another_value' }
651
- end
652
- its([:attribute]) { should == 'value' }
653
- its([:attribute]) { should_not == 'another_value' }
654
- its([:another_attribute]) { should == 'another_value' }
655
- its([:another_attribute]) { should_not == 'value' }
656
- its(:keys) { should =~ ['another_attribute', :attribute] }
657
- context "when referring to an attribute without the proper array syntax" do
658
- context "it raises an error" do
659
- its(:attribute) do
660
- expect do
661
- should eq('value')
662
- end.to raise_error(NoMethodError)
663
- end
664
- end
665
- end
666
- end
667
-
668
- context "calling and overriding super" do
669
- it "calls to the subject defined in the parent group" do
670
- group = ExampleGroup.describe(Array) do
671
- subject { [1, 'a'] }
672
-
673
- its(:last) { should == 'a' }
674
-
675
- describe '.first' do
676
- def subject; super().first; end
677
-
678
- its(:next) { should == 2 }
679
- end
680
- end
681
-
682
- group.run.should be_true
683
- end
684
- end
685
-
686
- end
687
638
 
688
639
  describe "#top_level_description" do
689
640
  it "returns the description from the outermost example group" do
@@ -31,6 +31,29 @@ describe RSpec::Core::Formatters::BaseFormatter do
31
31
  formatter.send(:read_failed_line, exception, example)
32
32
  }.should_not raise_error
33
33
  end
34
+
35
+ context "when String alias to_int to_i" do
36
+ before do
37
+ class String
38
+ alias :to_int :to_i
39
+ end
40
+ end
41
+
42
+ after do
43
+ class String
44
+ undef to_int
45
+ end
46
+ end
47
+
48
+ it "doesn't hang when file exists" do
49
+ exception = mock(:Exception, :backtrace => [ "#{__FILE__}:#{__LINE__}"])
50
+
51
+ example = mock(:Example, :file_path => __FILE__)
52
+ formatter.send(:read_failed_line, exception, example).should
53
+ eql %Q{ exception = mock(:Exception, :backtrace => [ "\#{__FILE__}:\#{__LINE__}"])\n}
54
+ end
55
+
56
+ end
34
57
  end
35
58
 
36
59
  end