diff --git a/.gitignore b/.gitignore index b76786e..1411ac3 100644 --- a/.gitignore +++ b/.gitignore @@ -6,3 +6,4 @@ gh-pages /.bundle .yardoc /doc +/tmp diff --git a/.rspec b/.rspec new file mode 100644 index 0000000..c99d2e7 --- /dev/null +++ b/.rspec @@ -0,0 +1 @@ +--require spec_helper diff --git a/.travis.yml b/.travis.yml index e1422d4..f688971 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,39 +1,23 @@ language: ruby + sudo: false fast_finish: true -script: bundle exec rake $RUN - -matrix: - include: - - rvm: 2.4.2 - env: OPAL_VERSION='master' - - rvm: 2.3.4 - env: OPAL_VERSION='~> 0.10.5' - - rvm: 2.1.10 - env: RACK_VERSION='< 2.0' - - rvm: 2.0.0 - env: RACK_VERSION='< 2.0' - # We use 2.1.9 to differentiate the rvm version - # as travis doesn't allow failures by env. - - rvm: 2.1.9 - env: RUN=zepto PATH=".:$PATH" RACK_VERSION='< 2.0' +script: bundle exec rspec - allow_failures: - - rvm: 2.1.9 # zepto +rvm: + - 2.3 + - 2.4 + - 2.5 + - 2.6 +addons: + apt: + sources: + - google-chrome + packages: + - google-chrome-stable cache: bundler: true - directories: - - node_modules - -before_install: - - gem update --system - - "export PATH=$PWD/travis_phantomjs/phantomjs-2.1.1-linux-x86_64/bin:$PATH" - - "if [ $(phantomjs --version) != '2.1.1' ]; then rm -rf $PWD/travis_phantomjs; mkdir -p $PWD/travis_phantomjs; fi" - - "if [ $(phantomjs --version) != '2.1.1' ]; then wget https://assets.membergetmember.co/software/phantomjs-2.1.1-linux-x86_64.tar.bz2 -O $PWD/travis_phantomjs/phantomjs-2.1.1-linux-x86_64.tar.bz2; fi" - - "if [ $(phantomjs --version) != '2.1.1' ]; then tar -xvf $PWD/travis_phantomjs/phantomjs-2.1.1-linux-x86_64.tar.bz2 -C $PWD/travis_phantomjs; fi" - - "phantomjs --version" - diff --git a/Gemfile b/Gemfile index 22131a9..265f57c 100644 --- a/Gemfile +++ b/Gemfile @@ -1,6 +1,8 @@ source 'https://rubygems.org' gemspec +gem 'c_lexer', platform: :mri + case (opal_version = ENV['OPAL_VERSION']) when 'master' gem 'opal', github: 'opal/opal', branch: 'master' diff --git a/opal-jquery.gemspec b/opal-jquery.gemspec index 6d88826..165302e 100644 --- a/opal-jquery.gemspec +++ b/opal-jquery.gemspec @@ -15,9 +15,13 @@ Gem::Specification.new do |s| s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n") s.require_paths = ['lib'] - s.add_runtime_dependency 'opal', '>= 0.10.0', '< 0.12.0' - s.add_development_dependency 'opal-rspec', '~> 0.7.0.rc.2' + s.add_runtime_dependency 'opal', '~> 1.0' s.add_development_dependency 'opal-sprockets', '~> 0.4.1' s.add_development_dependency 'yard' s.add_development_dependency 'rake' + s.add_development_dependency 'puma' + s.add_development_dependency 'rspec' + s.add_development_dependency 'launchy' + s.add_development_dependency 'capybara' + s.add_development_dependency 'apparition' end diff --git a/spec-opal/jquery/index.html.erb b/spec-opal/jquery/index.html.erb deleted file mode 100644 index af1a377..0000000 --- a/spec-opal/jquery/index.html.erb +++ /dev/null @@ -1,10 +0,0 @@ - - -
- - - - <%= javascript_include_tag 'jquery/jquery-1.8.3' %> - <%= javascript_include_tag @server.main %> - - diff --git a/spec-opal/jquery/index3.html.erb b/spec-opal/jquery/index3.html.erb deleted file mode 100644 index 4c29382..0000000 --- a/spec-opal/jquery/index3.html.erb +++ /dev/null @@ -1,10 +0,0 @@ - - - - - - - <%= javascript_include_tag 'jquery/jquery-3.0.0' %> - <%= javascript_include_tag @server.main %> - - diff --git a/spec-opal/kernel_spec.rb b/spec-opal/kernel_spec.rb deleted file mode 100644 index 0052ee6..0000000 --- a/spec-opal/kernel_spec.rb +++ /dev/null @@ -1,15 +0,0 @@ -require 'spec_helper' - -RSpec.describe 'Kernel#alert' do - it 'returns nil' do - begin - original_alert = `window.alert` - message = nil - `window.alert = function(string) { message = string; }` - Kernel.alert('a message').should be_nil - expect(message).to eq('a message') - ensure - `window.alert = #{original_alert}` - end - end -end diff --git a/spec/examples.txt b/spec/examples.txt new file mode 100644 index 0000000..3538f78 --- /dev/null +++ b/spec/examples.txt @@ -0,0 +1,4 @@ +example_id | status | run_time | +-------------------------- | ------ | ------------ | +./spec/kernel_spec.rb[1:1] | passed | 2.99 seconds | +./spec/kernel_spec.rb[1:2] | passed | 2.57 seconds | diff --git a/spec/kernel_spec.rb b/spec/kernel_spec.rb new file mode 100644 index 0000000..dd0c1ab --- /dev/null +++ b/spec/kernel_spec.rb @@ -0,0 +1,14 @@ +require 'spec_helper' + +RSpec.describe 'Kernel#alert', type: :feature do + it 'returns nil' do + accept_alert do + expect(evaluate_opal(%{alert "message 1"})).to eq(opal_nil) + end + end + + it 'shows an alert' do + accept_alert("message 1") { execute_opal %{alert "message 1"} } + accept_alert("message 2") { execute_opal %{Kernel.alert "message 2"} } + end +end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb new file mode 100644 index 0000000..71974f7 --- /dev/null +++ b/spec/spec_helper.rb @@ -0,0 +1,25 @@ +require 'puma/minissl' # avoid warnings +require 'opal-jquery' +require 'support/capybara' + +RSpec.configure do |config| + config.expect_with :rspec do |expectations| + expectations.include_chain_clauses_in_custom_matcher_descriptions = true + end + + config.mock_with :rspec do |mocks| + mocks.verify_partial_doubles = true + end + + config.shared_context_metadata_behavior = :apply_to_host_groups + config.filter_run_when_matching :focus + config.example_status_persistence_file_path = "spec/examples.txt" + config.disable_monkey_patching! + config.warnings = true + config.default_formatter = "doc" if config.files_to_run.one? + config.profile_examples = 10 + config.order = :random + + Kernel.srand ENV['RSPEC_SEED'] || config.seed +end + diff --git a/spec/support/app/application-v1.rb b/spec/support/app/application-v1.rb new file mode 100644 index 0000000..d87156f --- /dev/null +++ b/spec/support/app/application-v1.rb @@ -0,0 +1,3 @@ +require 'opal' +require 'jquery-1.8.3.js' +require 'opal-jquery' diff --git a/spec/support/app/application-v3.rb b/spec/support/app/application-v3.rb new file mode 100644 index 0000000..272f3fa --- /dev/null +++ b/spec/support/app/application-v3.rb @@ -0,0 +1,3 @@ +require 'opal' +require 'jquery-3.0.0.js' +require 'opal-jquery' diff --git a/spec-opal/jquery/jquery-1.8.3.js b/spec/support/app/jquery-1.8.3.js similarity index 100% rename from spec-opal/jquery/jquery-1.8.3.js rename to spec/support/app/jquery-1.8.3.js diff --git a/spec-opal/jquery/jquery-3.0.0.js b/spec/support/app/jquery-3.0.0.js similarity index 100% rename from spec-opal/jquery/jquery-3.0.0.js rename to spec/support/app/jquery-3.0.0.js diff --git a/spec/support/capybara.rb b/spec/support/capybara.rb new file mode 100644 index 0000000..308cca1 --- /dev/null +++ b/spec/support/capybara.rb @@ -0,0 +1,52 @@ +require 'opal' +require 'capybara/rspec' +require 'opal/simple_server' + +Capybara.save_path = "#{Dir.pwd}/tmp/capybara" + +Opal.append_path "#{__dir__}/app" + +jquery_version = ENV['JQUERY_VERSION'] || '3' + +Capybara.app = Opal::SimpleServer.new { |s| + s.main = "application-v#{jquery_version}" +} + +require 'capybara/apparition' +Capybara.default_driver = :apparition +Capybara.javascript_driver = :apparition + +Capybara.register_server :puma do |app, port, host| + require 'rack/handler/puma' + Rack::Handler::Puma.run(app, Host: host, Port: port, Threads: "0:4", Silent: true) +end + +module OpalHelper + def compile_opal(code) + Opal.compile(code, requireable: false) + end + + def execute_opal(code) + execute_script compile_opal(code) + end + + def evaluate_opal(code) + # Remove the initial comment that prevents evaluate from worning + evaluate_script compile_opal(code).strip.lines[1..-1].join("\n") + end + + def opal_nil + @opal_nil ||= evaluate_opal 'nil' + end +end + +RSpec.configure do |config| + config.before(:each) do + visit '/' + sleep 0.05 until evaluate_script('document.readyState') == 'complete' + end + + config.include OpalHelper + config.include Capybara::DSL + config.include Capybara::RSpecMatchers +end