diff --git a/Rakefile b/Rakefile index 6c35c1b..93a2268 100644 --- a/Rakefile +++ b/Rakefile @@ -2,12 +2,12 @@ require 'bundler' Bundler.require Bundler::GemHelper.install_tasks -require 'opal/spec/rake_task' -Opal::Spec::RakeTask.new(:default) do |s| +require 'opal/rspec/rake_task' +Opal::RSpec::RakeTask.new(:default) do |s| s.index_path = 'spec/jquery/index.html' end -Opal::Spec::RakeTask.new(:zepto) do |s| +Opal::RSpec::RakeTask.new(:zepto) do |s| s.index_path = 'spec/zepto/index.html' end diff --git a/config.ru b/config.ru index c64db0e..fafe9db 100644 --- a/config.ru +++ b/config.ru @@ -2,7 +2,7 @@ require 'bundler' Bundler.require run Opal::Server.new { |s| - s.main = 'opal/spec/sprockets_runner' + s.main = 'opal/rspec/sprockets_runner' s.append_path 'spec' s.debug = false s.index_path = 'spec/jquery/index.html' diff --git a/opal-jquery.gemspec b/opal-jquery.gemspec index f84e56e..fd2953b 100644 --- a/opal-jquery.gemspec +++ b/opal-jquery.gemspec @@ -16,5 +16,5 @@ Gem::Specification.new do |s| s.require_paths = ['lib'] s.add_runtime_dependency 'opal', '~> 0.5.0' - s.add_development_dependency 'opal-spec', '~> 0.3.0' + s.add_development_dependency 'opal-rspec' end diff --git a/opal/opal-jquery/element.rb b/opal/opal-jquery/element.rb index 4374265..8383937 100644 --- a/opal/opal-jquery/element.rb +++ b/opal/opal-jquery/element.rb @@ -1,22 +1,18 @@ -class Element - %x{ - var root = $opal.global, dom_class; +%x{ + var root = $opal.global, dom_class; - if (root.jQuery) { - dom_class = jQuery - } - else if (root.Zepto) { - dom_class = Zepto.zepto.Z; - } - else { - throw new Error("jQuery must be included before opal-jquery"); - } - - self._proto = dom_class.prototype, def = self._proto; - dom_class.prototype._klass = self; + if (root.jQuery) { + dom_class = jQuery + } + else if (root.Zepto) { + dom_class = Zepto.zepto.Z; + } + else { + throw new Error("jQuery must be included before opal-jquery"); } +} - include Kernel +class Element < `dom_class` include Enumerable def self.find(selector) diff --git a/spec/element/animations_spec.rb b/spec/element/animations_spec.rb index ede23ca..307a575 100644 --- a/spec/element/animations_spec.rb +++ b/spec/element/animations_spec.rb @@ -9,33 +9,37 @@ ### HACKY # jQUery's animate method doesn't *always* finish on time # so the values are being compared using greater than - + it "should animate a set of properties and values" do foo = Element.find "#animate-foo" foo.animate :width => "200px" set_timeout 400 do - (foo.css("width").to_f > 199).should be_true + (foo.css("width").to_f > 199).should eq(true) end end - it "should allow you to set a speed in the params" do + async "should allow you to set a speed in the params" do foo = Element.find "#animate-foo" foo.animate :width => "200px", :speed => 100 set_timeout 105 do - (foo.css("width").to_f > 199).should be_true + run_async { + (foo.css("width").to_f > 199).should eq(true) + } end end - it "should accept a block as a callback" do + async "should accept a block as a callback" do foo = Element.find "#animate-foo" - foo.animate :width => "200px" do + foo.animate :width => "200px", :speed => 100 do foo.add_class "finished" end set_timeout 405 do - foo.class_name.should equal("finished") + run_async { + foo.class_name.should eq("finished") + } end end end diff --git a/spec/element/attributes_spec.rb b/spec/element/attributes_spec.rb index 31bc13b..ef919ff 100644 --- a/spec/element/attributes_spec.rb +++ b/spec/element/attributes_spec.rb @@ -72,14 +72,14 @@ describe "#add_class" do it "should add the given class name to the element" do foo = Element.find '#foo' - foo.has_class?('lemons').should be_false + foo.has_class?('lemons').should eq(false) foo.add_class 'lemons' - foo.has_class?('lemons').should be_true + foo.has_class?('lemons').should eq(true) end it "should not duplicate class names on an element" do bar = Element.find '#bar' - bar.has_class?('apples').should be_true + bar.has_class?('apples').should eq(true) bar.add_class 'apples' bar.class_name.should == 'apples' end @@ -93,9 +93,9 @@ describe '#has_class?' do it "should return true if the element has the given class" do - Element.find('#has-foo').has_class?("apples").should be_true - Element.find('#has-foo').has_class?("oranges").should be_false - Element.find('#has-bar').has_class?("lemons").should be_true + Element.find('#has-foo').has_class?("apples").should eq(true) + Element.find('#has-foo').has_class?("oranges").should eq(false) + Element.find('#has-bar').has_class?("lemons").should eq(true) end end @@ -152,16 +152,16 @@ describe '#toggle_class' do it 'adds the given class name to the element if not already present' do foo = Element.find('#foo') - foo.has_class?('oranges').should be_false + foo.has_class?('oranges').should eq(false) foo.toggle_class 'oranges' - foo.has_class?('oranges').should be_true + foo.has_class?('oranges').should eq(true) end it 'removes the class if the element already has it' do bar = Element.find('#bar') - bar.has_class?('apples').should be_true + bar.has_class?('apples').should eq(true) bar.toggle_class 'apples' - bar.has_class?('apples').should be_false + bar.has_class?('apples').should eq(false) end end diff --git a/spec/element/method_missing_spec.rb b/spec/element/method_missing_spec.rb index d94e490..c48fa40 100644 --- a/spec/element/method_missing_spec.rb +++ b/spec/element/method_missing_spec.rb @@ -25,8 +25,8 @@ class Element end it "only forwards calls when a native method exists" do - lambda { + expect { Element.new.some_unknown_plugin - }.should raise_error(NoMethodError) + }.to raise_error(Exception) end end diff --git a/spec/http_spec.rb b/spec/http_spec.rb index a70083c..47ca07c 100644 --- a/spec/http_spec.rb +++ b/spec/http_spec.rb @@ -13,7 +13,7 @@ async 'can add a success callback after the request is sent' do http = HTTP.get('spec/fixtures/simple.txt') http.callback do |response| - run_async { response.ok?.should be_true } + run_async { response.should be_ok } end end end @@ -22,7 +22,7 @@ async 'can add a failure callback after the request is sent' do http = HTTP.get('spec/fixtures/bad_url.txt') http.errback do |response| - run_async { response.ok?.should be_false } + run_async { response.should_not be_ok } end end end @@ -38,13 +38,13 @@ describe '#ok?' do async 'returns true when the request was a sucess' do HTTP.get('spec/fixtures/simple.txt') do |response| - run_async { response.ok?.should be_true } + run_async { response.should be_ok } end end async 'returns false when the request failed' do HTTP.get('spec/fixtures/non_existant.txt') do |response| - run_async { response.ok?.should be_false } + run_async { response.should_not be_ok } end end end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index fe09b18..8852a53 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,4 +1,4 @@ -require 'opal-spec' +require 'opal-rspec' require 'opal-jquery' module JqueryHelpers @@ -30,6 +30,6 @@ def html(html_string='') end end -class OpalSpec::Example - extend JqueryHelpers +RSpec.configure do |config| + config.extend JqueryHelpers end