rspec-core 2.11.1 → 3.11.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (222) hide show
  1. checksums.yaml +7 -0
  2. checksums.yaml.gz.sig +0 -0
  3. data/.document +1 -1
  4. data/.yardopts +3 -1
  5. data/Changelog.md +1814 -29
  6. data/{License.txt → LICENSE.md} +6 -4
  7. data/README.md +197 -48
  8. data/exe/rspec +2 -23
  9. data/lib/rspec/autorun.rb +1 -0
  10. data/lib/rspec/core/backtrace_formatter.rb +65 -0
  11. data/lib/rspec/core/bisect/coordinator.rb +62 -0
  12. data/lib/rspec/core/bisect/example_minimizer.rb +173 -0
  13. data/lib/rspec/core/bisect/fork_runner.rb +138 -0
  14. data/lib/rspec/core/bisect/server.rb +61 -0
  15. data/lib/rspec/core/bisect/shell_command.rb +126 -0
  16. data/lib/rspec/core/bisect/shell_runner.rb +73 -0
  17. data/lib/rspec/core/bisect/utilities.rb +69 -0
  18. data/lib/rspec/core/configuration.rb +1846 -407
  19. data/lib/rspec/core/configuration_options.rb +154 -50
  20. data/lib/rspec/core/did_you_mean.rb +46 -0
  21. data/lib/rspec/core/drb.rb +120 -0
  22. data/lib/rspec/core/dsl.rb +90 -18
  23. data/lib/rspec/core/example.rb +488 -152
  24. data/lib/rspec/core/example_group.rb +733 -294
  25. data/lib/rspec/core/example_status_persister.rb +235 -0
  26. data/lib/rspec/core/filter_manager.rb +175 -147
  27. data/lib/rspec/core/flat_map.rb +20 -0
  28. data/lib/rspec/core/formatters/base_bisect_formatter.rb +45 -0
  29. data/lib/rspec/core/formatters/base_formatter.rb +32 -130
  30. data/lib/rspec/core/formatters/base_text_formatter.rb +62 -190
  31. data/lib/rspec/core/formatters/bisect_drb_formatter.rb +29 -0
  32. data/lib/rspec/core/formatters/bisect_progress_formatter.rb +157 -0
  33. data/lib/rspec/core/formatters/console_codes.rb +76 -0
  34. data/lib/rspec/core/formatters/deprecation_formatter.rb +223 -0
  35. data/lib/rspec/core/formatters/documentation_formatter.rb +62 -27
  36. data/lib/rspec/core/formatters/exception_presenter.rb +521 -0
  37. data/lib/rspec/core/formatters/failure_list_formatter.rb +23 -0
  38. data/lib/rspec/core/formatters/fallback_message_formatter.rb +28 -0
  39. data/lib/rspec/core/formatters/helpers.rb +93 -14
  40. data/lib/rspec/core/formatters/html_formatter.rb +104 -415
  41. data/lib/rspec/core/formatters/html_printer.rb +414 -0
  42. data/lib/rspec/core/formatters/html_snippet_extractor.rb +120 -0
  43. data/lib/rspec/core/formatters/json_formatter.rb +102 -0
  44. data/lib/rspec/core/formatters/profile_formatter.rb +68 -0
  45. data/lib/rspec/core/formatters/progress_formatter.rb +12 -15
  46. data/lib/rspec/core/formatters/protocol.rb +182 -0
  47. data/lib/rspec/core/formatters/snippet_extractor.rb +115 -39
  48. data/lib/rspec/core/formatters/syntax_highlighter.rb +91 -0
  49. data/lib/rspec/core/formatters.rb +279 -0
  50. data/lib/rspec/core/hooks.rb +451 -300
  51. data/lib/rspec/core/invocations.rb +87 -0
  52. data/lib/rspec/core/memoized_helpers.rb +580 -0
  53. data/lib/rspec/core/metadata.rb +395 -173
  54. data/lib/rspec/core/metadata_filter.rb +255 -0
  55. data/lib/rspec/core/minitest_assertions_adapter.rb +31 -0
  56. data/lib/rspec/core/mocking_adapters/flexmock.rb +31 -0
  57. data/lib/rspec/core/mocking_adapters/mocha.rb +57 -0
  58. data/lib/rspec/core/mocking_adapters/null.rb +14 -0
  59. data/lib/rspec/core/mocking_adapters/rr.rb +31 -0
  60. data/lib/rspec/core/mocking_adapters/rspec.rb +32 -0
  61. data/lib/rspec/core/notifications.rb +521 -0
  62. data/lib/rspec/core/option_parser.rb +208 -64
  63. data/lib/rspec/core/ordering.rb +169 -0
  64. data/lib/rspec/core/output_wrapper.rb +29 -0
  65. data/lib/rspec/core/pending.rb +115 -59
  66. data/lib/rspec/core/profiler.rb +34 -0
  67. data/lib/rspec/core/project_initializer/.rspec +1 -0
  68. data/lib/rspec/core/project_initializer/spec/spec_helper.rb +98 -0
  69. data/lib/rspec/core/project_initializer.rb +26 -65
  70. data/lib/rspec/core/rake_task.rb +140 -131
  71. data/lib/rspec/core/reporter.rb +207 -44
  72. data/lib/rspec/core/ruby_project.rb +15 -6
  73. data/lib/rspec/core/runner.rb +180 -44
  74. data/lib/rspec/core/sandbox.rb +37 -0
  75. data/lib/rspec/core/set.rb +54 -0
  76. data/lib/rspec/core/shared_context.rb +25 -19
  77. data/lib/rspec/core/shared_example_group.rb +229 -54
  78. data/lib/rspec/core/shell_escape.rb +49 -0
  79. data/lib/rspec/core/test_unit_assertions_adapter.rb +30 -0
  80. data/lib/rspec/core/version.rb +3 -1
  81. data/lib/rspec/core/warnings.rb +40 -0
  82. data/lib/rspec/core/world.rb +208 -49
  83. data/lib/rspec/core.rb +166 -80
  84. data.tar.gz.sig +0 -0
  85. metadata +230 -445
  86. metadata.gz.sig +0 -0
  87. data/exe/autospec +0 -13
  88. data/features/Autotest.md +0 -38
  89. data/features/README.md +0 -17
  90. data/features/Upgrade.md +0 -364
  91. data/features/command_line/README.md +0 -28
  92. data/features/command_line/example_name_option.feature +0 -101
  93. data/features/command_line/exit_status.feature +0 -83
  94. data/features/command_line/format_option.feature +0 -81
  95. data/features/command_line/init.feature +0 -18
  96. data/features/command_line/line_number_appended_to_path.feature +0 -140
  97. data/features/command_line/line_number_option.feature +0 -58
  98. data/features/command_line/order.feature +0 -29
  99. data/features/command_line/pattern_option.feature +0 -31
  100. data/features/command_line/rake_task.feature +0 -68
  101. data/features/command_line/ruby.feature +0 -22
  102. data/features/command_line/tag.feature +0 -91
  103. data/features/configuration/alias_example_to.feature +0 -48
  104. data/features/configuration/custom_settings.feature +0 -84
  105. data/features/configuration/default_path.feature +0 -38
  106. data/features/configuration/fail_fast.feature +0 -77
  107. data/features/configuration/read_options_from_file.feature +0 -87
  108. data/features/example_groups/basic_structure.feature +0 -55
  109. data/features/example_groups/shared_context.feature +0 -74
  110. data/features/example_groups/shared_examples.feature +0 -204
  111. data/features/expectation_framework_integration/configure_expectation_framework.feature +0 -102
  112. data/features/filtering/exclusion_filters.feature +0 -139
  113. data/features/filtering/if_and_unless.feature +0 -168
  114. data/features/filtering/inclusion_filters.feature +0 -105
  115. data/features/filtering/run_all_when_everything_filtered.feature +0 -46
  116. data/features/formatters/custom_formatter.feature +0 -36
  117. data/features/formatters/text_formatter.feature +0 -46
  118. data/features/helper_methods/arbitrary_methods.feature +0 -40
  119. data/features/helper_methods/let.feature +0 -50
  120. data/features/helper_methods/modules.feature +0 -149
  121. data/features/hooks/around_hooks.feature +0 -343
  122. data/features/hooks/before_and_after_hooks.feature +0 -423
  123. data/features/hooks/filtering.feature +0 -234
  124. data/features/metadata/current_example.feature +0 -17
  125. data/features/metadata/described_class.feature +0 -17
  126. data/features/metadata/user_defined.feature +0 -113
  127. data/features/mock_framework_integration/use_any_framework.feature +0 -106
  128. data/features/mock_framework_integration/use_flexmock.feature +0 -96
  129. data/features/mock_framework_integration/use_mocha.feature +0 -97
  130. data/features/mock_framework_integration/use_rr.feature +0 -98
  131. data/features/mock_framework_integration/use_rspec.feature +0 -97
  132. data/features/pending/pending_examples.feature +0 -229
  133. data/features/spec_files/arbitrary_file_suffix.feature +0 -13
  134. data/features/step_definitions/additional_cli_steps.rb +0 -30
  135. data/features/subject/attribute_of_subject.feature +0 -124
  136. data/features/subject/explicit_subject.feature +0 -82
  137. data/features/subject/implicit_receiver.feature +0 -29
  138. data/features/subject/implicit_subject.feature +0 -63
  139. data/features/support/env.rb +0 -12
  140. data/lib/autotest/discover.rb +0 -1
  141. data/lib/autotest/rspec2.rb +0 -73
  142. data/lib/rspec/core/backward_compatibility.rb +0 -65
  143. data/lib/rspec/core/command_line.rb +0 -36
  144. data/lib/rspec/core/deprecation.rb +0 -36
  145. data/lib/rspec/core/drb_command_line.rb +0 -26
  146. data/lib/rspec/core/drb_options.rb +0 -87
  147. data/lib/rspec/core/extensions/instance_eval_with_args.rb +0 -44
  148. data/lib/rspec/core/extensions/kernel.rb +0 -9
  149. data/lib/rspec/core/extensions/module_eval_with_args.rb +0 -38
  150. data/lib/rspec/core/extensions/ordered.rb +0 -21
  151. data/lib/rspec/core/extensions.rb +0 -4
  152. data/lib/rspec/core/formatters/text_mate_formatter.rb +0 -34
  153. data/lib/rspec/core/let.rb +0 -110
  154. data/lib/rspec/core/load_path.rb +0 -3
  155. data/lib/rspec/core/metadata_hash_builder.rb +0 -97
  156. data/lib/rspec/core/mocking/with_absolutely_nothing.rb +0 -11
  157. data/lib/rspec/core/mocking/with_flexmock.rb +0 -27
  158. data/lib/rspec/core/mocking/with_mocha.rb +0 -29
  159. data/lib/rspec/core/mocking/with_rr.rb +0 -27
  160. data/lib/rspec/core/mocking/with_rspec.rb +0 -23
  161. data/lib/rspec/core/subject.rb +0 -219
  162. data/spec/autotest/discover_spec.rb +0 -19
  163. data/spec/autotest/failed_results_re_spec.rb +0 -45
  164. data/spec/autotest/rspec_spec.rb +0 -123
  165. data/spec/command_line/order_spec.rb +0 -137
  166. data/spec/rspec/core/command_line_spec.rb +0 -108
  167. data/spec/rspec/core/command_line_spec_output.txt +0 -0
  168. data/spec/rspec/core/configuration_options_spec.rb +0 -377
  169. data/spec/rspec/core/configuration_spec.rb +0 -1196
  170. data/spec/rspec/core/deprecations_spec.rb +0 -66
  171. data/spec/rspec/core/drb_command_line_spec.rb +0 -108
  172. data/spec/rspec/core/drb_options_spec.rb +0 -180
  173. data/spec/rspec/core/dsl_spec.rb +0 -17
  174. data/spec/rspec/core/example_group_spec.rb +0 -1098
  175. data/spec/rspec/core/example_spec.rb +0 -370
  176. data/spec/rspec/core/filter_manager_spec.rb +0 -256
  177. data/spec/rspec/core/formatters/base_formatter_spec.rb +0 -80
  178. data/spec/rspec/core/formatters/base_text_formatter_spec.rb +0 -363
  179. data/spec/rspec/core/formatters/documentation_formatter_spec.rb +0 -88
  180. data/spec/rspec/core/formatters/helpers_spec.rb +0 -66
  181. data/spec/rspec/core/formatters/html_formatted-1.8.7-jruby.html +0 -410
  182. data/spec/rspec/core/formatters/html_formatted-1.8.7.html +0 -409
  183. data/spec/rspec/core/formatters/html_formatted-1.9.2.html +0 -416
  184. data/spec/rspec/core/formatters/html_formatted-1.9.3.html +0 -416
  185. data/spec/rspec/core/formatters/html_formatter_spec.rb +0 -82
  186. data/spec/rspec/core/formatters/progress_formatter_spec.rb +0 -30
  187. data/spec/rspec/core/formatters/snippet_extractor_spec.rb +0 -18
  188. data/spec/rspec/core/formatters/text_mate_formatted-1.8.7-jruby.html +0 -410
  189. data/spec/rspec/core/formatters/text_mate_formatted-1.8.7.html +0 -409
  190. data/spec/rspec/core/formatters/text_mate_formatted-1.9.2.html +0 -416
  191. data/spec/rspec/core/formatters/text_mate_formatted-1.9.3.html +0 -416
  192. data/spec/rspec/core/formatters/text_mate_formatter_spec.rb +0 -83
  193. data/spec/rspec/core/hooks_filtering_spec.rb +0 -227
  194. data/spec/rspec/core/hooks_spec.rb +0 -250
  195. data/spec/rspec/core/kernel_extensions_spec.rb +0 -9
  196. data/spec/rspec/core/let_spec.rb +0 -55
  197. data/spec/rspec/core/metadata_spec.rb +0 -447
  198. data/spec/rspec/core/option_parser_spec.rb +0 -166
  199. data/spec/rspec/core/pending_example_spec.rb +0 -220
  200. data/spec/rspec/core/project_initializer_spec.rb +0 -130
  201. data/spec/rspec/core/rake_task_spec.rb +0 -138
  202. data/spec/rspec/core/reporter_spec.rb +0 -103
  203. data/spec/rspec/core/resources/a_bar.rb +0 -0
  204. data/spec/rspec/core/resources/a_foo.rb +0 -0
  205. data/spec/rspec/core/resources/a_spec.rb +0 -1
  206. data/spec/rspec/core/resources/custom_example_group_runner.rb +0 -14
  207. data/spec/rspec/core/resources/formatter_specs.rb +0 -60
  208. data/spec/rspec/core/resources/utf8_encoded.rb +0 -8
  209. data/spec/rspec/core/rspec_matchers_spec.rb +0 -45
  210. data/spec/rspec/core/ruby_project_spec.rb +0 -24
  211. data/spec/rspec/core/runner_spec.rb +0 -81
  212. data/spec/rspec/core/shared_context_spec.rb +0 -67
  213. data/spec/rspec/core/shared_example_group_spec.rb +0 -84
  214. data/spec/rspec/core/subject_spec.rb +0 -244
  215. data/spec/rspec/core/world_spec.rb +0 -144
  216. data/spec/rspec/core_spec.rb +0 -35
  217. data/spec/spec_helper.rb +0 -98
  218. data/spec/support/config_options_helper.rb +0 -24
  219. data/spec/support/helper_methods.rb +0 -5
  220. data/spec/support/matchers.rb +0 -65
  221. data/spec/support/shared_example_groups.rb +0 -41
  222. data/spec/support/spec_files.rb +0 -44
@@ -1,27 +0,0 @@
1
- require 'rr'
2
-
3
- RSpec.configuration.backtrace_clean_patterns.push(RR::Errors::BACKTRACE_IDENTIFIER)
4
-
5
- module RSpec
6
- module Core
7
- module MockFrameworkAdapter
8
-
9
- def self.framework_name; :rr end
10
-
11
- include RR::Extensions::InstanceMethods
12
-
13
- def setup_mocks_for_rspec
14
- RR::Space.instance.reset
15
- end
16
-
17
- def verify_mocks_for_rspec
18
- RR::Space.instance.verify_doubles
19
- end
20
-
21
- def teardown_mocks_for_rspec
22
- RR::Space.instance.reset
23
- end
24
-
25
- end
26
- end
27
- end
@@ -1,23 +0,0 @@
1
- require 'rspec/mocks'
2
-
3
- module RSpec
4
- module Core
5
- module MockFrameworkAdapter
6
-
7
- def self.framework_name; :rspec end
8
-
9
- def setup_mocks_for_rspec
10
- RSpec::Mocks::setup(self)
11
- end
12
-
13
- def verify_mocks_for_rspec
14
- RSpec::Mocks::verify
15
- end
16
-
17
- def teardown_mocks_for_rspec
18
- RSpec::Mocks::teardown
19
- end
20
-
21
- end
22
- end
23
- end
@@ -1,219 +0,0 @@
1
- module RSpec
2
- module Core
3
- module Subject
4
- module ExampleMethods
5
- # Returns the example group's `subject`.
6
- #
7
- # @note `subject` was contributed by Joe Ferris to support the one-liner
8
- # syntax embraced by shoulda matchers:
9
- #
10
- # describe Widget do
11
- # it { should validate_presence_of(:name) }
12
- # end
13
- #
14
- # While the examples below demonstrate how to use `subject`
15
- # explicitly in examples, we recommend that you define a method with
16
- # an intention revealing name instead.
17
- #
18
- # @example
19
- #
20
- # # explicit declaration of subject
21
- # describe Person do
22
- # subject { Person.new(:birthdate => 19.years.ago) }
23
- # it "should be eligible to vote" do
24
- # subject.should be_eligible_to_vote
25
- # # ^ ^ explicit reference to subject not recommended
26
- # end
27
- # end
28
- #
29
- # # implicit subject => { Person.new }
30
- # describe Person do
31
- # it "should be eligible to vote" do
32
- # subject.should be_eligible_to_vote
33
- # # ^ ^ explicit reference to subject not recommended
34
- # end
35
- # end
36
- #
37
- # # one-liner syntax - should is invoked on subject
38
- # describe Person do
39
- # it { should be_eligible_to_vote }
40
- # end
41
- #
42
- # @see ExampleGroupMethods#subject
43
- # @see #should
44
- def subject
45
- if defined?(@original_subject)
46
- @original_subject
47
- else
48
- @original_subject = instance_eval(&self.class.subject)
49
- end
50
- end
51
-
52
- # When `should` is called with no explicit receiver, the call is
53
- # delegated to the object returned by `subject`. Combined with an
54
- # implicit subject this supports very concise expressions.
55
- #
56
- # @example
57
- #
58
- # describe Person do
59
- # it { should be_eligible_to_vote }
60
- # end
61
- #
62
- # @see #subject
63
- def should(matcher=nil, message=nil)
64
- RSpec::Expectations::PositiveExpectationHandler.handle_matcher(subject, matcher, message)
65
- end
66
-
67
- # Just like `should`, `should_not` delegates to the subject (implicit or
68
- # explicit) of the example group.
69
- #
70
- # @example
71
- #
72
- # describe Person do
73
- # it { should_not be_eligible_to_vote }
74
- # end
75
- #
76
- # @see #subject
77
- def should_not(matcher=nil, message=nil)
78
- RSpec::Expectations::NegativeExpectationHandler.handle_matcher(subject, matcher, message)
79
- end
80
-
81
- private
82
-
83
- def _attribute_chain(attribute)
84
- attribute.to_s.split('.')
85
- end
86
-
87
- def _nested_attribute(subject, attribute)
88
- _attribute_chain(attribute).inject(subject) do |inner_subject, attr|
89
- inner_subject.send(attr)
90
- end
91
- end
92
- end
93
-
94
- module ExampleGroupMethods
95
- # Creates a nested example group named by the submitted `attribute`,
96
- # and then generates an example using the submitted block.
97
- #
98
- # @example
99
- #
100
- # # This ...
101
- # describe Array do
102
- # its(:size) { should eq(0) }
103
- # end
104
- #
105
- # # ... generates the same runtime structure as this:
106
- # describe Array do
107
- # describe "size" do
108
- # it "should eq(0)" do
109
- # subject.size.should eq(0)
110
- # end
111
- # end
112
- # end
113
- #
114
- # The attribute can be a `Symbol` or a `String`. Given a `String`
115
- # with dots, the result is as though you concatenated that `String`
116
- # onto the subject in an expression.
117
- #
118
- # @example
119
- #
120
- # describe Person do
121
- # subject do
122
- # Person.new.tap do |person|
123
- # person.phone_numbers << "555-1212"
124
- # end
125
- # end
126
- #
127
- # its("phone_numbers.first") { should eq("555-1212") }
128
- # end
129
- #
130
- # When the subject is a `Hash`, you can refer to the Hash keys by
131
- # specifying a `Symbol` or `String` in an array.
132
- #
133
- # @example
134
- #
135
- # describe "a configuration Hash" do
136
- # subject do
137
- # { :max_users => 3,
138
- # 'admin' => :all_permissions }
139
- # end
140
- #
141
- # its([:max_users]) { should eq(3) }
142
- # its(['admin']) { should eq(:all_permissions) }
143
- #
144
- # # You can still access to its regular methods this way:
145
- # its(:keys) { should include(:max_users) }
146
- # its(:count) { should eq(2) }
147
- # end
148
- def its(attribute, &block)
149
- describe(attribute) do
150
- example do
151
- self.class.class_eval do
152
- define_method(:subject) do
153
- if defined?(@_subject)
154
- @_subject
155
- else
156
- @_subject = Array === attribute ? super()[*attribute] : _nested_attribute(super(), attribute)
157
- end
158
- end
159
- end
160
- instance_eval(&block)
161
- end
162
- end
163
- end
164
-
165
- # Declares a `subject` for an example group which can then be the
166
- # implicit receiver (through delegation) of calls to `should`.
167
- #
168
- # Given a `name`, defines a method with that name which returns the
169
- # `subject`. This lets you declare the subject once and access it
170
- # implicitly in one-liners and explicitly using an intention revealing
171
- # name.
172
- #
173
- # @param [String,Symbol] name used to define an accessor with an
174
- # intention revealing name
175
- # @param block defines the value to be returned by `subject` in examples
176
- #
177
- # @example
178
- #
179
- # describe CheckingAccount, "with $50" do
180
- # subject { CheckingAccount.new(Money.new(50, :USD)) }
181
- # it { should have_a_balance_of(Money.new(50, :USD)) }
182
- # it { should_not be_overdrawn }
183
- # end
184
- #
185
- # describe CheckingAccount, "with a non-zero starting balance" do
186
- # subject(:account) { CheckingAccount.new(Money.new(50, :USD)) }
187
- # it { should_not be_overdrawn }
188
- # it "has a balance equal to the starting balance" do
189
- # account.balance.should eq(Money.new(50, :USD))
190
- # end
191
- # end
192
- #
193
- # @see ExampleMethods#subject
194
- # @see ExampleMethods#should
195
- def subject(name=nil, &block)
196
- define_method(name) { subject } if name
197
- block ? @explicit_subject_block = block : explicit_subject || implicit_subject
198
- end
199
-
200
- attr_reader :explicit_subject_block
201
-
202
- private
203
-
204
- def explicit_subject
205
- group = self
206
- while group.respond_to?(:explicit_subject_block)
207
- return group.explicit_subject_block if group.explicit_subject_block
208
- group = group.superclass
209
- end
210
- end
211
-
212
- def implicit_subject
213
- described = described_class || description
214
- Class === described ? proc { described.new } : proc { described }
215
- end
216
- end
217
- end
218
- end
219
- end
@@ -1,19 +0,0 @@
1
- require "spec_helper"
2
-
3
- describe "autotest/discover.rb" do
4
- context "with ./.rspec present" do
5
- it "adds 'rspec2' to the list of discoveries" do
6
- File.stub(:exist?).with("./.rspec") { true }
7
- Autotest.should_receive(:add_discovery)
8
- load File.expand_path("../../../lib/autotest/discover.rb", __FILE__)
9
- end
10
- end
11
-
12
- context "with ./.rspec absent" do
13
- it "does not add 'rspec2' to the list of discoveries" do
14
- File.stub(:exist?) { false }
15
- Autotest.should_not_receive(:add_discovery)
16
- load File.expand_path("../../../lib/autotest/discover.rb", __FILE__)
17
- end
18
- end
19
- end
@@ -1,45 +0,0 @@
1
- require "spec_helper"
2
-
3
- describe "failed_results_re for autotest" do
4
- def run_example
5
- group = RSpec::Core::ExampleGroup.describe("group")
6
- group.example("example") { yield }
7
- io = StringIO.new
8
- formatter = RSpec::Core::Formatters::BaseTextFormatter.new(io)
9
- reporter = RSpec::Core::Reporter.new(formatter)
10
-
11
- group.run(reporter)
12
- reporter.report(1, nil) {}
13
- io.string
14
- end
15
-
16
- shared_examples "autotest failed_results_re" do
17
- it "matches a failure" do
18
- output = run_example { fail }
19
- output.should match(Autotest::Rspec2.new.failed_results_re)
20
- output.should include(__FILE__.sub(File.expand_path('.'),'.'))
21
- end
22
-
23
- it "does not match when there are no failures" do
24
- output = run_example { } # pass
25
- output.should_not match(Autotest::Rspec2.new.failed_results_re)
26
- output.should_not include(__FILE__.sub(File.expand_path('.'),'.'))
27
- end
28
- end
29
-
30
- context "with color enabled" do
31
- before do
32
- RSpec.configuration.stub(:color_enabled? => true)
33
- end
34
-
35
- include_examples "autotest failed_results_re"
36
- end
37
-
38
- context "with color disabled " do
39
- before do
40
- RSpec.configuration.stub(:color_enabled? => false)
41
- end
42
-
43
- include_examples "autotest failed_results_re"
44
- end
45
- end
@@ -1,123 +0,0 @@
1
- require "spec_helper"
2
-
3
- describe Autotest::Rspec2 do
4
- let(:rspec_autotest) { Autotest::Rspec2.new }
5
- let(:spec_cmd) { File.expand_path("../../../exe/rspec", __FILE__) }
6
- let(:ruby_cmd) { "ruby" }
7
-
8
- before do
9
- File.stub(:exist?) { false }
10
- end
11
-
12
- it "uses autotest's prefix" do
13
- rspec_autotest.prefix = "this is the prefix "
14
- rspec_autotest.
15
- make_test_cmd({'a' => 'b'}).should match(/this is the prefix/)
16
- end
17
-
18
- describe "commands" do
19
- before do
20
- rspec_autotest.stub(:ruby => ruby_cmd)
21
- files = %w[file_one file_two]
22
- @files_to_test = {
23
- files[0] => [],
24
- files[1] => []
25
- }
26
- # this is not the inner representation of Autotest!
27
- rspec_autotest.files_to_test = @files_to_test
28
- @to_test = files.map { |f| File.expand_path(f) }.join ' '
29
- end
30
-
31
- it "makes the appropriate test command" do
32
- actual_command = rspec_autotest.make_test_cmd(@files_to_test)
33
- expected_command = /#{ruby_cmd}.*'#{spec_cmd}' (.*)/
34
-
35
- actual_command.should match(expected_command)
36
-
37
- actual_command =~ expected_command
38
- $1.should =~ /#{File.expand_path('file_one')}/
39
- $1.should =~ /#{File.expand_path('file_two')}/
40
- end
41
-
42
- it "returns a blank command for no files" do
43
- rspec_autotest.make_test_cmd({}).should eq('')
44
- end
45
-
46
- it "quotes the paths of files to test" do
47
- cmd = rspec_autotest.make_test_cmd(@files_to_test)
48
- @files_to_test.keys.each do |file_to_test|
49
- cmd.should match(/'#{File.expand_path(file_to_test)}'/)
50
- end
51
- end
52
-
53
- it "gives '--tty' to #{Autotest::Rspec2::RSPEC_EXECUTABLE}, not '--autotest'" do
54
- cmd = rspec_autotest.make_test_cmd(@files_to_test)
55
- cmd.should match(' --tty ')
56
- cmd.should_not match(' --autotest ')
57
- end
58
- end
59
-
60
- describe "mappings" do
61
- before do
62
- @lib_file = "lib/something.rb"
63
- @spec_file = "spec/something_spec.rb"
64
- rspec_autotest.hook :initialize
65
- end
66
-
67
- it "finds the spec file for a given lib file" do
68
- rspec_autotest.should map_specs([@spec_file]).to(@lib_file)
69
- end
70
-
71
- it "finds the spec file if given a spec file" do
72
- rspec_autotest.should map_specs([@spec_file]).to(@spec_file)
73
- end
74
-
75
- it "ignores files in spec dir that aren't specs" do
76
- rspec_autotest.should map_specs([]).to("spec/spec_helper.rb")
77
- end
78
-
79
- it "ignores untracked files (in @file)" do
80
- rspec_autotest.should map_specs([]).to("lib/untracked_file")
81
- end
82
- end
83
-
84
- describe "consolidating failures" do
85
- let(:subject_file) { "lib/autotest/some.rb" }
86
- let(:spec_file) { "spec/autotest/some_spec.rb" }
87
-
88
- it "returns no failures if no failures were given in the output" do
89
- rspec_autotest.consolidate_failures([[]]).should eq({})
90
- end
91
-
92
- it "returns a hash with the spec filename => spec name for each failure or error" do
93
- failures = [ [ "false should be false", spec_file ] ]
94
- rspec_autotest.consolidate_failures(failures).should eq({
95
- spec_file => ["false should be false"]
96
- })
97
- end
98
-
99
- context "when subject file appears before the spec file in the backtrace" do
100
- let(:failures) do
101
- [ [ "false should be false", "#{subject_file}:143:\n#{spec_file}:203:" ] ]
102
- end
103
-
104
- it "excludes the subject file" do
105
- rspec_autotest.consolidate_failures(failures).keys.should_not include(subject_file)
106
- end
107
-
108
- it "includes the spec file" do
109
- rspec_autotest.consolidate_failures(failures).keys.should include(spec_file)
110
- end
111
- end
112
- end
113
-
114
- describe "normalizing file names" do
115
- it "ensures that a single file appears in files_to_test only once" do
116
- @files_to_test = {}
117
- ['filename.rb', './filename.rb', File.expand_path('filename.rb')].each do |file|
118
- @files_to_test[file] = []
119
- end
120
- rspec_autotest.normalize(@files_to_test).should have(1).file
121
- end
122
- end
123
- end
@@ -1,137 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe 'command line', :ui do
4
- let(:stderr) { StringIO.new }
5
- let(:stdout) { StringIO.new }
6
-
7
- before :all do
8
- write_file 'spec/order_spec.rb', """
9
- describe 'group 1' do
10
- specify('group 1 example 1') {}
11
- specify('group 1 example 2') {}
12
- specify('group 1 example 3') {}
13
- specify('group 1 example 4') {}
14
- specify('group 1 example 5') {}
15
- specify('group 1 example 6') {}
16
- specify('group 1 example 5') {}
17
- specify('group 1 example 7') {}
18
- specify('group 1 example 8') {}
19
- specify('group 1 example 9') {}
20
- specify('group 1 example 10') {}
21
-
22
- describe 'group 1-1' do
23
- specify('group 1-1 example 1') {}
24
- specify('group 1-1 example 2') {}
25
- specify('group 1-1 example 3') {}
26
- specify('group 1-1 example 4') {}
27
- specify('group 1-1 example 5') {}
28
- specify('group 1-1 example 6') {}
29
- specify('group 1-1 example 7') {}
30
- specify('group 1-1 example 8') {}
31
- specify('group 1-1 example 9') {}
32
- specify('group 1-1 example 10') {}
33
- end
34
-
35
- describe('group 1-2') { specify('example') {} }
36
- describe('group 1-3') { specify('example') {} }
37
- describe('group 1-4') { specify('example') {} }
38
- describe('group 1-5') { specify('example') {} }
39
- describe('group 1-6') { specify('example') {} }
40
- describe('group 1-7') { specify('example') {} }
41
- describe('group 1-8') { specify('example') {} }
42
- describe('group 1-9') { specify('example') {} }
43
- describe('group 1-10') { specify('example') {} }
44
- end
45
-
46
- describe('group 2') { specify('example') {} }
47
- describe('group 3') { specify('example') {} }
48
- describe('group 4') { specify('example') {} }
49
- describe('group 5') { specify('example') {} }
50
- describe('group 6') { specify('example') {} }
51
- describe('group 7') { specify('example') {} }
52
- describe('group 8') { specify('example') {} }
53
- describe('group 9') { specify('example') {} }
54
- describe('group 10') { specify('example') {} }
55
- """
56
- end
57
-
58
- describe '--order rand' do
59
- it 'runs the examples and groups in a different order each time' do
60
- run_command 'tmp/aruba/spec/order_spec.rb --order rand -f doc'
61
- RSpec.configuration.seed = srand && srand # reset seed in same process
62
- run_command 'tmp/aruba/spec/order_spec.rb --order rand -f doc'
63
-
64
- stdout.string.should match(/Randomized with seed \d+/)
65
-
66
- top_level_groups {|first_run, second_run| first_run.should_not eq(second_run)}
67
- nested_groups {|first_run, second_run| first_run.should_not eq(second_run)}
68
- examples('group 1') {|first_run, second_run| first_run.should_not eq(second_run)}
69
- examples('group 1-1') {|first_run, second_run| first_run.should_not eq(second_run)}
70
- end
71
- end
72
-
73
- describe '--order rand:SEED' do
74
- it 'runs the examples and groups in the same order each time' do
75
- 2.times { run_command 'tmp/aruba/spec/order_spec.rb --order rand:123 -f doc' }
76
-
77
- stdout.string.should match(/Randomized with seed 123/)
78
-
79
- top_level_groups {|first_run, second_run| first_run.should eq(second_run)}
80
- nested_groups {|first_run, second_run| first_run.should eq(second_run)}
81
- examples('group 1') {|first_run, second_run| first_run.should eq(second_run)}
82
- examples('group 1-1') {|first_run, second_run| first_run.should eq(second_run)}
83
- end
84
- end
85
-
86
- describe '--seed SEED' do
87
- it "forces '--order rand' and runs the examples and groups in the same order each time" do
88
- 2.times { run_command 'tmp/aruba/spec/order_spec.rb --seed 123 -f doc' }
89
-
90
- stdout.string.should match(/Randomized with seed \d+/)
91
-
92
- top_level_groups {|first_run, second_run| first_run.should eq(second_run)}
93
- nested_groups {|first_run, second_run| first_run.should eq(second_run)}
94
- examples('group 1') {|first_run, second_run| first_run.should eq(second_run)}
95
- examples('group 1-1') {|first_run, second_run| first_run.should eq(second_run)}
96
- end
97
- end
98
-
99
- describe '--order default on CLI with --order rand in .rspec' do
100
- it "overrides --order rand with --order default" do
101
- write_file '.rspec', '--order rand'
102
-
103
- run_command 'tmp/aruba/spec/order_spec.rb --order default -f doc'
104
-
105
- stdout.string.should_not match(/Randomized/)
106
-
107
- stdout.string.should match(
108
- /group 1.*group 1 example 1.*group 1 example 2.*group 1-1.*group 1-2.*group 2.*/m
109
- )
110
- end
111
- end
112
-
113
- def examples(group)
114
- yield split_in_half(stdout.string.scan(/^\s+#{group} example.*$/))
115
- end
116
-
117
- def top_level_groups
118
- yield example_groups_at_level(0)
119
- end
120
-
121
- def nested_groups
122
- yield example_groups_at_level(2)
123
- end
124
-
125
- def example_groups_at_level(level)
126
- split_in_half(stdout.string.scan(/^\s{#{level*2}}group.*$/))
127
- end
128
-
129
- def split_in_half(array)
130
- length, midpoint = array.length, array.length / 2
131
- return array.slice(0, midpoint), array.slice(midpoint, length)
132
- end
133
-
134
- def run_command(cmd)
135
- RSpec::Core::Runner.run(cmd.split, stderr, stdout)
136
- end
137
- end