Skip to content

Commit

Permalink
Update rspec gems to use latest master
Browse files Browse the repository at this point in the history
  • Loading branch information
adambeynon committed Oct 26, 2013
1 parent 0ebde6e commit 7bea4d0
Show file tree
Hide file tree
Showing 10 changed files with 127 additions and 66 deletions.
7 changes: 4 additions & 3 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ gem 'opal', :github => 'opal/opal'
gem 'opal-sprockets', :github => 'opal/opal-sprockets'

# As we monkey patch a lot, work of a specific commit on github
gem 'rspec-expectations', :github => 'rspec/rspec-expectations', :ref => '4c47e4c43e'
gem 'rspec-core', :github => 'rspec/rspec-core', :ref => 'fcc72a72ae'
gem 'rspec-mocks', :github => 'rspec/rspec-mocks', :ref => 'cd7261f3fb'
gem 'rspec-support', :github => 'rspec/rspec-support', :ref => 'f235ccb129'
gem 'rspec-expectations', :github => 'rspec/rspec-expectations', :ref => 'd3277fd42e'
gem 'rspec-core', :github => 'rspec/rspec-core', :ref => 'ed8898c58b'
gem 'rspec-mocks', :github => 'rspec/rspec-mocks', :ref => 'a2f952a025'

gem 'rspec', :github => 'rspec/rspec'
46 changes: 29 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,30 +37,42 @@ Visit the page in any browser and view the console:
`opal/opal-rspec/fixes.rb` contains a few bug fixes that need to be merged upstream
to opal itself. In app/rspec we have to stub various rspec files.

### Immutable strings
### rspec/core.rb

`opal/opal/rspec/fixes.rb` contains two stub methods as those core rspec methods
try to use mutable strings, which are not supported in opal.
* **line 1**: `require_rspec` to fake require_relative doesnt work at runtime.
opal has to include all dependencies into build.

### HEREDOCS
* **line 90**: heredoc fails to parse in opal as EOS is used within heredoc

Parsing heredocs causes problems
* **line 171**: `&::Time.method(:now)` doesnt work so wrong method is set

* rspec/core/shared_example_group/collection.rb
* rspec/core/example_group.rb
* rspec/core/project_initializer.rb
* rspec/core/shared_example_group.rb
* rspec/matchers/built_in/change.rb
### rspec/core/configuration.rb

### require
* **line ?**: something in that file is causing opal to generate bad javascript.
This is possible a require statement used as an expression which generates empty
code.

When used as expression generating empty code (syntax error)
### rspec/core/example_group.rb

* rspec/core/configuration.rb
* **line 434**: cannot parse heredoc as it uses EOS inline before string ends

### Bad autoload/missing file
* **line 547**: opal cannot use mutable strings (see opal/rspec/fixes.rb)

An autoload exists, but the file referenced doesnt actually exist, so we
have to stub it
* **line 564**: opal cannot use mutable strings (see opal/rspec/fixes.rb)

* rspec/matchers/built_in/have.rb
### rspec/core/project_initializer.rb

* **line 1**: opal cannot parse these heredocs (EOS used before last line of string)

### rspec/core/shared_example_group.rb

* **line 112**: opal cannot parse this heredoc

### rspec/core/shared_example_group/collection.rb

* **line 17**: opal cannot parse command call inside aref

### rspec/matchers/built_in/have.rb

* **line 1**: this is an error in rspec. This autoload does not exist so we must
stub the file.
1 change: 1 addition & 0 deletions app/rspec-builder.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
require 'rspec/support'
require 'rspec/core'
require 'rspec/mocks'
require 'rspec-expectations'
Expand Down
18 changes: 10 additions & 8 deletions app/rspec/core.rb
Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@
require_rspec = if defined?(require_relative)
lambda do |path|
# require_relative path
require_relative path
end
else # for 1.8.7
lambda do |path|
# require "rspec/#{path}"
require "rspec/#{path}"
end
end

require 'set'
require 'time'
require 'rbconfig'
require 'rspec/core/caller_filter'

require 'rspec/core/version'

require 'rspec/support/caller_filter'

require 'rspec/core/flat_map'
require 'rspec/core/filter_manager'
require 'rspec/core/dsl'
Expand All @@ -35,7 +39,6 @@
require 'rspec/core/shared_example_group/collection'
require 'rspec/core/shared_example_group'
require 'rspec/core/example_group'
require 'rspec/core/version'

module RSpec
autoload :SharedContext, 'rspec/core/shared_context'
Expand Down Expand Up @@ -85,10 +88,12 @@ def self.configuration
RSpec.warn_deprecation <<-WARNING
*****************************************************************
DEPRECATION WARN
* RSpec.configuration with a block is deprecated and has no effect.
* please use RSpec.configure with a block instead.
Called from
*****************************************************************
WARNING
Expand Down Expand Up @@ -163,10 +168,7 @@ module Core
# it.
class Time
class << self
def now
::Time.now
end
#define_method(:now, &::Time.method(:now))
def now; ::Time.now; end #define_method(:now, &::Time.method(:now))
end
end

Expand Down
54 changes: 47 additions & 7 deletions app/rspec/core/example_group.rb
Original file line number Diff line number Diff line change
Expand Up @@ -267,16 +267,10 @@ def self.superclass_metadata
#
# @see DSL#describe
def self.describe(*args, &example_group_block)
@_subclass_count ||= 0
@_subclass_count += 1
args << {} unless args.last.is_a?(Hash)
args.last.update(:example_group_block => example_group_block)

# TODO 2010-05-05: Because we don't know if const_set is thread-safe
child = const_set(
"Nested_#{@_subclass_count}",
subclass(self, args, &example_group_block)
)
child = subclass(self, args, &example_group_block)
children << child
child
end
Expand All @@ -289,6 +283,7 @@ class << self
def self.subclass(parent, args, &example_group_block)
subclass = Class.new(parent)
subclass.set_it_up(*args)
ExampleGroups.assign_const(subclass)
subclass.module_eval(&example_group_block) if example_group_block

# The LetDefinitions module must be included _after_ other modules
Expand Down Expand Up @@ -438,6 +433,8 @@ def self.ordering_strategy
registry.fetch(order) do
warn <<-WARNING
WARN: Ignoring unknown ordering specified using `:order => #{order.inspect}` metadata.
WARN
WARN
WARNING

registry.fetch(:global)
Expand Down Expand Up @@ -530,4 +527,47 @@ def instance_exec_with_rescue(example, context = nil, &hook)
end
end
end

# Namespace for the example group subclasses generated by top-level `describe`.
module ExampleGroups
def self.assign_const(group)
base_name = base_name_for(group)
const_scope = constant_scope_for(group)
name = disambiguate(base_name, const_scope)

const_scope.const_set(name, group)
end

def self.constant_scope_for(group)
const_scope = group.superclass
const_scope = self if const_scope == Core::ExampleGroup
const_scope
end

def self.base_name_for(group)
return "Anonymous" if group.description.empty?

# convert to CamelCase
name = ' ' + group.description
name.gsub!(/[^0-9a-zA-Z]+([0-9a-zA-Z])/) { $1.upcase }

name.lstrip! # Remove leading whitespace
name.gsub!(/\W/, '') # JRuby, RBX and others don't like non-ascii in const names

# Ruby requires first const letter to be A-Z. Use `Nested`
# as necessary to enforce that.
name.gsub!(/\A([^A-Z]|\z)/, 'Nested\1')

name
end

def self.disambiguate(name, const_scope)
return name unless const_scope.const_defined?(name)

# Add a trailing number if needed to disambiguate from an existing constant.
name << "_2"
name.next! while const_scope.const_defined?(name)
name
end
end
end
4 changes: 4 additions & 0 deletions app/rspec/core/shared_example_group.rb
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,10 @@ def warn_if_key_taken(source, key, new_block)

RSpec.warn_with <<-WARNING
WARN: Shared example group '#{key}' has been previously defined at:
WARN
WARN
WARN
WARN
WARNING
end

Expand Down
19 changes: 1 addition & 18 deletions app/rspec/core/shared_example_group/collection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ def initialize(sources, examples)
end

def [](key)
fetch_examples(key) || warn_deprecation_and_fetch_anyway(key)
fetch_examples(key)
end

private
Expand All @@ -21,23 +21,6 @@ def source_for(key)
@sources.reverse.find { |source| @examples[source].has_key? key }
end

def fetch_anyway(key)
@examples.values.inject({}, &:merge)[key]
end

def warn_deprecation_and_fetch_anyway(key)
if (example = fetch_anyway key)
backtrace_line = CallerFilter.first_non_rspec_line

RSpec.warn_deprecation <<-WARNING
Accessing shared_examples defined across contexts is deprecated.
Please declare shared_examples within a shared context, or at the top level.
WARNING

example
end
end

end
end
end
Expand Down
7 changes: 0 additions & 7 deletions app/rspec/matchers/built_in/change.rb

This file was deleted.

31 changes: 31 additions & 0 deletions opal/opal/rspec/fixes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,34 @@ def prefix_and_expected(symbol)
return $~[1], $~[3]
end
end

module RSpec::ExampleGroups
def self.base_name_for(group)
return "Anonymous" if group.description.empty?

# convert to CamelCase
name = ' ' + group.description
name = name.gsub(/[^0-9a-zA-Z]+([0-9a-zA-Z])/) { |m| m[1].upcase }

name = name.lstrip # Remove leading whitespace
name = name.gsub(/\W/, '') # JRuby, RBX and others don't like non-ascii in const names

# Ruby requires first const letter to be A-Z. Use `Nested`
# as necessary to enforce that.
name = name.gsub(/\A([^A-Z]|\z)/, 'Nested$1')

name
end

def self.disambiguate(name, const_scope)
return name unless const_scope.const_defined?(name)

# Add a trailing number if needed to disambiguate from an existing constant.
name = name + "_2"
while const_scope.const_defined?(name)
name = name.next
end

name
end
end
6 changes: 0 additions & 6 deletions spec/example_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -92,12 +92,6 @@ def some_helper
end
end

describe [1, 2, 3] do
it "should use a given object as the subject" do
subject.should eq([1, 2, 3])
end
end

describe "Simple expectations" do
before do
@bar = 200
Expand Down

0 comments on commit 7bea4d0

Please sign in to comment.