Skip to content

Commit

Permalink
Use custom formatter for results and configure rspec to use should an…
Browse files Browse the repository at this point in the history
…d expect syntax
  • Loading branch information
adambeynon committed Oct 10, 2013
1 parent bc4680f commit 4a8b560
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 30 deletions.
10 changes: 5 additions & 5 deletions app/app.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@

it "should eat" do
1.should == 1
@bar.should == 201
@bar.should == 200
end

after do
@bar.class
end
end

Expand Down Expand Up @@ -37,8 +41,4 @@
end
end

RSpec.configure do |config|
config.formatter = OpalRSpec::TextFormatter
end

OpalRSpec::Runner.new.run
13 changes: 12 additions & 1 deletion opal/opal-rspec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,20 @@
require 'rspec-expectations'

# For now, we don't support mocking. This placeholder in rspec-core allows that.
# use any mocking. win.
require 'rspec/core/mocking/with_absolutely_nothing'

require 'opal-rspec/fixes'
require 'opal-rspec/text_formatter'
require 'opal-rspec/runner'

RSpec.configure do |config|

# For now, always use our custom formatter for results
config.formatter = OpalRSpec::TextFormatter

# Always support expect() and .should syntax (we should not do this really..)
config.expect_with :rspec do |c|
c.syntax = [:should, :expect]
end
end

24 changes: 5 additions & 19 deletions opal/opal-rspec/fixes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,6 @@ def underscore(camel_cased_word)
end
end

# make sure should and expect syntax are both loaded
RSpec::Expectations::Syntax.enable_should
RSpec::Expectations::Syntax.enable_expect

# opal doesnt yet support module_exec for defining methods in modules properly
module RSpec::Matchers
alias_method :expect, :expect
Expand All @@ -43,21 +39,11 @@ module Kernel
# These two methods break because of instance_variables(). That method should ignore
# private variables added by opal. This breaks as we copy ._klass which makes these
# collections think they are arrays as we copy the _klass property from an array
class RSpec::Core::Hooks::HookCollection
def for(example_or_group)
RSpec::Core::Hooks::HookCollection.
new(hooks.select {|hook| hook.options_apply?(example_or_group)}).
with(example_or_group)
end
end

class RSpec::Core::Hooks::AroundHookCollection
def for(example, initial_procsy=nil)
RSpec::Core::Hooks::AroundHookCollection.new(hooks.select {|hook| hook.options_apply?(example)}).
with(example, initial_procsy)
end
end

#
# OR:
#
# it breaks because we copy all methods from array, and dont have our real send,
# __send__ and class methods. This is more likely
class RSpec::Core::Hooks::HookCollection
`def.$send = Opal.Kernel.$send`
`def.$__send__ = Opal.Kernel.$__send__`
Expand Down
5 changes: 0 additions & 5 deletions opal/opal-rspec/runner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ def initialize(options={}, configuration=RSpec::configuration, world=RSpec::worl
end

def run(err=$stdout, out=$stdout)
# load specs by the time this runs!
@configuration.error_stream = err
@configuration.output_stream ||= out

Expand All @@ -20,10 +19,6 @@ def run(err=$stdout, out=$stdout)
end
end
end

def reporter
RSpec.configuration.formatter
end
end
end

0 comments on commit 4a8b560

Please sign in to comment.