Skip to content

Commit

Permalink
Update specs ready for rspec
Browse files Browse the repository at this point in the history
  • Loading branch information
adambeynon committed Nov 1, 2013
1 parent 7bde6f1 commit 60de215
Show file tree
Hide file tree
Showing 8 changed files with 44 additions and 30 deletions.
4 changes: 4 additions & 0 deletions .travis.yml
Expand Up @@ -3,3 +3,7 @@ language: ruby
rvm:
- 1.8.7
- 1.9.3

branches:
except:
- rspec
2 changes: 1 addition & 1 deletion Gemfile
Expand Up @@ -4,4 +4,4 @@ gemspec
gem 'rake'
gem 'opal', :github => 'opal/opal'
gem 'opal-sprockets', :github => 'opal/opal-sprockets'
gem 'opal-spec', :github => 'opal/opal-spec'
gem 'opal-rspec', :path => '../opal-rspec'
6 changes: 3 additions & 3 deletions Rakefile
Expand Up @@ -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

Expand Down
18 changes: 11 additions & 7 deletions spec/element/animations_spec.rb
Expand Up @@ -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
Expand Down
20 changes: 10 additions & 10 deletions spec/element/attributes_spec.rb
Expand Up @@ -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
Expand All @@ -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

Expand Down Expand Up @@ -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

Expand Down
4 changes: 2 additions & 2 deletions spec/element/method_missing_spec.rb
Expand Up @@ -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
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
12 changes: 9 additions & 3 deletions spec/spec_helper.rb
@@ -1,6 +1,12 @@
require 'opal-spec'
require 'opal-rspec'
require 'opal-jquery'

# FIXME: wtf? why isnt Element getting should and should_not
class Element
`def.$should = $opal.top.$should`
`def.$should_not = $opal.top.$should_not`
end

module JqueryHelpers
# Add some html code to the body tag ready for testing. This will
# be added before each test, then removed after each test. It is
Expand Down Expand Up @@ -30,6 +36,6 @@ def html(html_string='')
end
end

class OpalSpec::Example
extend JqueryHelpers
RSpec.configure do |config|
config.extend JqueryHelpers
end

0 comments on commit 60de215

Please sign in to comment.