opal-rspec-cj 0.4.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (176) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +3 -0
  3. data/.gitmodules +15 -0
  4. data/.travis.yml +13 -0
  5. data/.yardopts +5 -0
  6. data/CHANGELOG.md +25 -0
  7. data/Gemfile +8 -0
  8. data/README.md +147 -0
  9. data/Rakefile +26 -0
  10. data/config.ru +10 -0
  11. data/example/Gemfile +4 -0
  12. data/example/README.md +13 -0
  13. data/example/Rakefile +8 -0
  14. data/example/opal/user.rb +11 -0
  15. data/example/spec/user_spec.rb +15 -0
  16. data/lib/opal-rspec.rb +2 -0
  17. data/lib/opal/rspec.rb +20 -0
  18. data/lib/opal/rspec/rake_task.rb +63 -0
  19. data/lib/opal/rspec/version.rb +5 -0
  20. data/opal-rspec.gemspec +21 -0
  21. data/opal/opal-rspec.rb +1 -0
  22. data/opal/opal/rspec.rb +25 -0
  23. data/opal/opal/rspec/async.rb +289 -0
  24. data/opal/opal/rspec/browser_formatter.rb +188 -0
  25. data/opal/opal/rspec/fixes.rb +116 -0
  26. data/opal/opal/rspec/requires.rb +45 -0
  27. data/opal/opal/rspec/runner.rb +69 -0
  28. data/opal/opal/rspec/sprockets_runner.rb.erb +11 -0
  29. data/opal/opal/rspec/text_formatter.rb +74 -0
  30. data/spec/async_spec.rb +38 -0
  31. data/spec/example_spec.rb +163 -0
  32. data/spec/matchers_spec.rb +201 -0
  33. data/spec/mock_spec.rb +63 -0
  34. data/spec/named_subject_spec.rb +11 -0
  35. data/spec/should_syntax_spec.rb +17 -0
  36. data/vendor/spec_runner.js +50 -0
  37. data/vendor_lib/rspec-expectations.rb +1 -0
  38. data/vendor_lib/rspec.rb +3 -0
  39. data/vendor_lib/rspec/autorun.rb +2 -0
  40. data/vendor_lib/rspec/core.rb +203 -0
  41. data/vendor_lib/rspec/core/backport_random.rb +302 -0
  42. data/vendor_lib/rspec/core/backtrace_formatter.rb +65 -0
  43. data/vendor_lib/rspec/core/command_line.rb +36 -0
  44. data/vendor_lib/rspec/core/configuration.rb +1129 -0
  45. data/vendor_lib/rspec/core/configuration_options.rb +143 -0
  46. data/vendor_lib/rspec/core/drb_command_line.rb +26 -0
  47. data/vendor_lib/rspec/core/drb_options.rb +87 -0
  48. data/vendor_lib/rspec/core/dsl.rb +26 -0
  49. data/vendor_lib/rspec/core/example.rb +312 -0
  50. data/vendor_lib/rspec/core/example_group.rb +540 -0
  51. data/vendor_lib/rspec/core/filter_manager.rb +224 -0
  52. data/vendor_lib/rspec/core/flat_map.rb +17 -0
  53. data/vendor_lib/rspec/core/formatters.rb +54 -0
  54. data/vendor_lib/rspec/core/formatters/base_formatter.rb +291 -0
  55. data/vendor_lib/rspec/core/formatters/base_text_formatter.rb +307 -0
  56. data/vendor_lib/rspec/core/formatters/deprecation_formatter.rb +193 -0
  57. data/vendor_lib/rspec/core/formatters/documentation_formatter.rb +67 -0
  58. data/vendor_lib/rspec/core/formatters/helpers.rb +82 -0
  59. data/vendor_lib/rspec/core/formatters/html_formatter.rb +155 -0
  60. data/vendor_lib/rspec/core/formatters/html_printer.rb +408 -0
  61. data/vendor_lib/rspec/core/formatters/json_formatter.rb +99 -0
  62. data/vendor_lib/rspec/core/formatters/progress_formatter.rb +32 -0
  63. data/vendor_lib/rspec/core/formatters/snippet_extractor.rb +101 -0
  64. data/vendor_lib/rspec/core/hooks.rb +535 -0
  65. data/vendor_lib/rspec/core/memoized_helpers.rb +431 -0
  66. data/vendor_lib/rspec/core/metadata.rb +313 -0
  67. data/vendor_lib/rspec/core/mocking/with_absolutely_nothing.rb +11 -0
  68. data/vendor_lib/rspec/core/mocking/with_flexmock.rb +27 -0
  69. data/vendor_lib/rspec/core/mocking/with_mocha.rb +52 -0
  70. data/vendor_lib/rspec/core/mocking/with_rr.rb +27 -0
  71. data/vendor_lib/rspec/core/mocking/with_rspec.rb +27 -0
  72. data/vendor_lib/rspec/core/option_parser.rb +234 -0
  73. data/vendor_lib/rspec/core/ordering.rb +154 -0
  74. data/vendor_lib/rspec/core/pending.rb +110 -0
  75. data/vendor_lib/rspec/core/project_initializer.rb +88 -0
  76. data/vendor_lib/rspec/core/rake_task.rb +128 -0
  77. data/vendor_lib/rspec/core/reporter.rb +132 -0
  78. data/vendor_lib/rspec/core/ruby_project.rb +44 -0
  79. data/vendor_lib/rspec/core/runner.rb +97 -0
  80. data/vendor_lib/rspec/core/shared_context.rb +53 -0
  81. data/vendor_lib/rspec/core/shared_example_group.rb +146 -0
  82. data/vendor_lib/rspec/core/shared_example_group/collection.rb +27 -0
  83. data/vendor_lib/rspec/core/version.rb +7 -0
  84. data/vendor_lib/rspec/core/warnings.rb +22 -0
  85. data/vendor_lib/rspec/core/world.rb +131 -0
  86. data/vendor_lib/rspec/expectations.rb +75 -0
  87. data/vendor_lib/rspec/expectations/differ.rb +154 -0
  88. data/vendor_lib/rspec/expectations/errors.rb +9 -0
  89. data/vendor_lib/rspec/expectations/expectation_target.rb +87 -0
  90. data/vendor_lib/rspec/expectations/extensions.rb +1 -0
  91. data/vendor_lib/rspec/expectations/extensions/object.rb +29 -0
  92. data/vendor_lib/rspec/expectations/fail_with.rb +79 -0
  93. data/vendor_lib/rspec/expectations/handler.rb +68 -0
  94. data/vendor_lib/rspec/expectations/syntax.rb +182 -0
  95. data/vendor_lib/rspec/expectations/version.rb +8 -0
  96. data/vendor_lib/rspec/matchers.rb +633 -0
  97. data/vendor_lib/rspec/matchers/built_in.rb +39 -0
  98. data/vendor_lib/rspec/matchers/built_in/base_matcher.rb +68 -0
  99. data/vendor_lib/rspec/matchers/built_in/be.rb +213 -0
  100. data/vendor_lib/rspec/matchers/built_in/be_instance_of.rb +15 -0
  101. data/vendor_lib/rspec/matchers/built_in/be_kind_of.rb +11 -0
  102. data/vendor_lib/rspec/matchers/built_in/be_within.rb +55 -0
  103. data/vendor_lib/rspec/matchers/built_in/change.rb +141 -0
  104. data/vendor_lib/rspec/matchers/built_in/cover.rb +21 -0
  105. data/vendor_lib/rspec/matchers/built_in/eq.rb +22 -0
  106. data/vendor_lib/rspec/matchers/built_in/eql.rb +23 -0
  107. data/vendor_lib/rspec/matchers/built_in/equal.rb +48 -0
  108. data/vendor_lib/rspec/matchers/built_in/exist.rb +26 -0
  109. data/vendor_lib/rspec/matchers/built_in/has.rb +48 -0
  110. data/vendor_lib/rspec/matchers/built_in/include.rb +61 -0
  111. data/vendor_lib/rspec/matchers/built_in/match.rb +17 -0
  112. data/vendor_lib/rspec/matchers/built_in/match_array.rb +51 -0
  113. data/vendor_lib/rspec/matchers/built_in/raise_error.rb +154 -0
  114. data/vendor_lib/rspec/matchers/built_in/respond_to.rb +74 -0
  115. data/vendor_lib/rspec/matchers/built_in/satisfy.rb +30 -0
  116. data/vendor_lib/rspec/matchers/built_in/start_and_end_with.rb +48 -0
  117. data/vendor_lib/rspec/matchers/built_in/throw_symbol.rb +94 -0
  118. data/vendor_lib/rspec/matchers/built_in/yield.rb +297 -0
  119. data/vendor_lib/rspec/matchers/compatibility.rb +14 -0
  120. data/vendor_lib/rspec/matchers/configuration.rb +113 -0
  121. data/vendor_lib/rspec/matchers/dsl.rb +23 -0
  122. data/vendor_lib/rspec/matchers/generated_descriptions.rb +35 -0
  123. data/vendor_lib/rspec/matchers/matcher.rb +301 -0
  124. data/vendor_lib/rspec/matchers/method_missing.rb +12 -0
  125. data/vendor_lib/rspec/matchers/operator_matcher.rb +99 -0
  126. data/vendor_lib/rspec/matchers/pretty.rb +70 -0
  127. data/vendor_lib/rspec/matchers/test_unit_integration.rb +11 -0
  128. data/vendor_lib/rspec/mocks.rb +100 -0
  129. data/vendor_lib/rspec/mocks/any_instance/chain.rb +92 -0
  130. data/vendor_lib/rspec/mocks/any_instance/expectation_chain.rb +47 -0
  131. data/vendor_lib/rspec/mocks/any_instance/message_chains.rb +75 -0
  132. data/vendor_lib/rspec/mocks/any_instance/recorder.rb +200 -0
  133. data/vendor_lib/rspec/mocks/any_instance/stub_chain.rb +45 -0
  134. data/vendor_lib/rspec/mocks/any_instance/stub_chain_chain.rb +23 -0
  135. data/vendor_lib/rspec/mocks/argument_list_matcher.rb +104 -0
  136. data/vendor_lib/rspec/mocks/argument_matchers.rb +264 -0
  137. data/vendor_lib/rspec/mocks/arity_calculator.rb +66 -0
  138. data/vendor_lib/rspec/mocks/configuration.rb +111 -0
  139. data/vendor_lib/rspec/mocks/error_generator.rb +203 -0
  140. data/vendor_lib/rspec/mocks/errors.rb +12 -0
  141. data/vendor_lib/rspec/mocks/example_methods.rb +201 -0
  142. data/vendor_lib/rspec/mocks/extensions/marshal.rb +17 -0
  143. data/vendor_lib/rspec/mocks/framework.rb +36 -0
  144. data/vendor_lib/rspec/mocks/instance_method_stasher.rb +112 -0
  145. data/vendor_lib/rspec/mocks/matchers/have_received.rb +99 -0
  146. data/vendor_lib/rspec/mocks/matchers/receive.rb +112 -0
  147. data/vendor_lib/rspec/mocks/matchers/receive_messages.rb +72 -0
  148. data/vendor_lib/rspec/mocks/message_expectation.rb +643 -0
  149. data/vendor_lib/rspec/mocks/method_double.rb +209 -0
  150. data/vendor_lib/rspec/mocks/method_reference.rb +95 -0
  151. data/vendor_lib/rspec/mocks/mock.rb +7 -0
  152. data/vendor_lib/rspec/mocks/mutate_const.rb +406 -0
  153. data/vendor_lib/rspec/mocks/object_reference.rb +90 -0
  154. data/vendor_lib/rspec/mocks/order_group.rb +82 -0
  155. data/vendor_lib/rspec/mocks/proxy.rb +269 -0
  156. data/vendor_lib/rspec/mocks/proxy_for_nil.rb +37 -0
  157. data/vendor_lib/rspec/mocks/space.rb +95 -0
  158. data/vendor_lib/rspec/mocks/standalone.rb +3 -0
  159. data/vendor_lib/rspec/mocks/stub_chain.rb +51 -0
  160. data/vendor_lib/rspec/mocks/syntax.rb +374 -0
  161. data/vendor_lib/rspec/mocks/targets.rb +90 -0
  162. data/vendor_lib/rspec/mocks/test_double.rb +109 -0
  163. data/vendor_lib/rspec/mocks/verifying_double.rb +77 -0
  164. data/vendor_lib/rspec/mocks/verifying_message_expecation.rb +60 -0
  165. data/vendor_lib/rspec/mocks/verifying_proxy.rb +151 -0
  166. data/vendor_lib/rspec/mocks/version.rb +7 -0
  167. data/vendor_lib/rspec/support.rb +6 -0
  168. data/vendor_lib/rspec/support/caller_filter.rb +56 -0
  169. data/vendor_lib/rspec/support/spec.rb +14 -0
  170. data/vendor_lib/rspec/support/spec/deprecation_helpers.rb +29 -0
  171. data/vendor_lib/rspec/support/spec/in_sub_process.rb +40 -0
  172. data/vendor_lib/rspec/support/spec/stderr_splitter.rb +50 -0
  173. data/vendor_lib/rspec/support/version.rb +7 -0
  174. data/vendor_lib/rspec/support/warnings.rb +41 -0
  175. data/vendor_lib/rspec/version.rb +5 -0
  176. metadata +268 -0
@@ -0,0 +1,116 @@
1
+ require 'encoding'
2
+
3
+ # This breaks on 2.0.0, so it is here ready for when opal bumps to 2.0.0
4
+ class RSpec::CallerFilter
5
+ def self.first_non_rspec_line
6
+ ""
7
+ end
8
+ end
9
+
10
+ # Opal does not support mutable strings
11
+ module RSpec
12
+ module Matchers
13
+ module Pretty
14
+ def underscore(camel_cased_word)
15
+ word = camel_cased_word.to_s
16
+ word = word.gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2')
17
+ word = word.gsub(/([a-z\d])([A-Z])/,'\1_\2')
18
+ word = word.tr("-", "_")
19
+ word = word.downcase
20
+ word
21
+ end
22
+ end
23
+ end
24
+ end
25
+
26
+ module RSpec::ExampleGroups
27
+ # opal cannot use mutable strings AND opal doesnt support `\A` or `\z` anchors
28
+ def self.base_name_for(group)
29
+ return "Anonymous" if group.description.empty?
30
+
31
+ # convert to CamelCase
32
+ name = ' ' + group.description
33
+ name = name.gsub(/[^0-9a-zA-Z]+([0-9a-zA-Z])/) { |m| m[1].upcase }
34
+
35
+ name = name.lstrip # Remove leading whitespace
36
+ name = name.gsub(/\W/, '') # JRuby, RBX and others don't like non-ascii in const names
37
+
38
+ # Ruby requires first const letter to be A-Z. Use `Nested`
39
+ # as necessary to enforce that.
40
+ name = name.gsub(/^([^A-Z]|$)/, 'Nested\1')
41
+
42
+ name
43
+ end
44
+
45
+ # opal cannot use mutable strings
46
+ def self.disambiguate(name, const_scope)
47
+ return name unless const_scope.const_defined?(name)
48
+
49
+ # Add a trailing number if needed to disambiguate from an existing constant.
50
+ name = name + "_2"
51
+ while const_scope.const_defined?(name)
52
+ name = name.next
53
+ end
54
+
55
+ name
56
+ end
57
+ end
58
+
59
+ # Opal does not support ObjectSpace, so force object __id__'s
60
+ class RSpec::Mocks::Space
61
+ def id_for(object)
62
+ object.__id__
63
+ end
64
+ end
65
+
66
+ # Buggy under Opal?
67
+ class RSpec::Mocks::MethodDouble
68
+ def save_original_method!
69
+ @original_method ||= @method_stasher.original_method
70
+ end
71
+ end
72
+
73
+ # Missing on vendored rspec version
74
+ module RSpec
75
+ module Core
76
+ module MemoizedHelpers
77
+ def is_expected
78
+ expect(subject)
79
+ end
80
+ end
81
+ end
82
+ end
83
+
84
+ RSpec::Core::Formatters::DeprecationFormatter::GeneratedDeprecationMessage.class_eval do
85
+ def to_s
86
+ msg = "#{@data[:deprecated]} is deprecated."
87
+ msg += " Use #{@data[:replacement]} instead." if @data[:replacement]
88
+ msg += " Called from #{@data[:call_site]}." if @data[:call_site]
89
+ msg
90
+ end
91
+
92
+ def too_many_warnings_message
93
+ msg = "Too many uses of deprecated '#{type}'."
94
+ msg += " Set config.deprecation_stream to a File for full output."
95
+ msg
96
+ end
97
+ end
98
+
99
+ def (RSpec::Expectations).fail_with(message, expected=nil, actual=nil)
100
+ if !message
101
+ raise ArgumentError, "Failure message is nil. Does your matcher define the " +
102
+ "appropriate failure_message_for_* method to return a string?"
103
+ end
104
+
105
+ if actual && expected
106
+ if all_strings?(actual, expected)
107
+ if any_multiline_strings?(actual, expected)
108
+ message # + "\nDiff:" + differ.diff_as_string(coerce_to_string(actual), coerce_to_string(expected))
109
+ end
110
+ elsif no_procs?(actual, expected) && no_numbers?(actual, expected)
111
+ message # + "\nDiff:" + differ.diff_as_object(actual, expected)
112
+ end
113
+ end
114
+
115
+ raise(RSpec::Expectations::ExpectationNotMetError.new(message))
116
+ end
@@ -0,0 +1,45 @@
1
+ require 'corelib/dir'
2
+ require 'thread'
3
+
4
+ require 'set'
5
+ require 'time'
6
+ require 'rbconfig'
7
+ require 'pathname'
8
+
9
+ # TODO: still needed? meh..
10
+ require 'rspec/core/version'
11
+ require 'rspec/core/flat_map'
12
+ require 'rspec/core/filter_manager'
13
+ require 'rspec/core/dsl'
14
+ require 'rspec/core/reporter'
15
+ require 'rspec/core/hooks'
16
+ require 'rspec/core/memoized_helpers'
17
+ require 'rspec/core/metadata'
18
+ require 'rspec/core/pending'
19
+ require 'rspec/core/formatters'
20
+ require 'rspec/core/ordering'
21
+ require 'rspec/core/world'
22
+ require 'rspec/core/configuration'
23
+ require 'rspec/core/option_parser'
24
+ require 'rspec/core/configuration_options'
25
+ require 'rspec/core/command_line'
26
+ require 'rspec/core/runner'
27
+ require 'rspec/core/example'
28
+ require 'rspec/core/shared_example_group/collection'
29
+ require 'rspec/core/shared_example_group'
30
+ require 'rspec/core/example_group'
31
+
32
+ require 'rspec/core/mocking/with_rspec'
33
+
34
+ require 'rspec/support'
35
+ require 'rspec/core'
36
+ require 'rspec/expectations'
37
+ require 'rspec/mocks'
38
+ require 'rspec'
39
+
40
+ # FIXME: still needed?
41
+ require 'rspec/core/formatters/base_text_formatter'
42
+ require 'rspec/core/formatters/html_printer'
43
+ require 'rspec/matchers/pretty'
44
+ require 'rspec/matchers/built_in/base_matcher'
45
+ require 'rspec/matchers/built_in/be'
@@ -0,0 +1,69 @@
1
+ module Opal
2
+ module RSpec
3
+ class Runner
4
+
5
+ class << self
6
+ def browser?
7
+ `typeof(document) !== "undefined"`
8
+ end
9
+
10
+ def phantom?
11
+ `typeof(phantom) !== 'undefined' || typeof(OPAL_SPEC_PHANTOM) !== 'undefined'`
12
+ end
13
+
14
+ def default_formatter
15
+ if phantom?
16
+ TextFormatter
17
+ else # browser
18
+ BrowserFormatter
19
+ end
20
+ end
21
+
22
+ def autorun
23
+ if browser?
24
+ `setTimeout(function() { #{Runner.new.run} }, 0)`
25
+ else # phantom
26
+ Runner.new.run
27
+ end
28
+ end
29
+ end
30
+
31
+ def initialize(options = {})
32
+ @options = options
33
+ @world = ::RSpec.world
34
+ @configuration = ::RSpec.configuration
35
+ end
36
+
37
+ def run(err=$stdout, out=$stdout)
38
+ @configuration.error_stream = err
39
+ @configuration.output_stream ||= out
40
+
41
+ self.start
42
+ run_examples
43
+
44
+ run_async_examples do
45
+ self.finish
46
+ end
47
+ end
48
+
49
+ def run_examples
50
+ @world.example_groups.map { |g| g.run(@reporter) }.all?
51
+ end
52
+
53
+ def run_async_examples(&block)
54
+ AsyncRunner.new(self, @reporter, block).run
55
+ end
56
+
57
+ def start
58
+ @reporter = @configuration.reporter
59
+ @reporter.start(@world.example_count)
60
+ @configuration.run_hook(:before, :suite)
61
+ end
62
+
63
+ def finish
64
+ @configuration.run_hook(:after, :suite)
65
+ @reporter.finish
66
+ end
67
+ end
68
+ end
69
+ end
@@ -0,0 +1,11 @@
1
+ # This file is used by Opal::Server to basically load all spec files that
2
+ # can be found in the spec/ directory.
3
+
4
+ require 'opal'
5
+ require 'opal-rspec'
6
+
7
+ <% Dir.glob('spec/**/*_spec.{rb,opal}').each do |s| %>
8
+ require <%= s.sub(/^spec\//, '').sub(/\.(rb|opal)$/, '').inspect %>
9
+ <% end %>
10
+
11
+ Opal::RSpec::Runner.autorun
@@ -0,0 +1,74 @@
1
+ module Opal
2
+ module RSpec
3
+ class TextFormatter < ::RSpec::Core::Formatters::BaseFormatter
4
+
5
+ def dump_failures
6
+ if failed_examples.empty?
7
+ puts "\nFinished"
8
+ else
9
+ puts "\nFailures:"
10
+ failed_examples.each_with_index do |example, index|
11
+ puts "\n"
12
+ dump_failure(example, index)
13
+ end
14
+ end
15
+ end
16
+
17
+ def dump_failure(example, index)
18
+ puts "#{short_padding}#{index.next}) #{example.full_description}"
19
+ dump_failure_info(example)
20
+ end
21
+
22
+ def dump_failure_info(example)
23
+ exception = example.execution_result[:exception]
24
+ exception_class_name = exception.class.name.to_s
25
+ red "#{long_padding}#{exception_class_name}:"
26
+ exception.message.to_s.split("\n").each { |line| red "#{long_padding} #{line}" }
27
+ end
28
+
29
+ def dump_summary(duration, example_count, failure_count, pending_count)
30
+ @duration = duration
31
+ @example_count = example_count
32
+ @failure_count = failure_count
33
+ @pending_count = pending_count
34
+
35
+ msg = "\n#{example_count} examples, #{failure_count} failures (time taken: #{duration})"
36
+
37
+ if failure_count == 0
38
+ green msg
39
+ finish_with_code(0)
40
+ else
41
+ red msg
42
+ finish_with_code(1)
43
+ end
44
+ end
45
+
46
+ def finish_with_code(code)
47
+ %x{
48
+ if (typeof(phantom) !== "undefined") {
49
+ phantom.exit(code);
50
+ }
51
+ else {
52
+ Opal.global.OPAL_SPEC_CODE = code;
53
+ }
54
+ }
55
+ end
56
+
57
+ def green(str)
58
+ `console.log('\033[32m' + str + '\033[0m')`
59
+ end
60
+
61
+ def red(str)
62
+ `console.log('\033[31m' + str + '\033[0m')`
63
+ end
64
+
65
+ def short_padding
66
+ ' '
67
+ end
68
+
69
+ def long_padding
70
+ ' '
71
+ end
72
+ end
73
+ end
74
+ end
@@ -0,0 +1,38 @@
1
+ describe "Asynchronous helpers" do
2
+ let(:foo) { 100 }
3
+
4
+ before do
5
+ @model = Object.new
6
+ end
7
+
8
+ async "can run examples async" do
9
+ async do
10
+ 1.should == 1
11
+ end
12
+ end
13
+
14
+ async "can access let() helpers and before() helpers" do
15
+ async do
16
+ foo.should eq(100)
17
+ @model.should be_kind_of(Object)
18
+ end
19
+ end
20
+
21
+ async "can finish running after a long delay" do
22
+ obj = [1, 2, 3, 4]
23
+
24
+ delay(1) do
25
+ async { obj.should == [1, 2, 3, 4] }
26
+ end
27
+ end
28
+
29
+ async "should make example fail before async block reached" do
30
+ expect {
31
+ expect(:foo).to eq(:baz)
32
+ }.to raise_error(Exception)
33
+
34
+ delay(0) do
35
+ async { expect(42).to eq(42) }
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,163 @@
1
+ module SomeHelpers
2
+ def opal_rspec_helper
3
+ let(:defined_opal_helper) { :it_works }
4
+ end
5
+ end
6
+
7
+ module SomeMoreHelpers
8
+ def opal_rspec_include_helper
9
+ 42
10
+ end
11
+ end
12
+
13
+ RSpec.configure do |c|
14
+ c.extend SomeHelpers
15
+ c.include SomeMoreHelpers
16
+ end
17
+
18
+ describe "RSpec include and extend" do
19
+ opal_rspec_helper
20
+
21
+ it "works for extend" do
22
+ defined_opal_helper.should == :it_works
23
+ end
24
+
25
+ it "works for include" do
26
+ opal_rspec_include_helper.should == 42
27
+ end
28
+ end
29
+
30
+ $count = 0
31
+
32
+ describe "let" do
33
+ let(:count) { $count += 1 }
34
+
35
+ it "memoizes the value" do
36
+ count.should eq(1)
37
+ count.should eq(1)
38
+ end
39
+
40
+ it "is not cached across examples" do
41
+ count.should eq(2)
42
+ end
43
+ end
44
+
45
+ describe "helper methods" do
46
+ def some_helper
47
+ :present
48
+ end
49
+
50
+ it "should be available" do
51
+ some_helper.should eq(:present)
52
+ end
53
+
54
+ describe "nested group" do
55
+ it "should work in nested groups" do
56
+ some_helper.should eq(:present)
57
+ end
58
+ end
59
+ end
60
+
61
+ describe "nested describes" do
62
+ it "works in multiple places" do
63
+ 1.should eq(1)
64
+ end
65
+
66
+ describe "nested" do
67
+ it "and here" do
68
+ 1.should_not eq(2)
69
+ end
70
+ end
71
+ end
72
+
73
+ describe "subject" do
74
+ subject { [1, 2, 3] }
75
+
76
+ it "a new instance should be the subject" do
77
+ subject.should be_kind_of(Array)
78
+ end
79
+
80
+ describe "nested subjects" do
81
+ before { subject << 4 }
82
+
83
+ it "should work with before and example" do
84
+ subject.should == [1, 2, 3, 4]
85
+ end
86
+ end
87
+ end
88
+
89
+ describe Hash do
90
+ it "should create a new instance of subject for classes" do
91
+ subject.should == {}
92
+ end
93
+
94
+ it "provides the subject as the described_class" do
95
+ expect(described_class).to eq(Hash)
96
+ end
97
+ end
98
+
99
+ describe [1, 2, 3] do
100
+ it "can use an object instance as a subject" do
101
+ expect(subject).to eq([1, 2, 3])
102
+ end
103
+ end
104
+
105
+ describe "Simple expectations" do
106
+ before do
107
+ @bar = 200
108
+ end
109
+
110
+ it "should eat" do
111
+ @bar.should == 200
112
+ end
113
+
114
+ after do
115
+ @bar.class
116
+ end
117
+ end
118
+
119
+ describe "should syntax" do
120
+ it "should work for positive" do
121
+ [1, 2, 3].should == [1, 2, 3]
122
+ end
123
+
124
+ it "should work for negative" do
125
+ [1, 2, 3].should_not == [4, 5, 6]
126
+ end
127
+ end
128
+
129
+ describe "expect syntax" do
130
+ it "positive expectation" do
131
+ expect(100).to eq(100)
132
+ end
133
+
134
+ it "negative expectation" do
135
+ expect(100).to_not eq(300)
136
+ end
137
+ end
138
+
139
+ describe "Normal errors" do
140
+ it "should still work" do
141
+ lambda { raise "wtf son" }.should raise_error(Exception)
142
+ end
143
+ end
144
+
145
+ describe "let on an inner scope" do
146
+ describe "inner context" do
147
+ let(:foo) { :bar }
148
+
149
+ it "should still work" do
150
+ foo.should eq(:bar)
151
+ end
152
+ end
153
+ end
154
+
155
+ describe "#context" do
156
+ context "inner context" do
157
+ let(:foo) { :bar }
158
+
159
+ it "should still work" do
160
+ foo.should eq(:bar)
161
+ end
162
+ end
163
+ end