opal-rspec 0.0.1.beta1 → 0.0.1.beta2

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,146 +0,0 @@
1
- module RSpec
2
- module Core
3
- module SharedExampleGroup
4
- # @overload shared_examples(name, &block)
5
- # @overload shared_examples(name, tags, &block)
6
- #
7
- # Wraps the `block` in a module which can then be included in example
8
- # groups using `include_examples`, `include_context`, or
9
- # `it_behaves_like`.
10
- #
11
- # @param [String] name to match when looking up this shared group
12
- # @param block to be eval'd in a nested example group generated by `it_behaves_like`
13
- #
14
- # @example
15
- #
16
- # shared_examples "auditable" do
17
- # it "stores an audit record on save!" do
18
- # lambda { auditable.save! }.should change(Audit, :count).by(1)
19
- # end
20
- # end
21
- #
22
- # class Account do
23
- # it_behaves_like "auditable" do
24
- # def auditable; Account.new; end
25
- # end
26
- # end
27
- #
28
- # @see ExampleGroup.it_behaves_like
29
- # @see ExampleGroup.include_examples
30
- # @see ExampleGroup.include_context
31
- def shared_examples(*args, &block)
32
- SharedExampleGroup.registry.add_group(self, *args, &block)
33
- end
34
-
35
- alias_method :shared_context, :shared_examples
36
- alias_method :share_examples_for, :shared_examples
37
- alias_method :shared_examples_for, :shared_examples
38
-
39
- def shared_example_groups
40
- SharedExampleGroup.registry.shared_example_groups_for('main', *ancestors[0..-1])
41
- end
42
-
43
- module TopLevelDSL
44
- def shared_examples(*args, &block)
45
- SharedExampleGroup.registry.add_group('main', *args, &block)
46
- end
47
-
48
- alias_method :shared_context, :shared_examples
49
- alias_method :share_examples_for, :shared_examples
50
- alias_method :shared_examples_for, :shared_examples
51
-
52
- def shared_example_groups
53
- SharedExampleGroup.registry.shared_example_groups_for('main')
54
- end
55
- end
56
-
57
- def self.registry
58
- @registry ||= Registry.new
59
- end
60
-
61
- # @private
62
- #
63
- # Used internally to manage the shared example groups and
64
- # constants. We want to limit the number of methods we add
65
- # to objects we don't own (main and Module) so this allows
66
- # us to have helper methods that don't get added to those
67
- # objects.
68
- class Registry
69
- def add_group(source, *args, &block)
70
- ensure_block_has_source_location(block, CallerFilter.first_non_rspec_line)
71
-
72
- if key? args.first
73
- key = args.shift
74
- warn_if_key_taken source, key, block
75
- add_shared_example_group source, key, block
76
- end
77
-
78
- unless args.empty?
79
- mod = Module.new
80
- (class << mod; self; end).send :define_method, :extended do |host|
81
- host.class_eval(&block)
82
- end
83
- RSpec.configuration.extend mod, *args
84
- end
85
- end
86
-
87
- def shared_example_groups_for(*sources)
88
- Collection.new(sources, shared_example_groups)
89
- end
90
-
91
- def shared_example_groups
92
- @shared_example_groups ||= Hash.new { |hash,key| hash[key] = Hash.new }
93
- end
94
-
95
- def clear
96
- shared_example_groups.clear
97
- end
98
-
99
- private
100
-
101
- def add_shared_example_group(source, key, block)
102
- shared_example_groups[source][key] = block
103
- end
104
-
105
- def key?(candidate)
106
- [String, Symbol, Module].any? { |cls| cls === candidate }
107
- end
108
-
109
- def warn_if_key_taken(source, key, new_block)
110
- return unless existing_block = example_block_for(source, key)
111
-
112
- RSpec.warn_with <<-WARNING
113
- WARN: Shared example group '#{key}' has been previously defined at:
114
- WARN
115
- WARN
116
- WARN
117
- WARN
118
- WARNING
119
- end
120
-
121
- def formatted_location(block)
122
- block.source_location.join ":"
123
- end
124
-
125
- def example_block_for(source, key)
126
- shared_example_groups[source][key]
127
- end
128
-
129
- if Proc.method_defined?(:source_location)
130
- def ensure_block_has_source_location(block, caller_line); end
131
- else # for 1.8.7
132
- def ensure_block_has_source_location(block, caller_line)
133
- block.extend Module.new {
134
- define_method :source_location do
135
- caller_line.split(':')
136
- end
137
- }
138
- end
139
- end
140
- end
141
- end
142
- end
143
- end
144
-
145
- extend RSpec::Core::SharedExampleGroup::TopLevelDSL
146
- Module.send(:include, RSpec::Core::SharedExampleGroup::TopLevelDSL)
data/app/rspec/core.rb DELETED
@@ -1,202 +0,0 @@
1
- require_rspec = if defined?(require_relative)
2
- lambda do |path|
3
- require_relative path
4
- end
5
- else # for 1.8.7
6
- lambda do |path|
7
- require "rspec/#{path}"
8
- end
9
- end
10
-
11
- require 'set'
12
- require 'time'
13
- require 'rbconfig'
14
-
15
- require 'rspec/core/version'
16
-
17
- require 'rspec/support/caller_filter'
18
-
19
- require 'rspec/core/flat_map'
20
- require 'rspec/core/filter_manager'
21
- require 'rspec/core/dsl'
22
- require 'rspec/core/warnings'
23
- require 'rspec/core/reporter'
24
-
25
- require 'rspec/core/hooks'
26
- require 'rspec/core/memoized_helpers'
27
- require 'rspec/core/metadata'
28
- require 'rspec/core/pending'
29
- require 'rspec/core/formatters'
30
- require 'rspec/core/ordering'
31
-
32
- require 'rspec/core/world'
33
- require 'rspec/core/configuration'
34
- require 'rspec/core/option_parser'
35
- require 'rspec/core/configuration_options'
36
- require 'rspec/core/command_line'
37
- require 'rspec/core/runner'
38
- require 'rspec/core/example'
39
- require 'rspec/core/shared_example_group/collection'
40
- require 'rspec/core/shared_example_group'
41
- require 'rspec/core/example_group'
42
-
43
- module RSpec
44
- autoload :SharedContext, 'rspec/core/shared_context'
45
-
46
- # @private
47
- def self.wants_to_quit
48
- # Used internally to determine what to do when a SIGINT is received
49
- world.wants_to_quit
50
- end
51
-
52
- # @private
53
- # Used internally to determine what to do when a SIGINT is received
54
- def self.wants_to_quit=(maybe)
55
- world.wants_to_quit=(maybe)
56
- end
57
-
58
- # @private
59
- # Internal container for global non-configuration data
60
- def self.world
61
- @world ||= RSpec::Core::World.new
62
- end
63
-
64
- # @private
65
- # Used internally to set the global object
66
- def self.world=(new_world)
67
- @world = new_world
68
- end
69
-
70
- # @private
71
- # Used internally to ensure examples get reloaded between multiple runs in
72
- # the same process.
73
- def self.reset
74
- @world = nil
75
- @configuration = nil
76
- end
77
-
78
- # Returns the global [Configuration](RSpec/Core/Configuration) object. While you
79
- # _can_ use this method to access the configuration, the more common
80
- # convention is to use [RSpec.configure](RSpec#configure-class_method).
81
- #
82
- # @example
83
- # RSpec.configuration.drb_port = 1234
84
- # @see RSpec.configure
85
- # @see Core::Configuration
86
- def self.configuration
87
- if block_given?
88
- RSpec.warn_deprecation <<-WARNING
89
-
90
- *****************************************************************
91
- DEPRECATION WARN
92
-
93
- * RSpec.configuration with a block is deprecated and has no effect.
94
- * please use RSpec.configure with a block instead.
95
-
96
- Called from
97
- *****************************************************************
98
-
99
- WARNING
100
- end
101
- @configuration ||= RSpec::Core::Configuration.new
102
- end
103
-
104
- # @private
105
- # Used internally to set the global object
106
- def self.configuration=(new_configuration)
107
- @configuration = new_configuration
108
- end
109
-
110
- # Yields the global configuration to a block.
111
- # @yield [Configuration] global configuration
112
- #
113
- # @example
114
- # RSpec.configure do |config|
115
- # config.add_formatter 'documentation'
116
- # end
117
- # @see Core::Configuration
118
- def self.configure
119
- yield configuration if block_given?
120
- end
121
-
122
- # @private
123
- # Used internally to clear remaining groups when fail_fast is set
124
- def self.clear_remaining_example_groups
125
- world.example_groups.clear
126
- end
127
-
128
- # The example being executed.
129
- #
130
- # The primary audience for this method is library authors who need access
131
- # to the example currently being executed and also want to support all
132
- # versions of RSpec 2 and 3.
133
- #
134
- # @example
135
- #
136
- # RSpec.configure do |c|
137
- # # context.example is deprecated, but RSpec.current_example is not
138
- # # available until RSpec 3.0.
139
- # fetch_current_example = RSpec.respond_to?(:current_example) ?
140
- # proc { RSpec.current_example } : proc { |context| context.example }
141
- #
142
- # c.before(:each) do
143
- # example = fetch_current_example.call(self)
144
- #
145
- # # ...
146
- # end
147
- # end
148
- #
149
- def self.current_example
150
- Thread.current[:_rspec_current_example]
151
- end
152
-
153
- # Set the current example being executed.
154
- # @api private
155
- def self.current_example=(example)
156
- Thread.current[:_rspec_current_example] = example
157
- end
158
-
159
- # @private
160
- def self.windows_os?
161
- RbConfig::CONFIG['host_os'] =~ /cygwin|mswin|mingw|bccwin|wince|emx/
162
- end
163
-
164
- module Core
165
- # @private
166
- # This avoids issues with reporting time caused by examples that
167
- # change the value/meaning of Time.now without properly restoring
168
- # it.
169
- class Time
170
- class << self
171
- def now; ::Time.now; end #define_method(:now, &::Time.method(:now))
172
- end
173
- end
174
-
175
- # @private path to executable file
176
- def self.path_to_executable
177
- @path_to_executable ||= File.expand_path('../../../exe/rspec', __FILE__)
178
- end
179
- end
180
-
181
- MODULES_TO_AUTOLOAD = {
182
- :Matchers => "rspec/expectations",
183
- :Expectations => "rspec/expectations",
184
- :Mocks => "rspec/mocks"
185
- }
186
-
187
- def self.const_missing(name)
188
- # Load rspec-expectations when RSpec::Matchers is referenced. This allows
189
- # people to define custom matchers (using `RSpec::Matchers.define`) before
190
- # rspec-core has loaded rspec-expectations (since it delays the loading of
191
- # it to allow users to configure a different assertion/expectation
192
- # framework). `autoload` can't be used since it works with ruby's built-in
193
- # require (e.g. for files that are available relative to a load path dir),
194
- # but not with rubygems' extended require.
195
- #
196
- # As of rspec 2.14.1, we no longer require `rspec/mocks` and
197
- # `rspec/expectations` when `rspec` is required, so we want
198
- # to make them available as an autoload. For more info, see:
199
- # require MODULES_TO_AUTOLOAD.fetch(name) { return super }
200
- ::RSpec.const_get(name)
201
- end
202
- end
File without changes