Skip to content

Commit d28df35

Browse files
committedNov 4, 2013
Use rspec for running specs
1 parent 720dd53 commit d28df35

File tree

9 files changed

+47
-47
lines changed

9 files changed

+47
-47
lines changed
 

‎Rakefile

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@ require 'bundler'
22
Bundler.require
33
Bundler::GemHelper.install_tasks
44

5-
require 'opal/spec/rake_task'
6-
Opal::Spec::RakeTask.new(:default) do |s|
5+
require 'opal/rspec/rake_task'
6+
Opal::RSpec::RakeTask.new(:default) do |s|
77
s.index_path = 'spec/jquery/index.html'
88
end
99

10-
Opal::Spec::RakeTask.new(:zepto) do |s|
10+
Opal::RSpec::RakeTask.new(:zepto) do |s|
1111
s.index_path = 'spec/zepto/index.html'
1212
end
1313

‎config.ru

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ require 'bundler'
22
Bundler.require
33

44
run Opal::Server.new { |s|
5-
s.main = 'opal/spec/sprockets_runner'
5+
s.main = 'opal/rspec/sprockets_runner'
66
s.append_path 'spec'
77
s.debug = false
88
s.index_path = 'spec/jquery/index.html'

‎opal-jquery.gemspec

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,5 @@ Gem::Specification.new do |s|
1616
s.require_paths = ['lib']
1717

1818
s.add_runtime_dependency 'opal', '~> 0.5.0'
19-
s.add_development_dependency 'opal-spec', '~> 0.3.0'
19+
s.add_development_dependency 'opal-rspec'
2020
end

‎opal/opal-jquery/element.rb

+12-16
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,18 @@
1-
class Element
2-
%x{
3-
var root = $opal.global, dom_class;
1+
%x{
2+
var root = $opal.global, dom_class;
43
5-
if (root.jQuery) {
6-
dom_class = jQuery
7-
}
8-
else if (root.Zepto) {
9-
dom_class = Zepto.zepto.Z;
10-
}
11-
else {
12-
throw new Error("jQuery must be included before opal-jquery");
13-
}
14-
15-
self._proto = dom_class.prototype, def = self._proto;
16-
dom_class.prototype._klass = self;
4+
if (root.jQuery) {
5+
dom_class = jQuery
6+
}
7+
else if (root.Zepto) {
8+
dom_class = Zepto.zepto.Z;
9+
}
10+
else {
11+
throw new Error("jQuery must be included before opal-jquery");
1712
}
13+
}
1814

19-
include Kernel
15+
class Element < `dom_class`
2016
include Enumerable
2117

2218
def self.find(selector)

‎spec/element/animations_spec.rb

+11-7
Original file line numberDiff line numberDiff line change
@@ -9,33 +9,37 @@
99
### HACKY
1010
# jQUery's animate method doesn't *always* finish on time
1111
# so the values are being compared using greater than
12-
12+
1313
it "should animate a set of properties and values" do
1414
foo = Element.find "#animate-foo"
1515
foo.animate :width => "200px"
1616

1717
set_timeout 400 do
18-
(foo.css("width").to_f > 199).should be_true
18+
(foo.css("width").to_f > 199).should eq(true)
1919
end
2020
end
2121

22-
it "should allow you to set a speed in the params" do
22+
async "should allow you to set a speed in the params" do
2323
foo = Element.find "#animate-foo"
2424
foo.animate :width => "200px", :speed => 100
2525

2626
set_timeout 105 do
27-
(foo.css("width").to_f > 199).should be_true
27+
run_async {
28+
(foo.css("width").to_f > 199).should eq(true)
29+
}
2830
end
2931
end
3032

31-
it "should accept a block as a callback" do
33+
async "should accept a block as a callback" do
3234
foo = Element.find "#animate-foo"
33-
foo.animate :width => "200px" do
35+
foo.animate :width => "200px", :speed => 100 do
3436
foo.add_class "finished"
3537
end
3638

3739
set_timeout 405 do
38-
foo.class_name.should equal("finished")
40+
run_async {
41+
foo.class_name.should eq("finished")
42+
}
3943
end
4044
end
4145
end

‎spec/element/attributes_spec.rb

+10-10
Original file line numberDiff line numberDiff line change
@@ -72,14 +72,14 @@
7272
describe "#add_class" do
7373
it "should add the given class name to the element" do
7474
foo = Element.find '#foo'
75-
foo.has_class?('lemons').should be_false
75+
foo.has_class?('lemons').should eq(false)
7676
foo.add_class 'lemons'
77-
foo.has_class?('lemons').should be_true
77+
foo.has_class?('lemons').should eq(true)
7878
end
7979

8080
it "should not duplicate class names on an element" do
8181
bar = Element.find '#bar'
82-
bar.has_class?('apples').should be_true
82+
bar.has_class?('apples').should eq(true)
8383
bar.add_class 'apples'
8484
bar.class_name.should == 'apples'
8585
end
@@ -93,9 +93,9 @@
9393

9494
describe '#has_class?' do
9595
it "should return true if the element has the given class" do
96-
Element.find('#has-foo').has_class?("apples").should be_true
97-
Element.find('#has-foo').has_class?("oranges").should be_false
98-
Element.find('#has-bar').has_class?("lemons").should be_true
96+
Element.find('#has-foo').has_class?("apples").should eq(true)
97+
Element.find('#has-foo').has_class?("oranges").should eq(false)
98+
Element.find('#has-bar').has_class?("lemons").should eq(true)
9999
end
100100
end
101101

@@ -152,16 +152,16 @@
152152
describe '#toggle_class' do
153153
it 'adds the given class name to the element if not already present' do
154154
foo = Element.find('#foo')
155-
foo.has_class?('oranges').should be_false
155+
foo.has_class?('oranges').should eq(false)
156156
foo.toggle_class 'oranges'
157-
foo.has_class?('oranges').should be_true
157+
foo.has_class?('oranges').should eq(true)
158158
end
159159

160160
it 'removes the class if the element already has it' do
161161
bar = Element.find('#bar')
162-
bar.has_class?('apples').should be_true
162+
bar.has_class?('apples').should eq(true)
163163
bar.toggle_class 'apples'
164-
bar.has_class?('apples').should be_false
164+
bar.has_class?('apples').should eq(false)
165165
end
166166
end
167167

‎spec/element/method_missing_spec.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ class Element
2525
end
2626

2727
it "only forwards calls when a native method exists" do
28-
lambda {
28+
expect {
2929
Element.new.some_unknown_plugin
30-
}.should raise_error(NoMethodError)
30+
}.to raise_error(Exception)
3131
end
3232
end

‎spec/http_spec.rb

+4-4
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
async 'can add a success callback after the request is sent' do
1414
http = HTTP.get('spec/fixtures/simple.txt')
1515
http.callback do |response|
16-
run_async { response.ok?.should be_true }
16+
run_async { response.should be_ok }
1717
end
1818
end
1919
end
@@ -22,7 +22,7 @@
2222
async 'can add a failure callback after the request is sent' do
2323
http = HTTP.get('spec/fixtures/bad_url.txt')
2424
http.errback do |response|
25-
run_async { response.ok?.should be_false }
25+
run_async { response.should_not be_ok }
2626
end
2727
end
2828
end
@@ -38,13 +38,13 @@
3838
describe '#ok?' do
3939
async 'returns true when the request was a sucess' do
4040
HTTP.get('spec/fixtures/simple.txt') do |response|
41-
run_async { response.ok?.should be_true }
41+
run_async { response.should be_ok }
4242
end
4343
end
4444

4545
async 'returns false when the request failed' do
4646
HTTP.get('spec/fixtures/non_existant.txt') do |response|
47-
run_async { response.ok?.should be_false }
47+
run_async { response.should_not be_ok }
4848
end
4949
end
5050
end

‎spec/spec_helper.rb

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
require 'opal-spec'
1+
require 'opal-rspec'
22
require 'opal-jquery'
33

44
module JqueryHelpers
@@ -30,6 +30,6 @@ def html(html_string='')
3030
end
3131
end
3232

33-
class OpalSpec::Example
34-
extend JqueryHelpers
33+
RSpec.configure do |config|
34+
config.extend JqueryHelpers
3535
end

0 commit comments

Comments
 (0)
Please sign in to comment.