rspec-core 2.0.0.a1 → 2.0.0.a2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (50) hide show
  1. data/README.markdown +34 -3
  2. data/Rakefile +32 -17
  3. data/bin/rspec +5 -7
  4. data/cucumber.yml +3 -2
  5. data/features-pending/example_groups/example_group_with_should_methods.feature +3 -1
  6. data/features/before_and_after_blocks/around.feature +34 -0
  7. data/features/example_groups/describe_aliases.feature +20 -0
  8. data/{features-pending → features}/example_groups/nested_groups.feature +6 -8
  9. data/features/expectations/customized_message.feature +6 -6
  10. data/{features-pending → features}/matchers/define_matcher.feature +9 -9
  11. data/features/mock_framework_integration/use_rspec.feature +1 -1
  12. data/features/mocks/block_local_expectations.feature +68 -0
  13. data/{features-pending → features}/mocks/mix_stubs_and_mocks.feature +5 -1
  14. data/features/support/env.rb +6 -18
  15. data/lib/rspec/core.rb +5 -5
  16. data/lib/rspec/core/advice.rb +49 -0
  17. data/lib/rspec/core/command_line_options.rb +4 -11
  18. data/lib/rspec/core/configuration.rb +20 -32
  19. data/lib/rspec/core/example.rb +48 -15
  20. data/lib/rspec/core/example_group.rb +68 -93
  21. data/lib/rspec/core/extensions/instance_exec.rb +31 -0
  22. data/lib/rspec/core/kernel_extensions.rb +3 -1
  23. data/lib/rspec/core/load_path.rb +4 -0
  24. data/lib/rspec/core/metadata.rb +78 -0
  25. data/lib/rspec/core/rake_task.rb +3 -4
  26. data/lib/rspec/core/ruby_project.rb +30 -0
  27. data/lib/rspec/core/runner.rb +6 -7
  28. data/lib/rspec/core/version.rb +2 -2
  29. data/lib/rspec/core/world.rb +6 -4
  30. data/rspec-core.gemspec +33 -14
  31. data/spec/rspec/core/command_line_options_spec.rb +10 -10
  32. data/spec/rspec/core/configuration_spec.rb +26 -21
  33. data/spec/rspec/core/example_group_spec.rb +243 -173
  34. data/spec/rspec/core/example_group_subject_spec.rb +1 -1
  35. data/spec/rspec/core/example_spec.rb +12 -22
  36. data/spec/rspec/core/formatters/base_formatter_spec.rb +1 -1
  37. data/spec/rspec/core/formatters/documentation_formatter_spec.rb +1 -1
  38. data/spec/rspec/core/formatters/progress_formatter_spec.rb +4 -3
  39. data/spec/rspec/core/kernel_extensions_spec.rb +1 -1
  40. data/spec/rspec/core/metadata_spec.rb +101 -0
  41. data/spec/rspec/core/mocha_spec.rb +2 -2
  42. data/spec/rspec/core/runner_spec.rb +5 -5
  43. data/spec/rspec/core/shared_behaviour_spec.rb +5 -5
  44. data/spec/rspec/core/world_spec.rb +8 -8
  45. data/spec/rspec/core_spec.rb +1 -1
  46. data/spec/spec_helper.rb +15 -8
  47. data/specs.watchr +57 -0
  48. metadata +53 -15
  49. data/VERSION +0 -1
  50. data/VERSION.yml +0 -5
@@ -0,0 +1,31 @@
1
+ module Rspec
2
+ module Core
3
+ module InstanceExec
4
+ unless respond_to?(:instance_exec)
5
+ # based on Bounded Spec InstanceExec (Mauricio Fernandez)
6
+ # http://eigenclass.org/hiki/bounded+space+instance_exec
7
+ # - uses singleton_class of matcher instead of global
8
+ # InstanceExecHelper module
9
+ # - this keeps it scoped to this class only, which is the
10
+ # only place we need it
11
+ # - only necessary for ruby 1.8.6
12
+ def instance_exec(*args, &block)
13
+ singleton_class = (class << self; self; end)
14
+ begin
15
+ orig_critical, Thread.critical = Thread.critical, true
16
+ n = 0
17
+ n += 1 while respond_to?(method_name="__instance_exec#{n}")
18
+ singleton_class.module_eval{ define_method(:__instance_exec, &block) }
19
+ ensure
20
+ Thread.critical = orig_critical
21
+ end
22
+ begin
23
+ return send(:__instance_exec, *args)
24
+ ensure
25
+ singleton_class.module_eval{ remove_method(:__instance_exec) } rescue nil
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
@@ -3,9 +3,11 @@ module Rspec
3
3
  module KernelExtensions
4
4
 
5
5
  def describe(*args, &behaviour_block)
6
+ args << {} unless args.last.is_a?(Hash)
7
+ args.last.update :caller => caller(1)
6
8
  Rspec::Core::ExampleGroup.describe(*args, &behaviour_block)
7
9
  end
8
-
10
+
9
11
  alias :context :describe
10
12
 
11
13
  end
@@ -0,0 +1,4 @@
1
+ require 'rspec/core/ruby_project'
2
+
3
+ Rspec::Core::RubyProject.add_to_load_path('lib')
4
+ Rspec::Core::RubyProject.add_to_load_path('spec')
@@ -0,0 +1,78 @@
1
+ module Rspec
2
+ module Core
3
+ class Metadata < Hash
4
+
5
+ def self.process(superclass_metadata, *args)
6
+ new(superclass_metadata) do |metadata|
7
+ metadata.process(*args)
8
+ end
9
+ end
10
+
11
+ attr_reader :superclass_metadata
12
+
13
+ def initialize(superclass_metadata=nil)
14
+ @superclass_metadata = superclass_metadata
15
+ update(@superclass_metadata) if @superclass_metadata
16
+ store(:behaviour, {})
17
+ yield self if block_given?
18
+ end
19
+
20
+ def process(*args)
21
+ extra_metadata = args.last.is_a?(Hash) ? args.pop : {}
22
+ extra_metadata.delete(:behaviour) # Remove it when present to prevent it clobbering the one we setup
23
+
24
+ self[:behaviour][:describes] = args.shift unless args.first.is_a?(String)
25
+ self[:behaviour][:describes] ||= self.superclass_metadata && self.superclass_metadata[:behaviour][:describes]
26
+ self[:behaviour][:description] = args.shift || ''
27
+
28
+ self[:behaviour][:name] = determine_name
29
+ self[:behaviour][:block] = extra_metadata.delete(:behaviour_block)
30
+ self[:behaviour][:caller] = extra_metadata.delete(:caller)
31
+ self[:behaviour][:file_path] = determine_file_path(extra_metadata.delete(:file_path))
32
+ self[:behaviour][:line_number] = determine_line_number(extra_metadata.delete(:line_number))
33
+
34
+ update(extra_metadata)
35
+ end
36
+
37
+ def for_example(desc, options)
38
+ dup.configure_for_example(desc,options)
39
+ end
40
+
41
+ def configure_for_example(desc, options)
42
+ store(:description, desc.to_s)
43
+ store(:execution_result, {})
44
+ store(:caller, options.delete(:caller))
45
+ if self[:caller]
46
+ store(:file_path, determine_file_path)
47
+ store(:line_number, determine_line_number)
48
+ end
49
+ update(options)
50
+ end
51
+
52
+ private
53
+
54
+ def possible_files
55
+ self[:behaviour][:caller].grep(/\_spec\.rb:/i)
56
+ end
57
+
58
+ def determine_file_path(given_file_path=nil)
59
+ return given_file_path if given_file_path
60
+ possible_files.first.split(':').first.strip
61
+ end
62
+
63
+ def determine_line_number(given_line_number=nil)
64
+ return given_line_number if given_line_number
65
+ possible_files.first.split(':')[1].to_i
66
+ end
67
+
68
+ def determine_name
69
+ if superclass_metadata && superclass_metadata[:behaviour][:name]
70
+ self[:behaviour][:name] = "#{superclass_metadata[:behaviour][:name]} #{self[:behaviour][:description]}".strip
71
+ else
72
+ self[:behaviour][:name] = "#{self[:behaviour][:describes]} #{self[:behaviour][:description]}".strip
73
+ end
74
+ end
75
+
76
+ end
77
+ end
78
+ end
@@ -18,7 +18,7 @@ module Rspec
18
18
  # Glob pattern to match files. (default is 'spec/**/*_spec.rb')
19
19
  attr_accessor :pattern
20
20
 
21
- # Array of commandline options to pass to ruby. Defaults to [].
21
+ # The options to pass to ruby. Defaults to blank
22
22
  attr_accessor :ruby_opts
23
23
 
24
24
  # Whether or not to fail Rake when an error occurs (typically when examples fail).
@@ -38,9 +38,6 @@ module Rspec
38
38
  # The options to pass to rcov. Defaults to blank
39
39
  attr_accessor :rcov_opts
40
40
 
41
- # The options to pass to ruby. Defaults to blank
42
- attr_accessor :ruby_opts
43
-
44
41
  def initialize(*args)
45
42
  @name = args.shift || :spec
46
43
  @pattern, @rcov_opts, @ruby_opts = nil, nil, nil
@@ -63,6 +60,8 @@ module Rspec
63
60
  else
64
61
  cmd_parts = [rcov ? 'rcov' : RUBY]
65
62
  cmd_parts += rcov ? [rcov_opts] : [ruby_opts]
63
+ cmd_parts << '-Ilib'
64
+ cmd_parts << '-Ispec'
66
65
  cmd_parts << "-w" if warning
67
66
  cmd_parts += files_to_run.collect { |fn| %["#{fn}"] }
68
67
  cmd = cmd_parts.join(" ")
@@ -0,0 +1,30 @@
1
+ module Rspec
2
+ module Core
3
+ module RubyProject
4
+ def add_to_load_path(dir)
5
+ dir = File.join(root, dir)
6
+ $LOAD_PATH.unshift(dir) unless $LOAD_PATH.include?(dir)
7
+ end
8
+
9
+ def root # :nodoc:
10
+ require 'pathname'
11
+ @project_root ||= determine_root
12
+ end
13
+
14
+ def determine_root # :nodoc:
15
+ # This is borrowed (slightly modified) from Scott Taylor's
16
+ # project_path project:
17
+ # http://github.com/smtlaissezfaire/project_path
18
+ Pathname(File.expand_path('.')).ascend do |path|
19
+ if File.exists?(File.join(path, "spec"))
20
+ return path
21
+ end
22
+ end
23
+ end
24
+
25
+ module_function :add_to_load_path
26
+ module_function :root
27
+ module_function :determine_root
28
+ end
29
+ end
30
+ end
@@ -21,16 +21,14 @@ module Rspec
21
21
  configuration.formatter
22
22
  end
23
23
 
24
- def require_all_files(files)
25
- files.each { |file| require file }
24
+ def require_all_files(configuration)
25
+ configuration.files_to_run.map {|f| require f.sub(/^spec\//,'') }
26
26
  end
27
27
 
28
28
  def run(args = [])
29
- cli_config = Rspec::Core::CommandLineOptions.parse(args)
30
-
31
- require_all_files(cli_config.files_to_run)
32
-
33
- cli_config.apply(configuration)
29
+ Rspec::Core::CommandLineOptions.parse(args).apply(configuration)
30
+
31
+ require_all_files(configuration)
34
32
 
35
33
  total_examples_to_run = Rspec::Core.world.total_examples_to_run
36
34
 
@@ -59,6 +57,7 @@ module Rspec
59
57
 
60
58
  suite_success
61
59
  end
60
+
62
61
 
63
62
  end
64
63
 
@@ -5,11 +5,11 @@ module Rspec # :nodoc:
5
5
  MAJOR = 2
6
6
  MINOR = 0
7
7
  TINY = 0
8
- PRE = 'a1'
8
+ PRE = 'a2'
9
9
 
10
10
  STRING = [MAJOR, MINOR, TINY, PRE].compact.join('.')
11
11
 
12
- SUMMARY = "rspec-core #{STRING}"
12
+ SUMMARY = "rspec-core " + STRING
13
13
  end
14
14
  end
15
15
  end
@@ -1,7 +1,5 @@
1
1
  module Rspec
2
-
3
2
  module Core
4
-
5
3
  class World
6
4
 
7
5
  attr_reader :behaviours
@@ -98,8 +96,12 @@ module Rspec
98
96
  end
99
97
  end
100
98
 
101
- end
99
+ def all_apply?(group, filters)
100
+ filters.all? do |filter_on, filter|
101
+ Rspec::Core.world.apply_condition(filter_on, filter, group.metadata)
102
+ end
103
+ end
102
104
 
105
+ end
103
106
  end
104
-
105
107
  end
@@ -1,17 +1,16 @@
1
1
  # Generated by jeweler
2
- # DO NOT EDIT THIS FILE
3
- # Instead, edit Jeweler::Tasks in Rakefile, and run `rake gemspec`
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
4
  # -*- encoding: utf-8 -*-
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{rspec-core}
8
- s.version = "2.0.0.a1"
8
+ s.version = "2.0.0.a2"
9
9
 
10
- s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
10
+ s.required_rubygems_version = Gem::Requirement.new("> 1.3.1") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["David Chelimsky", "Chad Humphries"]
12
- s.date = %q{2009-09-16}
12
+ s.date = %q{2010-01-24}
13
13
  s.default_executable = %q{rspec}
14
- s.description = %q{RSpec Core}
15
14
  s.email = %q{dchelimsky@gmail.com;chad.humphries@gmail.com}
16
15
  s.executables = ["rspec"]
17
16
  s.extra_rdoc_files = [
@@ -25,8 +24,6 @@ Gem::Specification.new do |s|
25
24
  "README.markdown",
26
25
  "Rakefile",
27
26
  "TODO.markdown",
28
- "VERSION",
29
- "VERSION.yml",
30
27
  "bin/rspec",
31
28
  "cucumber.yml",
32
29
  "example_specs/failing/README.txt",
@@ -80,7 +77,6 @@ Gem::Specification.new do |s|
80
77
  "features-pending/command_line/line_number_option_with_example_with_no_name.feature",
81
78
  "features-pending/example_groups/example_group_with_should_methods.feature",
82
79
  "features-pending/example_groups/implicit_docstrings.feature",
83
- "features-pending/example_groups/nested_groups.feature",
84
80
  "features-pending/expectations/expect_change.feature",
85
81
  "features-pending/expectations/expect_error.feature",
86
82
  "features-pending/extensions/custom_example_group.feature",
@@ -91,19 +87,23 @@ Gem::Specification.new do |s|
91
87
  "features-pending/interop/test_but_not_test_unit.feature",
92
88
  "features-pending/interop/test_case_with_should_methods.feature",
93
89
  "features-pending/matchers/define_diffable_matcher.feature",
94
- "features-pending/matchers/define_matcher.feature",
95
90
  "features-pending/matchers/define_matcher_with_fluent_interface.feature",
96
- "features-pending/mocks/mix_stubs_and_mocks.feature",
97
91
  "features-pending/mocks/stub_implementation.feature",
98
92
  "features-pending/pending/pending_examples.feature",
99
93
  "features-pending/runner/specify_line_number.feature",
94
+ "features/before_and_after_blocks/around.feature",
100
95
  "features/before_and_after_blocks/before_and_after_blocks.feature",
96
+ "features/example_groups/describe_aliases.feature",
97
+ "features/example_groups/nested_groups.feature",
101
98
  "features/expectations/customized_message.feature",
99
+ "features/matchers/define_matcher.feature",
102
100
  "features/matchers/define_matcher_outside_rspec.feature",
103
101
  "features/mock_framework_integration/use_flexmock.feature",
104
102
  "features/mock_framework_integration/use_mocha.feature",
105
103
  "features/mock_framework_integration/use_rr.feature",
106
104
  "features/mock_framework_integration/use_rspec.feature",
105
+ "features/mocks/block_local_expectations.feature",
106
+ "features/mocks/mix_stubs_and_mocks.feature",
107
107
  "features/step_definitions/running_rspec_steps.rb",
108
108
  "features/subject/explicit_subject.feature",
109
109
  "features/subject/implicit_subject.feature",
@@ -111,6 +111,7 @@ Gem::Specification.new do |s|
111
111
  "features/support/matchers/smart_match.rb",
112
112
  "lib/rspec/autorun.rb",
113
113
  "lib/rspec/core.rb",
114
+ "lib/rspec/core/advice.rb",
114
115
  "lib/rspec/core/backward_compatibility.rb",
115
116
  "lib/rspec/core/command_line_options.rb",
116
117
  "lib/rspec/core/configuration.rb",
@@ -118,23 +119,27 @@ Gem::Specification.new do |s|
118
119
  "lib/rspec/core/example.rb",
119
120
  "lib/rspec/core/example_group.rb",
120
121
  "lib/rspec/core/example_group_subject.rb",
122
+ "lib/rspec/core/extensions/instance_exec.rb",
121
123
  "lib/rspec/core/formatters.rb",
122
124
  "lib/rspec/core/formatters/base_formatter.rb",
123
125
  "lib/rspec/core/formatters/base_text_formatter.rb",
124
126
  "lib/rspec/core/formatters/documentation_formatter.rb",
125
127
  "lib/rspec/core/formatters/progress_formatter.rb",
126
128
  "lib/rspec/core/kernel_extensions.rb",
129
+ "lib/rspec/core/load_path.rb",
130
+ "lib/rspec/core/metadata.rb",
127
131
  "lib/rspec/core/mocking/with_absolutely_nothing.rb",
128
132
  "lib/rspec/core/mocking/with_flexmock.rb",
129
133
  "lib/rspec/core/mocking/with_mocha.rb",
130
134
  "lib/rspec/core/mocking/with_rr.rb",
131
135
  "lib/rspec/core/mocking/with_rspec.rb",
132
136
  "lib/rspec/core/rake_task.rb",
137
+ "lib/rspec/core/ruby_project.rb",
133
138
  "lib/rspec/core/runner.rb",
134
139
  "lib/rspec/core/shared_behaviour.rb",
135
140
  "lib/rspec/core/shared_behaviour_kernel_extensions.rb",
136
- "lib/rspec/core/world.rb",
137
141
  "lib/rspec/core/version.rb",
142
+ "lib/rspec/core/world.rb",
138
143
  "rspec-core.gemspec",
139
144
  "script/console",
140
145
  "spec/resources/example_classes.rb",
@@ -147,6 +152,7 @@ Gem::Specification.new do |s|
147
152
  "spec/rspec/core/formatters/documentation_formatter_spec.rb",
148
153
  "spec/rspec/core/formatters/progress_formatter_spec.rb",
149
154
  "spec/rspec/core/kernel_extensions_spec.rb",
155
+ "spec/rspec/core/metadata_spec.rb",
150
156
  "spec/rspec/core/mocha_spec.rb",
151
157
  "spec/rspec/core/resources/a_bar.rb",
152
158
  "spec/rspec/core/resources/a_foo.rb",
@@ -159,13 +165,15 @@ Gem::Specification.new do |s|
159
165
  "spec/rspec/core/world_spec.rb",
160
166
  "spec/rspec/core_spec.rb",
161
167
  "spec/ruby_forker.rb",
162
- "spec/spec_helper.rb"
168
+ "spec/spec_helper.rb",
169
+ "specs.watchr"
163
170
  ]
164
171
  s.homepage = %q{http://github.com/rspec/core}
165
172
  s.rdoc_options = ["--charset=UTF-8"]
166
173
  s.require_paths = ["lib"]
174
+ s.rubyforge_project = %q{rspec}
167
175
  s.rubygems_version = %q{1.3.5}
168
- s.summary = %q{RSpec Core}
176
+ s.summary = %q{Rspec runner and example group classes}
169
177
  s.test_files = [
170
178
  "spec/resources/example_classes.rb",
171
179
  "spec/rspec/core/command_line_options_spec.rb",
@@ -177,6 +185,7 @@ Gem::Specification.new do |s|
177
185
  "spec/rspec/core/formatters/documentation_formatter_spec.rb",
178
186
  "spec/rspec/core/formatters/progress_formatter_spec.rb",
179
187
  "spec/rspec/core/kernel_extensions_spec.rb",
188
+ "spec/rspec/core/metadata_spec.rb",
180
189
  "spec/rspec/core/mocha_spec.rb",
181
190
  "spec/rspec/core/resources/a_bar.rb",
182
191
  "spec/rspec/core/resources/a_foo.rb",
@@ -197,8 +206,18 @@ Gem::Specification.new do |s|
197
206
  s.specification_version = 3
198
207
 
199
208
  if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
209
+ s.add_development_dependency(%q<rspec-expectations>, [">= 2.0.0.a2"])
210
+ s.add_development_dependency(%q<rspec-mocks>, [">= 2.0.0.a2"])
211
+ s.add_development_dependency(%q<cucumber>, [">= 0.5.3"])
200
212
  else
213
+ s.add_dependency(%q<rspec-expectations>, [">= 2.0.0.a2"])
214
+ s.add_dependency(%q<rspec-mocks>, [">= 2.0.0.a2"])
215
+ s.add_dependency(%q<cucumber>, [">= 0.5.3"])
201
216
  end
202
217
  else
218
+ s.add_dependency(%q<rspec-expectations>, [">= 2.0.0.a2"])
219
+ s.add_dependency(%q<rspec-mocks>, [">= 2.0.0.a2"])
220
+ s.add_dependency(%q<cucumber>, [">= 0.5.3"])
203
221
  end
204
222
  end
223
+
@@ -1,9 +1,9 @@
1
- require 'spec/spec_helper'
1
+ require 'spec_helper'
2
2
 
3
3
  describe Rspec::Core::CommandLineOptions do
4
4
 
5
5
  def options_from_args(*args)
6
- Rspec::Core::CommandLineOptions.new(args).parse
6
+ Rspec::Core::CommandLineOptions.new(args).parse.options
7
7
  end
8
8
 
9
9
  describe 'color_enabled' do
@@ -43,18 +43,18 @@ describe Rspec::Core::CommandLineOptions do
43
43
 
44
44
  end
45
45
 
46
- describe 'files_to_run' do
47
-
48
- example '-c file.rb dir/file.rb should parse' do
49
- options_from_args('-c', 'file.rb', 'dir/file.rb').should include(:files_to_run => ['file.rb', 'dir/file.rb'])
46
+ describe "files_or_directories_to_run" do
47
+
48
+ it "parses files from '-c file.rb dir/file.rb'" do
49
+ options_from_args("-c", "file.rb", "dir/file.rb").should include(:files_or_directories_to_run => ["file.rb", "dir/file.rb"])
50
50
  end
51
51
 
52
- example 'dir should parse' do
53
- options_from_args('dir').should include(:files_to_run => ['dir'])
52
+ it "parses dir from 'dir'" do
53
+ options_from_args("dir").should include(:files_or_directories_to_run => ["dir"])
54
54
  end
55
55
 
56
- example 'spec/file1_spec.rb, spec/file2_spec.rb should parse' do
57
- options_from_args('spec/file1_spec.rb', 'spec/file2_spec.rb').should include(:files_to_run => ['spec/file1_spec.rb', 'spec/file2_spec.rb'])
56
+ it "parses dir and files from 'spec/file1_spec.rb, spec/file2_spec.rb'" do
57
+ options_from_args("dir", "spec/file1_spec.rb", "spec/file2_spec.rb").should include(:files_or_directories_to_run => ["dir", "spec/file1_spec.rb", "spec/file2_spec.rb"])
58
58
  end
59
59
 
60
60
  end