Skip to content

Commit

Permalink
Merge pull request #24 from opal/rspec-3-1-wip
Browse files Browse the repository at this point in the history
Bump RSpec to 3.1 (thanks to @wied03!)
elia committed Jul 27, 2015
2 parents d947fbb + 62119f7 commit 1ceeeb2
Showing 159 changed files with 422 additions and 16,471 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
## 0.5.0 (edge)

* Update to RSpec 3.1 (core is 3.1.7, expectations/support 3.1.2, mocks 3.1.3)

* Remove copy of source (and just rely on git submodule fetch)

## 0.4.3 (2015-06-14)

* Allow the gem to be run under Opal 0.7 and 0.8
7 changes: 7 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
source 'https://rubygems.org'
gemspec

unless Dir['rspec{,-{core,expectations,mocks,support}}'].any?
warn 'Run: "git submodule update --init" to get RSpec sources'
end

gem 'rspec', path: 'rspec'
gem 'rspec-support', path: 'rspec-support'
gem 'rspec-core', path: 'rspec-core'
gem 'rspec-mocks', path: 'rspec-mocks'
gem 'rspec-expectations', path: 'rspec-expectations'

# Opal 0.9 still in development
# gem 'opal', git: 'https://github.com/opal/opal.git'
21 changes: 4 additions & 17 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -6,21 +6,8 @@ Bundler::GemHelper.install_tasks
require 'opal/rspec/rake_task'
Opal::RSpec::RakeTask.new(:default)


require 'fileutils'
desc "Copy RSpec sources"
task :copy_rspec do
gems = %w(rspec rspec-core rspec-expectations rspec-mocks rspec-support)

gems.each do |gem|
spec = Gem::Specification.find_by_name gem
lib = File.join spec.gem_dir, 'lib'

Dir["#{lib}/**/*.rb"].each do |file|
out = file.sub(/^#{lib}\//, 'opal/')

FileUtils.mkdir_p File.dirname(out)
FileUtils.cp file, out
end
end
desc 'Generates an RSpec requires file free of dynamic requires'
task :generate_requires do
# Do this free of any requires used to make this Rake task happen
sh 'ruby -Irspec/lib -Irspec-core/lib/rspec -Irspec-support/lib/rspec util/create_requires.rb'
end
47 changes: 35 additions & 12 deletions lib/opal/rspec.rb
Original file line number Diff line number Diff line change
@@ -1,20 +1,43 @@
require 'opal'
require 'opal/rspec/version'
require 'opal/minitest'

# Just register our opal code path with opal build tools
Opal.append_path File.expand_path('../../../opal', __FILE__)
Opal.append_path File.expand_path('../../../vendor_lib', __FILE__)

# Catch our git submodule included directories
%w{rspec rspec-core rspec-expectations rspec-mocks rspec-support}.each do |gem|
Opal.append_path File.expand_path("../../../#{gem}/lib", __FILE__)
end

Opal::Processor.dynamic_require_severity = :warning

Opal::Processor.stub_file "rspec/matchers/built_in/have"
Opal::Processor.stub_file "diff/lcs"
Opal::Processor.stub_file "diff/lcs/hunk"
Opal::Processor.stub_file "fileutils"
Opal::Processor.stub_file "test/unit/assertions"
Opal::Processor.stub_file "coderay"
Opal::Processor.stub_file "optparse"
Opal::Processor.stub_file "shellwords"
Opal::Processor.stub_file "socket"
Opal::Processor.stub_file "uri"
Opal::Processor.stub_file "drb/drb"
stubs = [
'mutex_m', # Used with some threading operations but seems to run OK without this
'prettyprint',
'tempfile', # Doesn't exist in Opal
'diff/lcs',
'diff/lcs/block',
'diff/lcs/callbacks',
'diff/lcs/change',
'diff/lcs/hunk',
'diff/lcs/internals',
'test/unit/assertions',

# Opal doesn't have optparse, yet
'optparse',

'shellwords',
'socket',
'uri',
'drb/drb',

# Minitest used to be in stdlib, now is in opal-minitest GEM,
# but this file does not exist
# (referenced from minitest_assertions_adapter.rb in RSpec)
'minitest/unit',

'cgi/util',
]

stubs.each {|mod| Opal::Processor.stub_file mod }
7 changes: 5 additions & 2 deletions opal-rspec.gemspec
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# -*- encoding: utf-8 -*-
require 'rake'
require File.expand_path('../lib/opal/rspec/version', __FILE__)

Gem::Specification.new do |s|
@@ -10,11 +11,13 @@ Gem::Specification.new do |s|
s.summary = 'RSpec for Opal'
s.description = 'Opal compatible rspec library'

s.files = `git ls-files`.split("\n")
s.files = `git ls-files`.split("\n") + FileList['rspec*/**/*.rb']

s.require_paths = ['lib']

s.add_dependency 'opal', ['>= 0.7.0', '< 0.9']
s.add_dependency 'opal', ['>= 0.8.0.rc1', '< 0.9']
# Opal now does not include minitest but we need it for Sprockets/test execution
s.add_dependency 'opal-minitest', '~> 0.0'
s.add_development_dependency 'rake'
s.add_development_dependency 'yard'
end
9 changes: 2 additions & 7 deletions opal/opal/rspec.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
class MiniTest
class Unit; end
end

Test = MiniTest

require 'opal/rspec/pre_require_fixes'
require 'opal/rspec/requires'
require 'opal/rspec/fixes'
require 'opal/rspec/text_formatter'
@@ -13,7 +8,7 @@ class Unit; end

RSpec.configure do |config|
# For now, always use our custom formatter for results
config.formatter = Opal::RSpec::Runner.default_formatter
config.default_formatter = Opal::RSpec::Runner.default_formatter

# Async helpers for specs
config.include Opal::RSpec::AsyncHelpers
25 changes: 16 additions & 9 deletions opal/opal/rspec/async.rb
Original file line number Diff line number Diff line change
@@ -98,8 +98,9 @@ def self.included(base)
# end
# end
#
def async(&block)
@example.continue_async(block)
def async(&block)
# we may have timed out, in which case @example will be gone
@example.continue_async(block) if @example
end

# Runs the given block after a given duration. You are still required to
@@ -201,7 +202,8 @@ class AsyncExample < ::RSpec::Core::Example
#
# @see AsyncHelpers::ClassMethods.async
def self.register(*args)
examples << new(*args)
example_group = args[0]
example_group.examples << new(*args)
end

# All async examples in specs.
@@ -211,10 +213,9 @@ def self.examples
@examples ||= []
end

def run(example_group_instance, reporter, &after_run_block)
def run(example_group_instance, reporter)
@example_group_instance = example_group_instance
@reporter = reporter
@after_run_block = after_run_block
@finished = false

should_wait = true
@@ -225,15 +226,22 @@ def run(example_group_instance, reporter, &after_run_block)
start(reporter)

begin
run_before_each
run_before_example
@example_group_instance.instance_exec(self, &@example_block)
if pending?
Pending.mark_fixed! self

raise Pending::PendingExampleFixedError,
'Expected example to fail since it is pending, but it passed.',
[location]
end
rescue Exception => e
set_exception(e)
should_wait = false
end

if should_wait
delay options[:timeout] || 10 do
delay self.metadata[:timeout] || 10 do
next if finished?

set_exception RuntimeError.new("timeout")
@@ -264,7 +272,7 @@ def async_example_finished
@finished = true

begin
run_after_each
run_after_example
rescue Exception => e
set_exception(e)
ensure
@@ -282,7 +290,6 @@ def async_example_finished

finish(@reporter)
::RSpec.current_example = nil
@after_run_block.call
end
end
end
54 changes: 36 additions & 18 deletions opal/opal/rspec/browser_formatter.rb
Original file line number Diff line number Diff line change
@@ -4,6 +4,8 @@ module Opal
module RSpec
class BrowserFormatter < ::RSpec::Core::Formatters::BaseFormatter
include ERB::Util

::RSpec::Core::Formatters.register self, :dump_summary, :example_group_finished, :example_failed, :example_passed, :example_pending

CSS_STYLES = ::RSpec::Core::Formatters::HtmlPrinter::GLOBAL_STYLES

@@ -18,11 +20,11 @@ def start(example_count)
styles.append_to_head
end

def example_group_started(example_group)
def example_group_started(notification)
super

@example_group_failed = false
parents = example_group.parent_groups.size
parents = @example_group.parent_groups.size

@rspec_group = Element.new(:div, class_name: "example_group passed")
@rspec_dl = Element.new(:dl)
@@ -35,24 +37,42 @@ def example_group_started(example_group)
@rspec_results << @rspec_group
end

def example_group_finished(example_group)
super

def example_group_finished(_notification)
if @example_group_failed
@rspec_group.class_name = "example_group failed"
@rspec_dt.class_name = "failed"
Element.id('rspec-header').class_name = 'failed'
end

if @example_group_pending
@rspec_group.class_name = "example_group not_implemented"
@rspec_dt.class_name = "pending"
Element.id('rspec-header').class_name = 'not_implemented'
end
end

def example_pending(notification)
example = notification.example
duration = sprintf("%0.5f", example.execution_result.run_time)

pending_message = example.execution_result.pending_message

def example_failed(example)
super
duration = sprintf("%0.5f", example.execution_result[:run_time])
@example_group_pending = true

@rspec_dl << Element.new(:dd, class_name: "example not_implemented", html: <<-HTML)
<span class="not_implemented_spec_name">#{h example.description} (PENDING: #{h(pending_message)})</span>
HTML
end

def example_failed(notification)
example = notification.example
duration = sprintf("%0.5f", example.execution_result.run_time)

error = example.execution_result[:exception]
error = example.execution_result.exception
error_name = error.class.name.to_s
output = "#{short_padding}#{error_name}:\n"
error.message.to_s.split("\n").each { |line| output += "#{long_padding} #{line}\n" }
error.backtrace.each {|trace| output += "#{long_padding} #{trace}\n"}

@example_group_failed = true

@@ -65,23 +85,21 @@ def example_failed(example)
HTML
end

def example_passed(example)
super
duration = sprintf("%0.5f", example.execution_result[:run_time])
def example_passed(notification)
example = notification.example
duration = sprintf("%0.5f", example.execution_result.run_time)

@rspec_dl << Element.new(:dd, class_name: "example passed", html: <<-HTML)
<span class="passed_spec_name">#{h example.description}</span>
<span class="duration">#{duration}s</span>
HTML
end

def dump_summary(duration, example_count, failure_count, pending_count)
super
end

totals = "#{example_count} examples, #{failure_count} failures"
def dump_summary(notification)
totals = "#{notification.example_count} examples, #{notification.failure_count} failures, #{notification.pending_count} pending"
Element.id('totals').html = totals

duration = "Finished in <strong>#{sprintf("%.5f", duration)} seconds</strong>"
duration = "Finished in <strong>#{sprintf("%.5f", notification.duration)} seconds</strong>"
Element.id('duration').html = duration

add_scripts
Loading

0 comments on commit 1ceeeb2

Please sign in to comment.