rspec-core 2.8.0.rc2 → 2.8.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.
@@ -1,6 +1,10 @@
1
1
  require 'autotest'
2
2
  require 'rspec/core/deprecation'
3
3
 
4
+ # Derived from the `Autotest` class, extends the `autotest` command to work
5
+ # with RSpec.
6
+ #
7
+ # @note this will be extracted to a separate gem when we release rspec-3.
4
8
  class Autotest::Rspec2 < Autotest
5
9
 
6
10
  RSPEC_EXECUTABLE = File.expand_path('../../../exe/rspec', __FILE__)
@@ -205,7 +205,7 @@ MESSAGE
205
205
  @preferred_options.merge!(hash)
206
206
  end
207
207
 
208
- # @api private
208
+ # @private
209
209
  def reset
210
210
  @reporter = nil
211
211
  @formatters.clear
@@ -257,6 +257,9 @@ MESSAGE
257
257
  # Used by formatters to ask whether a backtrace line should be displayed
258
258
  # or not, based on the line matching any `backtrace_clean_patterns`.
259
259
  def cleaned_from_backtrace?(line)
260
+ # TODO (David 2011-12-25) why are we asking the configuration to do
261
+ # stuff? Either use the patterns directly or enapsulate the filtering
262
+ # in a BacktraceCleaner object.
260
263
  backtrace_clean_patterns.any? { |regex| line =~ regex }
261
264
  end
262
265
 
@@ -462,6 +465,7 @@ EOM
462
465
  end
463
466
  end
464
467
 
468
+ # @private
465
469
  def files_or_directories_to_run=(*files)
466
470
  files = files.flatten
467
471
  files << default_path if command == 'rspec' && default_path && files.empty?
@@ -597,17 +601,76 @@ EOM
597
601
  filter_manager.exclusions
598
602
  end
599
603
 
600
- def include(mod, *args)
601
- filters = build_metadata_hash_from(args)
602
- include_or_extend_modules << [:include, mod, filters]
604
+ # Tells RSpec to include `mod` in example groups. Methods defined in
605
+ # `mod` are exposed to examples (not example groups). Use `filters` to
606
+ # constrain the groups in which to include the module.
607
+ #
608
+ # @example
609
+ #
610
+ # module AuthenticationHelpers
611
+ # def login_as(user)
612
+ # # ...
613
+ # end
614
+ # end
615
+ #
616
+ # module UserHelpers
617
+ # def users(username)
618
+ # # ...
619
+ # end
620
+ # end
621
+ #
622
+ # RSpec.configure do |config|
623
+ # config.include(UserHelpers) # included in all modules
624
+ # config.include(AuthenticationHelpers, :type => :request)
625
+ # end
626
+ #
627
+ # describe "edit profile", :type => :request do
628
+ # it "can be viewed by owning user" do
629
+ # login_as users(:jdoe)
630
+ # get "/profiles/jdoe"
631
+ # assert_select ".username", :text => 'jdoe'
632
+ # end
633
+ # end
634
+ #
635
+ # @see #extend
636
+ def include(mod, *filters)
637
+ include_or_extend_modules << [:include, mod, build_metadata_hash_from(filters)]
603
638
  end
604
639
 
605
- def extend(mod, *args)
606
- filters = build_metadata_hash_from(args)
607
- include_or_extend_modules << [:extend, mod, filters]
640
+ # Tells RSpec to extend example groups with `mod`. Methods defined in
641
+ # `mod` are exposed to example groups (not examples). Use `filters` to
642
+ # constrain the groups to extend.
643
+ #
644
+ # Similar to `include`, but behavior is added to example groups, which
645
+ # are classes, rather than the examples, which are instances of those
646
+ # classes.
647
+ #
648
+ # @example
649
+ #
650
+ # module UiHelpers
651
+ # def run_in_browser
652
+ # # ...
653
+ # end
654
+ # end
655
+ #
656
+ # RSpec.configure do |config|
657
+ # config.extend(UiHelpers, :type => :request)
658
+ # end
659
+ #
660
+ # describe "edit profile", :type => :request do
661
+ # run_in_browser
662
+ #
663
+ # it "does stuff in the client" do
664
+ # # ...
665
+ # end
666
+ # end
667
+ #
668
+ # @see #include
669
+ def extend(mod, *filters)
670
+ include_or_extend_modules << [:extend, mod, build_metadata_hash_from(filters)]
608
671
  end
609
672
 
610
- # @api private
673
+ # @private
611
674
  #
612
675
  # Used internally to extend a group with modules using `include` and/or
613
676
  # `extend`.
@@ -618,21 +681,21 @@ EOM
618
681
  end
619
682
  end
620
683
 
621
- # @api private
684
+ # @private
622
685
  def configure_mock_framework
623
686
  RSpec::Core::ExampleGroup.send(:include, mock_framework)
624
687
  end
625
688
 
626
- # @api private
689
+ # @private
627
690
  def configure_expectation_framework
628
691
  expectation_frameworks.each do |framework|
629
692
  RSpec::Core::ExampleGroup.send(:include, framework)
630
693
  end
631
694
  end
632
695
 
633
- # @api private
696
+ # @private
634
697
  def load_spec_files
635
- files_to_run.map {|f| load File.expand_path(f) }
698
+ files_to_run.uniq.map {|f| load File.expand_path(f) }
636
699
  raise_if_rspec_1_is_loaded
637
700
  end
638
701
 
@@ -1,5 +1,6 @@
1
1
  module RSpec
2
2
  module Core
3
+ # Adds the `describe` method to the top-level namespace.
3
4
  module DSL
4
5
  # Generates a subclass of [ExampleGroup](ExampleGroup)
5
6
  #
@@ -16,20 +16,18 @@ module RSpec
16
16
  output.puts "Failures:"
17
17
  failed_examples.each_with_index do |example, index|
18
18
  output.puts
19
- dump_pending_example_fixed(example, index) || dump_failure(example, index)
19
+ pending_fixed?(example) ? dump_pending_fixed(example, index) : dump_failure(example, index)
20
20
  dump_backtrace(example)
21
21
  end
22
22
  end
23
23
 
24
24
  def colorise_summary(summary)
25
- if failure_count == 0
26
- if pending_count > 0
27
- yellow(summary)
28
- else
29
- green(summary)
30
- end
31
- else
25
+ if failure_count > 0
32
26
  red(summary)
27
+ elsif pending_count > 0
28
+ yellow(summary)
29
+ else
30
+ green(summary)
33
31
  end
34
32
  end
35
33
 
@@ -158,12 +156,13 @@ module RSpec
158
156
  end
159
157
  end
160
158
 
161
- def dump_pending_example_fixed(example, index)
162
- if example.execution_result[:exception].pending_fixed?
163
- output.puts "#{short_padding}#{index.next}) #{example.full_description} FIXED"
164
- output.puts blue("#{long_padding}Expected pending '#{example.metadata[:execution_result][:pending_message]}' to fail. No Error was raised.")
165
- true
166
- end
159
+ def dump_pending_fixed(example, index)
160
+ output.puts "#{short_padding}#{index.next}) #{example.full_description} FIXED"
161
+ output.puts blue("#{long_padding}Expected pending '#{example.metadata[:execution_result][:pending_message]}' to fail. No Error was raised.")
162
+ end
163
+
164
+ def pending_fixed?(example)
165
+ example.execution_result[:exception].pending_fixed?
167
166
  end
168
167
 
169
168
  def dump_failure(example, index)
@@ -176,15 +175,23 @@ module RSpec
176
175
  output.puts "#{long_padding}#{red("Failure/Error:")} #{red(read_failed_line(exception, example).strip)}"
177
176
  output.puts "#{long_padding}#{red(exception.class.name << ":")}" unless exception.class.name =~ /RSpec/
178
177
  exception.message.split("\n").each { |line| output.puts "#{long_padding} #{red(line)}" } if exception.message
179
-
180
- example.example_group.ancestors.push(example.example_group).each do |group|
181
- if group.metadata[:shared_group_name]
182
- output.puts "#{long_padding}Shared Example Group: \"#{group.metadata[:shared_group_name]}\" called from " +
183
- "#{backtrace_line(group.metadata[:example_group][:location])}"
184
- break
185
- end
178
+ if shared_group = find_shared_group(example)
179
+ dump_shared_failure_info(shared_group)
186
180
  end
187
181
  end
182
+
183
+ def dump_shared_failure_info(group)
184
+ output.puts "#{long_padding}Shared Example Group: \"#{group.metadata[:shared_group_name]}\" called from " +
185
+ "#{backtrace_line(group.metadata[:example_group][:location])}"
186
+ end
187
+
188
+ def find_shared_group(example)
189
+ group_and_ancestors(example).find {|group| group.metadata[:shared_group_name]}
190
+ end
191
+
192
+ def group_and_ancestors(example)
193
+ example.example_group.ancestors.push(example.example_group)
194
+ end
188
195
  end
189
196
  end
190
197
  end
@@ -169,7 +169,7 @@ module RSpec
169
169
 
170
170
  # @private
171
171
  def filter_applies?(key, value, metadata=self)
172
- return metadata.filter_applies_to_any_value?(key, value) if Array === metadata[key]
172
+ return metadata.filter_applies_to_any_value?(key, value) if Array === metadata[key] && !(Proc === value)
173
173
  return metadata.line_number_filter_applies?(value) if key == :line_numbers
174
174
  return metadata.location_filter_applies?(value) if key == :locations
175
175
  return metadata.filters_apply?(key, value) if Hash === value
@@ -25,7 +25,12 @@ module RSpec
25
25
  report_exists('.rspec')
26
26
  else
27
27
  report_creating('.rspec')
28
- FileUtils.touch('.rspec')
28
+ File.open('.rspec','w') do |f|
29
+ f.write <<-CONTENT
30
+ --color
31
+ --format progress
32
+ CONTENT
33
+ end
29
34
  end
30
35
  end
31
36
 
@@ -34,8 +39,22 @@ module RSpec
34
39
  report_exists("spec/spec_helper.rb")
35
40
  else
36
41
  report_creating("spec/spec_helper.rb")
37
- FileUtils.mkdir('spec') unless File.exist?('spec') && File.directory?('spec')
38
- FileUtils.touch('spec/spec_helper.rb')
42
+ FileUtils.mkdir_p('spec')
43
+ File.open('spec/spec_helper.rb','w') do |f|
44
+ f.write <<-CONTENT
45
+ # This file was generated by the `rspec --init` command. Conventionally, all
46
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
47
+ # Require this file using `require "spec_helper.rb"` to ensure that it is only
48
+ # loaded once.
49
+ #
50
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
51
+ RSpec.configure do |config|
52
+ config.treat_symbols_as_metadata_keys_with_true_values = true
53
+ config.run_all_when_everything_filtered = true
54
+ config.filter_run :focus
55
+ end
56
+ CONTENT
57
+ end
39
58
  end
40
59
  end
41
60
 
@@ -3,12 +3,10 @@ module RSpec
3
3
  # Exposes [ExampleGroup](ExampleGroup)-level methods to a module, so you
4
4
  # can include that module in an [ExampleGroup](ExampleGroup).
5
5
  #
6
- # @note exposed as `RSpec::SharedContext`
7
- #
8
6
  # @example
9
7
  #
10
8
  # module LoggedInAsAdmin
11
- # extend RSpec::SharedContext
9
+ # extend RSpec::Core::SharedContext
12
10
  # before(:each) do
13
11
  # log_in_as :admin
14
12
  # end
@@ -1,7 +1,7 @@
1
1
  module RSpec
2
2
  module Core
3
3
  module Version
4
- STRING = '2.8.0.rc2'
4
+ STRING = '2.8.0'
5
5
  end
6
6
  end
7
7
  end
@@ -18,6 +18,12 @@ module RSpec::Core
18
18
  config.load_spec_files
19
19
  end
20
20
 
21
+ it "loads each file once, even if duplicated in list" do
22
+ config.files_to_run = ["a_spec.rb", "a_spec.rb"]
23
+ config.should_receive(:load).once
24
+ config.load_spec_files
25
+ end
26
+
21
27
  context "with rspec-1 loaded" do
22
28
  before do
23
29
  Object.const_set(:Spec, Module.new)
@@ -692,6 +698,12 @@ module RSpec::Core
692
698
  config.inclusion_filter = :foo
693
699
  config.inclusion_filter.should eq({:foo => true})
694
700
  end
701
+
702
+ it "overrides any inclusion filters set on the command line or in configuration files" do
703
+ config.force(:inclusion_filter => { :foo => :bar })
704
+ config.inclusion_filter = {:want => :this}
705
+ config.inclusion_filter.should eq({:want => :this})
706
+ end
695
707
  end
696
708
 
697
709
  describe "#exclusion_filter" do
@@ -739,6 +751,12 @@ module RSpec::Core
739
751
  config.exclusion_filter = :foo
740
752
  config.exclusion_filter.should eq({:foo => true})
741
753
  end
754
+
755
+ it "overrides any exclusion filters set on the command line or in configuration files" do
756
+ config.force(:exclusion_filter => { :foo => :bar })
757
+ config.exclusion_filter = {:want => :this}
758
+ config.exclusion_filter.should eq({:want => :this})
759
+ end
742
760
  end
743
761
 
744
762
  describe "line_numbers=" do
@@ -160,6 +160,14 @@ module RSpec
160
160
  metadata_with_array.filter_applies?(:tag, 'fourtune').should be_true
161
161
  metadata_with_array.filter_applies?(:tag, 'fortune').should be_false
162
162
  end
163
+
164
+ it "matches a proc that evaluates to true" do
165
+ metadata_with_array.filter_applies?(:tag, lambda { |values| values.include? 'three' }).should be_true
166
+ end
167
+
168
+ it "does not match a proc that evaluates to false" do
169
+ metadata_with_array.filter_applies?(:tag, lambda { |values| values.include? 'nothing' }).should be_false
170
+ end
163
171
  end
164
172
  end
165
173
 
@@ -20,7 +20,7 @@ module RSpec::Core
20
20
 
21
21
  it "generates a .rspec" do
22
22
  command_line_config.run
23
- File.read('.rspec').should eq('')
23
+ File.read('.rspec').should =~ /--color\n--format progress/m
24
24
  end
25
25
  end
26
26
 
@@ -46,7 +46,7 @@ module RSpec::Core
46
46
 
47
47
  it "generates a spec/spec_helper.rb" do
48
48
  command_line_config.run
49
- File.read('spec/spec_helper.rb').should eq('')
49
+ File.read('spec/spec_helper.rb').should =~ /RSpec\.configure do \|config\|/m
50
50
  end
51
51
  end
52
52
 
@@ -3,29 +3,23 @@ require 'spec_helper'
3
3
  describe RSpec::Core do
4
4
 
5
5
  describe "#configuration" do
6
-
7
6
  it "returns the same object every time" do
8
7
  RSpec.configuration.should equal(RSpec.configuration)
9
8
  end
10
-
11
9
  end
12
10
 
13
11
  describe "#configure" do
14
-
15
12
  it "yields the current configuration" do
16
13
  RSpec.configure do |config|
17
14
  config.should eq(RSpec::configuration)
18
15
  end
19
16
  end
20
-
21
17
  end
22
18
 
23
19
  describe "#world" do
24
-
25
20
  it "returns the RSpec::Core::World instance the current run is using" do
26
21
  RSpec.world.should be_instance_of(RSpec::Core::World)
27
22
  end
28
-
29
23
  end
30
24
 
31
25
  end
metadata CHANGED
@@ -1,15 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rspec-core
3
3
  version: !ruby/object:Gem::Version
4
- hash: 15424209
5
- prerelease: 6
4
+ hash: 47
5
+ prerelease:
6
6
  segments:
7
7
  - 2
8
8
  - 8
9
9
  - 0
10
- - rc
11
- - 2
12
- version: 2.8.0.rc2
10
+ version: 2.8.0
13
11
  platform: ruby
14
12
  authors:
15
13
  - Steven Baker
@@ -19,7 +17,7 @@ autorequire:
19
17
  bindir: exe
20
18
  cert_chain: []
21
19
 
22
- date: 2011-12-20 00:00:00 Z
20
+ date: 2012-01-05 00:00:00 Z
23
21
  dependencies: []
24
22
 
25
23
  description: BDD for Ruby. RSpec runner and example groups.
@@ -220,21 +218,19 @@ required_ruby_version: !ruby/object:Gem::Requirement
220
218
  required_rubygems_version: !ruby/object:Gem::Requirement
221
219
  none: false
222
220
  requirements:
223
- - - ">"
221
+ - - ">="
224
222
  - !ruby/object:Gem::Version
225
- hash: 25
223
+ hash: 3
226
224
  segments:
227
- - 1
228
- - 3
229
- - 1
230
- version: 1.3.1
225
+ - 0
226
+ version: "0"
231
227
  requirements: []
232
228
 
233
229
  rubyforge_project: rspec
234
230
  rubygems_version: 1.8.11
235
231
  signing_key:
236
232
  specification_version: 3
237
- summary: rspec-core-2.8.0.rc2
233
+ summary: rspec-core-2.8.0
238
234
  test_files:
239
235
  - features/Autotest.md
240
236
  - features/README.md