Skip to content

Commit

Permalink
Use rspec for running specs
Browse files Browse the repository at this point in the history
adambeynon committed Nov 4, 2013

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
1 parent 720dd53 commit d28df35
Showing 9 changed files with 47 additions and 47 deletions.
6 changes: 3 additions & 3 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -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

2 changes: 1 addition & 1 deletion config.ru
Original file line number Diff line number Diff line change
@@ -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'
2 changes: 1 addition & 1 deletion opal-jquery.gemspec
Original file line number Diff line number Diff line change
@@ -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
28 changes: 12 additions & 16 deletions opal/opal-jquery/element.rb
Original file line number Diff line number Diff line change
@@ -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)
18 changes: 11 additions & 7 deletions spec/element/animations_spec.rb
Original file line number Diff line number Diff line change
@@ -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
20 changes: 10 additions & 10 deletions spec/element/attributes_spec.rb
Original file line number Diff line number Diff line change
@@ -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

4 changes: 2 additions & 2 deletions spec/element/method_missing_spec.rb
Original file line number Diff line number Diff line change
@@ -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
8 changes: 4 additions & 4 deletions spec/http_spec.rb
Original file line number Diff line number Diff line change
@@ -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
6 changes: 3 additions & 3 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit d28df35

Please sign in to comment.