opal-rspec 0.4.0.beta3 → 0.4.0.beta4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (161) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +0 -1
  3. data/.gitmodules +15 -0
  4. data/.travis.yml +12 -0
  5. data/.yardopts +5 -0
  6. data/CHANGELOG.md +3 -1
  7. data/Gemfile +6 -7
  8. data/README.md +2 -0
  9. data/Rakefile +12 -50
  10. data/lib/opal/rspec/version.rb +1 -1
  11. data/lib/opal/rspec.rb +14 -0
  12. data/opal/opal/rspec/async.rb +146 -11
  13. data/opal/opal/rspec/fixes.rb +18 -8
  14. data/opal/opal/rspec/requires.rb +45 -0
  15. data/opal/opal/rspec.rb +1 -24
  16. data/opal-rspec.gemspec +1 -1
  17. data/spec/async_spec.rb +4 -5
  18. data/spec/matchers_spec.rb +20 -0
  19. data/spec/named_subject_spec.rb +11 -0
  20. data/spec/should_syntax_spec.rb +17 -0
  21. data/vendor_lib/rspec/autorun.rb +2 -0
  22. data/vendor_lib/rspec/core/backport_random.rb +302 -0
  23. data/vendor_lib/rspec/core/backtrace_formatter.rb +65 -0
  24. data/vendor_lib/rspec/core/command_line.rb +36 -0
  25. data/vendor_lib/rspec/core/configuration.rb +1129 -0
  26. data/vendor_lib/rspec/core/configuration_options.rb +143 -0
  27. data/vendor_lib/rspec/core/drb_command_line.rb +26 -0
  28. data/vendor_lib/rspec/core/drb_options.rb +87 -0
  29. data/vendor_lib/rspec/core/dsl.rb +26 -0
  30. data/vendor_lib/rspec/core/example.rb +312 -0
  31. data/vendor_lib/rspec/core/example_group.rb +540 -0
  32. data/vendor_lib/rspec/core/filter_manager.rb +224 -0
  33. data/vendor_lib/rspec/core/flat_map.rb +17 -0
  34. data/vendor_lib/rspec/core/formatters/base_formatter.rb +291 -0
  35. data/vendor_lib/rspec/core/formatters/base_text_formatter.rb +307 -0
  36. data/vendor_lib/rspec/core/formatters/deprecation_formatter.rb +193 -0
  37. data/vendor_lib/rspec/core/formatters/documentation_formatter.rb +67 -0
  38. data/vendor_lib/rspec/core/formatters/helpers.rb +82 -0
  39. data/vendor_lib/rspec/core/formatters/html_formatter.rb +155 -0
  40. data/vendor_lib/rspec/core/formatters/html_printer.rb +408 -0
  41. data/vendor_lib/rspec/core/formatters/json_formatter.rb +99 -0
  42. data/vendor_lib/rspec/core/formatters/progress_formatter.rb +32 -0
  43. data/vendor_lib/rspec/core/formatters/snippet_extractor.rb +101 -0
  44. data/vendor_lib/rspec/core/formatters.rb +54 -0
  45. data/vendor_lib/rspec/core/hooks.rb +535 -0
  46. data/vendor_lib/rspec/core/memoized_helpers.rb +431 -0
  47. data/vendor_lib/rspec/core/metadata.rb +313 -0
  48. data/vendor_lib/rspec/core/mocking/with_absolutely_nothing.rb +11 -0
  49. data/vendor_lib/rspec/core/mocking/with_flexmock.rb +27 -0
  50. data/vendor_lib/rspec/core/mocking/with_mocha.rb +52 -0
  51. data/vendor_lib/rspec/core/mocking/with_rr.rb +27 -0
  52. data/vendor_lib/rspec/core/mocking/with_rspec.rb +27 -0
  53. data/vendor_lib/rspec/core/option_parser.rb +234 -0
  54. data/vendor_lib/rspec/core/ordering.rb +154 -0
  55. data/vendor_lib/rspec/core/pending.rb +110 -0
  56. data/vendor_lib/rspec/core/project_initializer.rb +88 -0
  57. data/vendor_lib/rspec/core/rake_task.rb +128 -0
  58. data/vendor_lib/rspec/core/reporter.rb +132 -0
  59. data/vendor_lib/rspec/core/ruby_project.rb +44 -0
  60. data/vendor_lib/rspec/core/runner.rb +97 -0
  61. data/vendor_lib/rspec/core/shared_context.rb +53 -0
  62. data/vendor_lib/rspec/core/shared_example_group/collection.rb +27 -0
  63. data/vendor_lib/rspec/core/shared_example_group.rb +146 -0
  64. data/vendor_lib/rspec/core/version.rb +7 -0
  65. data/vendor_lib/rspec/core/warnings.rb +22 -0
  66. data/vendor_lib/rspec/core/world.rb +131 -0
  67. data/vendor_lib/rspec/core.rb +203 -0
  68. data/vendor_lib/rspec/expectations/differ.rb +154 -0
  69. data/vendor_lib/rspec/expectations/errors.rb +9 -0
  70. data/vendor_lib/rspec/expectations/expectation_target.rb +87 -0
  71. data/vendor_lib/rspec/expectations/extensions/object.rb +29 -0
  72. data/vendor_lib/rspec/expectations/extensions.rb +1 -0
  73. data/vendor_lib/rspec/expectations/fail_with.rb +79 -0
  74. data/vendor_lib/rspec/expectations/handler.rb +68 -0
  75. data/vendor_lib/rspec/expectations/syntax.rb +182 -0
  76. data/vendor_lib/rspec/expectations/version.rb +8 -0
  77. data/vendor_lib/rspec/expectations.rb +75 -0
  78. data/vendor_lib/rspec/matchers/built_in/base_matcher.rb +68 -0
  79. data/vendor_lib/rspec/matchers/built_in/be.rb +213 -0
  80. data/vendor_lib/rspec/matchers/built_in/be_instance_of.rb +15 -0
  81. data/vendor_lib/rspec/matchers/built_in/be_kind_of.rb +11 -0
  82. data/vendor_lib/rspec/matchers/built_in/be_within.rb +55 -0
  83. data/vendor_lib/rspec/matchers/built_in/change.rb +141 -0
  84. data/vendor_lib/rspec/matchers/built_in/cover.rb +21 -0
  85. data/vendor_lib/rspec/matchers/built_in/eq.rb +22 -0
  86. data/vendor_lib/rspec/matchers/built_in/eql.rb +23 -0
  87. data/vendor_lib/rspec/matchers/built_in/equal.rb +48 -0
  88. data/vendor_lib/rspec/matchers/built_in/exist.rb +26 -0
  89. data/vendor_lib/rspec/matchers/built_in/has.rb +48 -0
  90. data/vendor_lib/rspec/matchers/built_in/include.rb +61 -0
  91. data/vendor_lib/rspec/matchers/built_in/match.rb +17 -0
  92. data/vendor_lib/rspec/matchers/built_in/match_array.rb +51 -0
  93. data/vendor_lib/rspec/matchers/built_in/raise_error.rb +154 -0
  94. data/vendor_lib/rspec/matchers/built_in/respond_to.rb +74 -0
  95. data/vendor_lib/rspec/matchers/built_in/satisfy.rb +30 -0
  96. data/vendor_lib/rspec/matchers/built_in/start_and_end_with.rb +48 -0
  97. data/vendor_lib/rspec/matchers/built_in/throw_symbol.rb +94 -0
  98. data/vendor_lib/rspec/matchers/built_in/yield.rb +297 -0
  99. data/vendor_lib/rspec/matchers/built_in.rb +39 -0
  100. data/vendor_lib/rspec/matchers/compatibility.rb +14 -0
  101. data/vendor_lib/rspec/matchers/configuration.rb +113 -0
  102. data/vendor_lib/rspec/matchers/dsl.rb +23 -0
  103. data/vendor_lib/rspec/matchers/generated_descriptions.rb +35 -0
  104. data/vendor_lib/rspec/matchers/matcher.rb +301 -0
  105. data/vendor_lib/rspec/matchers/method_missing.rb +12 -0
  106. data/vendor_lib/rspec/matchers/operator_matcher.rb +99 -0
  107. data/vendor_lib/rspec/matchers/pretty.rb +70 -0
  108. data/vendor_lib/rspec/matchers/test_unit_integration.rb +11 -0
  109. data/vendor_lib/rspec/matchers.rb +633 -0
  110. data/vendor_lib/rspec/mocks/any_instance/chain.rb +92 -0
  111. data/vendor_lib/rspec/mocks/any_instance/expectation_chain.rb +47 -0
  112. data/vendor_lib/rspec/mocks/any_instance/message_chains.rb +75 -0
  113. data/vendor_lib/rspec/mocks/any_instance/recorder.rb +200 -0
  114. data/vendor_lib/rspec/mocks/any_instance/stub_chain.rb +45 -0
  115. data/vendor_lib/rspec/mocks/any_instance/stub_chain_chain.rb +23 -0
  116. data/vendor_lib/rspec/mocks/argument_list_matcher.rb +104 -0
  117. data/vendor_lib/rspec/mocks/argument_matchers.rb +264 -0
  118. data/vendor_lib/rspec/mocks/arity_calculator.rb +66 -0
  119. data/vendor_lib/rspec/mocks/configuration.rb +111 -0
  120. data/vendor_lib/rspec/mocks/error_generator.rb +203 -0
  121. data/vendor_lib/rspec/mocks/errors.rb +12 -0
  122. data/vendor_lib/rspec/mocks/example_methods.rb +201 -0
  123. data/vendor_lib/rspec/mocks/extensions/marshal.rb +17 -0
  124. data/vendor_lib/rspec/mocks/framework.rb +36 -0
  125. data/vendor_lib/rspec/mocks/instance_method_stasher.rb +112 -0
  126. data/vendor_lib/rspec/mocks/matchers/have_received.rb +99 -0
  127. data/vendor_lib/rspec/mocks/matchers/receive.rb +112 -0
  128. data/vendor_lib/rspec/mocks/matchers/receive_messages.rb +72 -0
  129. data/vendor_lib/rspec/mocks/message_expectation.rb +643 -0
  130. data/vendor_lib/rspec/mocks/method_double.rb +209 -0
  131. data/vendor_lib/rspec/mocks/method_reference.rb +95 -0
  132. data/vendor_lib/rspec/mocks/mock.rb +7 -0
  133. data/vendor_lib/rspec/mocks/mutate_const.rb +406 -0
  134. data/vendor_lib/rspec/mocks/object_reference.rb +90 -0
  135. data/vendor_lib/rspec/mocks/order_group.rb +82 -0
  136. data/vendor_lib/rspec/mocks/proxy.rb +269 -0
  137. data/vendor_lib/rspec/mocks/proxy_for_nil.rb +37 -0
  138. data/vendor_lib/rspec/mocks/space.rb +95 -0
  139. data/vendor_lib/rspec/mocks/standalone.rb +3 -0
  140. data/vendor_lib/rspec/mocks/stub_chain.rb +51 -0
  141. data/vendor_lib/rspec/mocks/syntax.rb +374 -0
  142. data/vendor_lib/rspec/mocks/targets.rb +90 -0
  143. data/vendor_lib/rspec/mocks/test_double.rb +109 -0
  144. data/vendor_lib/rspec/mocks/verifying_double.rb +77 -0
  145. data/vendor_lib/rspec/mocks/verifying_message_expecation.rb +60 -0
  146. data/vendor_lib/rspec/mocks/verifying_proxy.rb +151 -0
  147. data/vendor_lib/rspec/mocks/version.rb +7 -0
  148. data/vendor_lib/rspec/mocks.rb +100 -0
  149. data/vendor_lib/rspec/support/caller_filter.rb +56 -0
  150. data/vendor_lib/rspec/support/spec/deprecation_helpers.rb +29 -0
  151. data/vendor_lib/rspec/support/spec/in_sub_process.rb +40 -0
  152. data/vendor_lib/rspec/support/spec/stderr_splitter.rb +50 -0
  153. data/vendor_lib/rspec/support/spec.rb +14 -0
  154. data/vendor_lib/rspec/support/version.rb +7 -0
  155. data/vendor_lib/rspec/support/warnings.rb +41 -0
  156. data/vendor_lib/rspec/support.rb +6 -0
  157. data/vendor_lib/rspec/version.rb +5 -0
  158. data/vendor_lib/rspec-expectations.rb +1 -0
  159. data/vendor_lib/rspec.rb +3 -0
  160. metadata +163 -4
  161. data/opal/opal/rspec/rspec.js +0 -20384
@@ -0,0 +1,154 @@
1
+ module RSpec
2
+ module Core
3
+ if defined?(::Random)
4
+ RandomNumberGenerator = ::Random
5
+ else
6
+ require 'rspec/core/backport_random'
7
+ RandomNumberGenerator = RSpec::Core::Backports::Random
8
+ end
9
+
10
+ # @private
11
+ module Ordering
12
+ # @private
13
+ # The default global ordering (defined order).
14
+ class Identity
15
+ def order(items)
16
+ items
17
+ end
18
+ end
19
+
20
+ # @private
21
+ # Orders items randomly.
22
+ class Random
23
+ def initialize(configuration)
24
+ @configuration = configuration
25
+ @used = false
26
+ end
27
+
28
+ def used?
29
+ @used
30
+ end
31
+
32
+ def order(items)
33
+ @used = true
34
+ rng = RandomNumberGenerator.new(@configuration.seed)
35
+ shuffle items, rng
36
+ end
37
+
38
+ if RUBY_VERSION > '1.9.3'
39
+ def shuffle(list, rng)
40
+ list.shuffle(:random => rng)
41
+ end
42
+ else
43
+ def shuffle(list, rng)
44
+ shuffled = list.dup
45
+ shuffled.size.times do |i|
46
+ j = i + rng.rand(shuffled.size - i)
47
+ next if i == j
48
+ shuffled[i], shuffled[j] = shuffled[j], shuffled[i]
49
+ end
50
+
51
+ shuffled
52
+ end
53
+ end
54
+ end
55
+
56
+ # @private
57
+ # Orders items based on a custom block.
58
+ class Custom
59
+ def initialize(callable)
60
+ @callable = callable
61
+ end
62
+
63
+ def order(list)
64
+ @callable.call(list)
65
+ end
66
+ end
67
+
68
+ # @private
69
+ # Stores the different ordering strategies.
70
+ class Registry
71
+ def initialize(configuration)
72
+ @configuration = configuration
73
+ @strategies = {}
74
+
75
+ register(:random, Random.new(configuration))
76
+
77
+ identity = Identity.new
78
+ register(:defined, identity)
79
+
80
+ # The default global ordering is --defined.
81
+ register(:global, identity)
82
+ end
83
+
84
+ def fetch(name, &fallback)
85
+ @strategies.fetch(name, &fallback)
86
+ end
87
+
88
+ def register(sym, strategy)
89
+ @strategies[sym] = strategy
90
+ end
91
+
92
+ def used_random_seed?
93
+ @strategies[:random].used?
94
+ end
95
+ end
96
+
97
+ # @private
98
+ # Manages ordering configuration.
99
+ #
100
+ # @note This is not intended to be used externally. Use
101
+ # the APIs provided by `RSpec::Core::Configuration` instead.
102
+ class ConfigurationManager
103
+ attr_reader :seed, :ordering_registry
104
+
105
+ def initialize
106
+ @ordering_registry = Registry.new(self)
107
+ @seed = rand(0xFFFF)
108
+ @seed_forced = false
109
+ @order_forced = false
110
+ end
111
+
112
+ def seed_used?
113
+ ordering_registry.used_random_seed?
114
+ end
115
+
116
+ def seed=(seed)
117
+ return if @seed_forced
118
+ register_ordering(:global, ordering_registry.fetch(:random))
119
+ @seed = seed.to_i
120
+ end
121
+
122
+ def order=(type)
123
+ order, seed = type.to_s.split(':')
124
+ @seed = seed = seed.to_i if seed
125
+
126
+ ordering_name = if order.include?('rand')
127
+ :random
128
+ elsif order == 'defined'
129
+ :defined
130
+ end
131
+
132
+ register_ordering(:global, ordering_registry.fetch(ordering_name)) if ordering_name
133
+ end
134
+
135
+ def force(hash)
136
+ if hash.has_key?(:seed)
137
+ self.seed = hash[:seed]
138
+ @seed_forced = true
139
+ @order_forced = true
140
+ elsif hash.has_key?(:order)
141
+ self.order = hash[:order]
142
+ @order_forced = true
143
+ end
144
+ end
145
+
146
+ def register_ordering(name, strategy = Custom.new(Proc.new { |l| yield l }))
147
+ return if @order_forced && name == :global
148
+ ordering_registry.register(name, strategy)
149
+ end
150
+ end
151
+ end
152
+ end
153
+ end
154
+
@@ -0,0 +1,110 @@
1
+ module RSpec
2
+ module Core
3
+ module Pending
4
+ class PendingDeclaredInExample < StandardError; end
5
+
6
+ # If Test::Unit is loaed, we'll use its error as baseclass, so that Test::Unit
7
+ # will report unmet RSpec expectations as failures rather than errors.
8
+ begin
9
+ class PendingExampleFixedError < Test::Unit::AssertionFailedError; end
10
+ rescue
11
+ class PendingExampleFixedError < StandardError; end
12
+ end
13
+
14
+ NO_REASON_GIVEN = 'No reason given'
15
+ NOT_YET_IMPLEMENTED = 'Not yet implemented'
16
+
17
+ # @overload pending()
18
+ # @overload pending(message)
19
+ # @overload pending(message, &block)
20
+ #
21
+ # Stops execution of an example, and reports it as pending. Takes an
22
+ # optional message and block.
23
+ #
24
+ # @param [String] message optional message to add to the summary report.
25
+ # @param [Block] block optional block. If it fails, the example is
26
+ # reported as pending. If it executes cleanly the example fails.
27
+ #
28
+ # @example
29
+ #
30
+ # describe "an example" do
31
+ # # reported as "Pending: no reason given"
32
+ # it "is pending with no message" do
33
+ # pending
34
+ # this_does_not_get_executed
35
+ # end
36
+ #
37
+ # # reported as "Pending: something else getting finished"
38
+ # it "is pending with a custom message" do
39
+ # pending("something else getting finished")
40
+ # this_does_not_get_executed
41
+ # end
42
+ #
43
+ # # reported as "Pending: something else getting finished"
44
+ # it "is pending with a failing block" do
45
+ # pending("something else getting finished") do
46
+ # raise "this is the failure"
47
+ # end
48
+ # end
49
+ #
50
+ # # reported as failure, saying we expected the block to fail but
51
+ # # it passed.
52
+ # it "is pending with a passing block" do
53
+ # pending("something else getting finished") do
54
+ # true.should be(true)
55
+ # end
56
+ # end
57
+ # end
58
+ #
59
+ # @note `before(:each)` hooks are eval'd when you use the `pending`
60
+ # method within an example. If you want to declare an example `pending`
61
+ # and bypass the `before` hooks as well, you can pass `:pending => true`
62
+ # to the `it` method:
63
+ #
64
+ # it "does something", :pending => true do
65
+ # # ...
66
+ # end
67
+ #
68
+ # or pass `:pending => "something else getting finished"` to add a
69
+ # message to the summary report:
70
+ #
71
+ # it "does something", :pending => "something else getting finished" do
72
+ # # ...
73
+ # end
74
+ def pending(*args)
75
+ current_example = RSpec.current_example
76
+
77
+ return self.class.before(:each) { pending(*args) } unless current_example
78
+
79
+ options = args.last.is_a?(Hash) ? args.pop : {}
80
+ message = args.first || NO_REASON_GIVEN
81
+
82
+ if options[:unless] || (options.has_key?(:if) && !options[:if])
83
+ return block_given? ? yield : nil
84
+ end
85
+
86
+ current_example.metadata[:pending] = true
87
+ current_example.metadata[:execution_result][:pending_message] = message
88
+ current_example.execution_result[:pending_fixed] = false
89
+ if block_given?
90
+ begin
91
+ result = begin
92
+ yield
93
+ current_example.example_group_instance.instance_eval { verify_mocks_for_rspec }
94
+ end
95
+ current_example.metadata[:pending] = false
96
+ rescue Exception => e
97
+ current_example.execution_result[:exception] = e
98
+ ensure
99
+ teardown_mocks_for_rspec
100
+ end
101
+ if result
102
+ current_example.execution_result[:pending_fixed] = true
103
+ raise PendingExampleFixedError.new
104
+ end
105
+ end
106
+ raise PendingDeclaredInExample.new(message)
107
+ end
108
+ end
109
+ end
110
+ end
@@ -0,0 +1,88 @@
1
+ module RSpec
2
+ module Core
3
+ class ProjectInitializer
4
+ def initialize(arg=nil)
5
+ @arg = arg
6
+ end
7
+
8
+ def run
9
+ create_spec_helper_file
10
+ create_dot_rspec_file
11
+
12
+ delete_if_confirmed("lib/tasks/rspec.rake", <<-MESSAGE)
13
+ If the file in lib/tasks/rspec.rake is the one generated by rspec-rails-1x,
14
+ you can get rid of it, as it is no longer needed with rspec-2.
15
+ MESSAGE
16
+ end
17
+
18
+ def create_dot_rspec_file
19
+ if File.exist?('.rspec')
20
+ report_exists('.rspec')
21
+ else
22
+ report_creating('.rspec')
23
+ File.open('.rspec','w') do |f|
24
+ f.write <<-CONTENT
25
+ --color
26
+ --format progress
27
+ CONTENT
28
+ end
29
+ end
30
+ end
31
+
32
+ def create_spec_helper_file
33
+ if File.exist?('spec/spec_helper.rb')
34
+ report_exists('spec/spec_helper.rb')
35
+ else
36
+ report_creating('spec/spec_helper.rb')
37
+ FileUtils.mkdir_p('spec')
38
+ File.open('spec/spec_helper.rb','w') do |f|
39
+ f.write <<-CONTENT
40
+ # This file was generated by the `rspec --init` command. Conventionally, all
41
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
42
+ # Require this file using `require "spec_helper"` to ensure that it is only
43
+ # loaded once.
44
+ #
45
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
46
+ RSpec.configure do |config|
47
+ # Limit the spec run to only specs with the focus metadata. If no specs have
48
+ # the filtering metadata and `run_all_when_everything_filtered = true` then
49
+ # all specs will run.
50
+ #config.filter_run :focus
51
+
52
+ # Run all specs when none match the provided filter. This works well in
53
+ # conjunction with `config.filter_run :focus`, as it will run the entire
54
+ # suite when no specs have `:filter` metadata.
55
+ #config.run_all_when_everything_filtered = true
56
+
57
+ # Run specs in random order to surface order dependencies. If you find an
58
+ # order dependency and want to debug it, you can fix the order by providing
59
+ # the seed, which is printed after each run.
60
+ # --seed 1234
61
+ #config.order = 'random'
62
+ end
63
+ CONTENT
64
+ end
65
+ end
66
+ end
67
+
68
+ def delete_if_confirmed(path, message)
69
+ if File.exist?(path)
70
+ puts
71
+ puts message
72
+ puts
73
+ puts " delete #{path}? [y/n]"
74
+ FileUtils.rm_rf(path) if gets =~ /y/i
75
+ end
76
+ end
77
+
78
+ def report_exists(file)
79
+ puts " exist #{file}"
80
+ end
81
+
82
+ def report_creating(file)
83
+ puts " create #{file}"
84
+ end
85
+
86
+ end
87
+ end
88
+ end
@@ -0,0 +1,128 @@
1
+ require 'rspec/support/warnings'
2
+ require 'rake'
3
+ require 'rake/tasklib'
4
+ require 'shellwords'
5
+
6
+ module RSpec
7
+ module Core
8
+ class RakeTask < ::Rake::TaskLib
9
+ include ::Rake::DSL if defined?(::Rake::DSL)
10
+
11
+ # Name of task.
12
+ #
13
+ # default:
14
+ # :spec
15
+ attr_accessor :name
16
+
17
+ # Glob pattern to match files.
18
+ #
19
+ # default:
20
+ # 'spec/**/*_spec.rb'
21
+ attr_accessor :pattern
22
+
23
+ # Whether or not to fail Rake when an error occurs (typically when examples fail).
24
+ #
25
+ # default:
26
+ # true
27
+ attr_accessor :fail_on_error
28
+
29
+ # A message to print to stderr when there are failures.
30
+ attr_accessor :failure_message
31
+
32
+ # Use verbose output. If this is set to true, the task will print the
33
+ # executed spec command to stdout.
34
+ #
35
+ # default:
36
+ # true
37
+ attr_accessor :verbose
38
+
39
+ # Command line options to pass to ruby.
40
+ #
41
+ # default:
42
+ # nil
43
+ attr_accessor :ruby_opts
44
+
45
+ # Path to rspec
46
+ #
47
+ # default:
48
+ # 'rspec'
49
+ attr_accessor :rspec_path
50
+
51
+ # Command line options to pass to rspec.
52
+ #
53
+ # default:
54
+ # nil
55
+ attr_accessor :rspec_opts
56
+
57
+ # @deprecated
58
+ # Use rspec_opts instead.
59
+ #
60
+ # Command line options to pass to rspec.
61
+ #
62
+ # default:
63
+ # nil
64
+ def spec_opts=(opts)
65
+ RSpec.deprecate('RSpec::Core::RakeTask#spec_opts=', :replacement => 'rspec_opts=')
66
+ @rspec_opts = opts
67
+ end
68
+
69
+ def initialize(*args, &task_block)
70
+ setup_ivars(args)
71
+
72
+ desc "Run RSpec code examples" unless ::Rake.application.last_comment
73
+
74
+ task name, *args do |_, task_args|
75
+ RakeFileUtils.send(:verbose, verbose) do
76
+ task_block.call(*[self, task_args].slice(0, task_block.arity)) if task_block
77
+ run_task verbose
78
+ end
79
+ end
80
+ end
81
+
82
+ def setup_ivars(args)
83
+ @name = args.shift || :spec
84
+ @ruby_opts, @rspec_opts = nil, nil, nil
85
+ @verbose, @fail_on_error = true, true
86
+
87
+ @rspec_path = 'rspec'
88
+ @pattern = './spec{,/*/**}/*_spec.rb'
89
+ end
90
+
91
+ def run_task(verbose)
92
+ command = spec_command
93
+
94
+ begin
95
+ puts command if verbose
96
+ success = system(command)
97
+ rescue
98
+ puts failure_message if failure_message
99
+ end
100
+ abort("#{command} failed") if fail_on_error unless success
101
+ end
102
+
103
+ private
104
+
105
+ def files_to_run
106
+ if ENV['SPEC']
107
+ FileList[ ENV['SPEC'] ].sort
108
+ else
109
+ FileList[ pattern ].sort.map(&:shellescape)
110
+ end
111
+ end
112
+
113
+ def spec_command
114
+ cmd_parts = []
115
+ cmd_parts << RUBY
116
+ cmd_parts << ruby_opts
117
+ cmd_parts << "-S" << rspec_path
118
+ cmd_parts << files_to_run
119
+ cmd_parts << rspec_opts
120
+ cmd_parts.flatten.reject(&blank).join(" ")
121
+ end
122
+
123
+ def blank
124
+ lambda {|s| s.nil? || s == ""}
125
+ end
126
+ end
127
+ end
128
+ end
@@ -0,0 +1,132 @@
1
+ module RSpec::Core
2
+ class Reporter
3
+ NOTIFICATIONS = %W[start message example_group_started example_group_finished example_started
4
+ example_passed example_failed example_pending start_dump dump_pending
5
+ dump_failures dump_summary seed close stop deprecation deprecation_summary].map(&:to_sym)
6
+
7
+ def initialize(configuration, *formatters)
8
+ @configuration = configuration
9
+ @listeners = Hash.new { |h,k| h[k] = [] }
10
+ formatters.each do |formatter|
11
+ register_listener(formatter, *NOTIFICATIONS)
12
+ end
13
+ @example_count = @failure_count = @pending_count = 0
14
+ @duration = @start = nil
15
+ end
16
+
17
+ # @api
18
+ # @param [Object] An obect that wishes to be notified of reporter events
19
+ # @param [Array] Array of symbols represents the events a listener wishes to subscribe too
20
+ #
21
+ # Registers a listener to a list of notifications. The reporter will send notification of
22
+ # events to all registered listeners
23
+ def register_listener(listener, *notifications)
24
+ notifications.each do |notification|
25
+ @listeners[notification.to_sym] << listener if listener.respond_to?(notification)
26
+ end
27
+ true
28
+ end
29
+
30
+ def registered_listeners(notification)
31
+ @listeners[notification]
32
+ end
33
+
34
+ # @api
35
+ # @overload report(count, &block)
36
+ # @overload report(count, &block)
37
+ # @param [Integer] count the number of examples being run
38
+ # @param [Block] block yields itself for further reporting.
39
+ #
40
+ # Initializes the report run and yields itself for further reporting. The
41
+ # block is required, so that the reporter can manage cleaning up after the
42
+ # run.
43
+ #
44
+ # @example
45
+ #
46
+ # reporter.report(group.examples.size) do |r|
47
+ # example_groups.map {|g| g.run(r) }
48
+ # end
49
+ #
50
+ def report(expected_example_count)
51
+ start(expected_example_count)
52
+ begin
53
+ yield self
54
+ ensure
55
+ finish
56
+ end
57
+ end
58
+
59
+ def start(expected_example_count)
60
+ @start = RSpec::Core::Time.now
61
+ notify :start, expected_example_count
62
+ end
63
+
64
+ def message(message)
65
+ notify :message, message
66
+ end
67
+
68
+ def example_group_started(group)
69
+ notify :example_group_started, group unless group.descendant_filtered_examples.empty?
70
+ end
71
+
72
+ def example_group_finished(group)
73
+ notify :example_group_finished, group unless group.descendant_filtered_examples.empty?
74
+ end
75
+
76
+ def example_started(example)
77
+ @example_count += 1
78
+ notify :example_started, example
79
+ end
80
+
81
+ def example_passed(example)
82
+ notify :example_passed, example
83
+ end
84
+
85
+ def example_failed(example)
86
+ @failure_count += 1
87
+ notify :example_failed, example
88
+ end
89
+
90
+ def example_pending(example)
91
+ @pending_count += 1
92
+ notify :example_pending, example
93
+ end
94
+
95
+ def deprecation(message)
96
+ notify :deprecation, message
97
+ end
98
+
99
+ def finish
100
+ begin
101
+ stop
102
+ notify :start_dump
103
+ notify :dump_pending
104
+ notify :dump_failures
105
+ notify :dump_summary, @duration, @example_count, @failure_count, @pending_count
106
+ notify :deprecation_summary
107
+ notify :seed, @configuration.seed if seed_used?
108
+ ensure
109
+ notify :close
110
+ end
111
+ end
112
+
113
+ alias_method :abort, :finish
114
+
115
+ def stop
116
+ @duration = (RSpec::Core::Time.now - @start).to_f if @start
117
+ notify :stop
118
+ end
119
+
120
+ def notify(event, *args, &block)
121
+ registered_listeners(event).each do |formatter|
122
+ formatter.send(event, *args, &block)
123
+ end
124
+ end
125
+
126
+ private
127
+
128
+ def seed_used?
129
+ @configuration.seed && @configuration.seed_used?
130
+ end
131
+ end
132
+ end
@@ -0,0 +1,44 @@
1
+ # This is borrowed (slightly modified) from Scott Taylor's
2
+ # project_path project:
3
+ # http://github.com/smtlaissezfaire/project_path
4
+
5
+ require 'pathname'
6
+
7
+ module RSpec
8
+ module Core
9
+ module RubyProject
10
+ def add_to_load_path(*dirs)
11
+ dirs.map {|dir| add_dir_to_load_path(File.join(root, dir))}
12
+ end
13
+
14
+ def add_dir_to_load_path(dir)
15
+ $LOAD_PATH.unshift(dir) unless $LOAD_PATH.include?(dir)
16
+ end
17
+
18
+ def root
19
+ @project_root ||= determine_root
20
+ end
21
+
22
+ def determine_root
23
+ find_first_parent_containing('spec') || '.'
24
+ end
25
+
26
+ def find_first_parent_containing(dir)
27
+ ascend_until {|path| File.exists?(File.join(path, dir))}
28
+ end
29
+
30
+ def ascend_until
31
+ Pathname(File.expand_path('.')).ascend do |path|
32
+ return path if yield(path)
33
+ end
34
+ end
35
+
36
+ module_function :add_to_load_path
37
+ module_function :add_dir_to_load_path
38
+ module_function :root
39
+ module_function :determine_root
40
+ module_function :find_first_parent_containing
41
+ module_function :ascend_until
42
+ end
43
+ end
44
+ end