Skip to content

Commit a190d22

Browse files
committedOct 15, 2014
Add simple #expect method to example groups
1 parent 0c222e3 commit a190d22

File tree

8 files changed

+35
-9
lines changed

8 files changed

+35
-9
lines changed
 

‎Gemfile

+2
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
source 'https://rubygems.org'
22
gemspec
3+
4+
gem 'opal', :github => 'opal/opal'

‎lib/opal/spec/rake_task.rb

-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
require 'opal/spec'
2-
require 'opal-sprockets'
32

43
module Opal
54
module Spec

‎opal-spec.gemspec

+1-2
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@ Gem::Specification.new do |s|
1313
s.files = `git ls-files`.split("\n")
1414
s.require_paths = ['lib']
1515

16-
s.add_dependency 'opal', '~> 0.5.0'
17-
s.add_dependency 'opal-sprockets', '~> 0.3.0'
16+
s.add_dependency 'opal', '~> 0.7.0.beta1'
1817

1918
s.add_development_dependency 'rake'
2019
end

‎opal/opal/spec/phantom_formatter.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@ def initialize
66
end
77

88
def log_green(str)
9-
`console.log('\\033[32m' + str + '\\033[0m')`
9+
`console.log('\033[32m' + str + '\033[0m')`
1010
end
1111

1212
def log_red(str)
13-
`console.log('\\033[31m' + str + '\\033[0m')`
13+
`console.log('\033[31m' + str + '\033[0m')`
1414
end
1515

1616
def log(str)

‎opal/opal/spec/runner.rb

-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
module OpalSpec
22
class Runner
33
def self.in_browser?
4-
$global[:document]
54
`typeof(document) !== 'undefined'`
65
end
76

‎opal/opal/spec/spec.rb

+18
Original file line numberDiff line numberDiff line change
@@ -181,5 +181,23 @@ def set_timeout(duration, &block)
181181
`setTimeout(#{block}, #{duration})`
182182
self
183183
end
184+
185+
def expect(value)
186+
ExpectTarget.new(value)
187+
end
188+
end
189+
190+
class ExpectTarget
191+
def initialize(value)
192+
@value = value
193+
end
194+
195+
def to(*args)
196+
@value.should(*args)
197+
end
198+
199+
def to_not(*args)
200+
@value.should_not(*args)
201+
end
184202
end
185203
end
+3-3
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
# This file is used by Opal::Server to basically load all spec files that
22
# can be found in the spec/ directory.
33

4-
<% require_asset 'opal' %>
5-
<% require_asset 'opal-spec' %>
4+
require 'opal'
5+
require 'opal-spec'
66

77
<% Dir.glob('spec/**/*_spec.{rb,opal}').each do |s| %>
8-
<% require_asset s.sub(/^spec\//, '').sub(/\.(rb|opal)$/, '') %>
8+
require <%= s.sub(/^spec\//, '').sub(/\.(rb|opal)$/, '').inspect %>
99
<% end %>
1010

1111
OpalSpec::Runner.autorun

‎spec/expect_spec.rb

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
describe '#expect' do
2+
it 'works with simple matchers' do
3+
expect(1).to eq(1)
4+
end
5+
6+
it 'works with simple to_not matchers' do
7+
expect(1).to_not eq(2)
8+
end
9+
end

0 commit comments

Comments
 (0)
Please sign in to comment.