Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added rspec-mocks to the suite. #75

Merged
merged 1 commit into from
Mar 17, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,5 @@ gem 'rspec-support', path: 'rspec-support'
gem 'rspec-core', path: 'rspec-core'
gem 'rspec-mocks', path: 'rspec-mocks'
gem 'rspec-expectations', path: 'rspec-expectations'

gem 'pry'
8 changes: 8 additions & 0 deletions lib-opal/opal/rspec/upstream-specs-support/mocks/config.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# require 'opal/progress_json_formatter' # verify case uses this
# require 'rspec/core/formatters'

RSpec.configure do |c|
#c.full_description = 'uses the default color for the shared example backtrace line'
c.add_formatter RSpec::Core::Formatters::JsonFormatter, '/tmp/spec_results.json'
c.add_formatter RSpec::Core::Formatters::ProgressFormatter, $stdout
end
98 changes: 98 additions & 0 deletions lib-opal/opal/rspec/upstream-specs-support/mocks/filters.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
require 'opal/rspec/upstream-specs-support/opal_filters'

OpalFilters.group("Bugs") do
fails "#any_instance setting a message expectation does not set the expectation on every instance"
fails "#any_instance when resetting post-verification existing method with expectations private methods restores a stubbed private method after the spec is run"
fails "#any_instance when resetting post-verification existing method with stubbing private methods restores a stubbed private method after the spec is run"
fails "#any_instance when stubbing behaves as 'every instance' handles freeze and duplication correctly"
fails "#any_instance when stubbing core ruby objects works with the non-standard constructor ''"
fails "#any_instance when stubbing core ruby objects works with the non-standard constructor \"\""
fails "A method stub #rspec_reset correctly restores the visibility of methods whose visibility has been tweaked on the singleton class"
fails "A method stub with args complains if called with no arg"
fails "A method stub with args complains if called with other arg"
fails "After a test double has been torn down for a class_double disallows being checked for nullness"
fails "After a test double has been torn down for a class_double disallows being turned into a null object"
fails "After a test double has been torn down for a class_double disallows mocking new methods"
fails "After a test double has been torn down for a class_double disallows previously mocked methods"
fails "After a test double has been torn down for a class_double disallows previously stubbed methods"
fails "After a test double has been torn down for a class_double disallows stubbing new message chains"
fails "After a test double has been torn down for a class_double disallows stubbing new methods (with receive)"
fails "After a test double has been torn down for a class_double disallows stubbing new methods (with receive_messages)"
fails "An instance double with the doubled class loaded for null objects includes the double's name in a private method error"
fails "An instance double with the doubled class loaded for null objects reports that it responds to defined private methods when the appropriate arg is passed"
fails "An instance double with the doubled class loaded for null objects reports that it responds to protected methods when the appropriate arg is passed"
fails "An instance double with the doubled class loaded gives a descriptive error message for NoMethodError"
fails "Combining implementation instructions warns when the inner implementation block is overriden"
fails "Method visibility when using partial mocks keeps private methods private"
fails "Method visibility when using partial mocks keeps protected methods protected"
fails "RSpec::Mocks.teardown does not put rspec-mocks into an inconsistent state when called extra times"
fails "RSpec::Mocks.teardown resets method stubs"

# Contains a before(:all) block that throws an error
# Opal uses around(:each) for filters, so the block gets invoked anyway producing an error
fails_context "RSpec::Mocks.with_temporary_scope in a before(:all) with an any_instance stub"

fails "RSpec::Mocks::ArgumentMatchers::HashExcludingMatcher describes itself properly"
fails "RSpec::Mocks::ArgumentMatchers::HashIncludingMatcher describes itself properly"
fails "RSpec::Mocks::Configuration configuring rspec-mocks directly behaves like configuring the syntax when configured to :should removes the expect methods from the example group context"
fails "RSpec::Mocks::Configuration configuring using the rspec-core config API behaves like configuring the syntax when configured to :should removes the expect methods from the example group context"
fails "RSpec::Mocks::Double does not respond_to? method_missing (because it's private)"
fails "RSpec::Mocks::Double even when a similar expectation with different arguments exist raises exception if args don't match when method called, correctly reporting the offending arguments"
fails "RSpec::Mocks::Double fails on no args if any args received"
fails "RSpec::Mocks::Double fails when args are expected but none are received"
fails "RSpec::Mocks::Double fails when calling yielding method with invalid kw args"
fails "RSpec::Mocks::Double has method_missing as private"
fails "RSpec::Mocks::Double raises exception if args don't match when method called even when the method is stubbed"
fails "RSpec::Mocks::Double raises exception if args don't match when method called even when using null_object"
fails "RSpec::Mocks::Double raises exception if args don't match when method called"
fails "RSpec::Mocks::Double reports line number of expectation of unreceived message after a message expecation after similar stub"
fails "RSpec::Mocks::Double reports line number of expectation of unreceived message"
fails "RSpec::Mocks::Double with a method that has a default argument raises an exception if the arguments don't match when the method is called, correctly reporting the offending arguments"
fails "RSpec::Mocks::Double with with a block with non-matching args fails"
fails "RSpec::Mocks::Double#and_yield with eval context as block argument and yielded arguments that are optional yields given argument when the argument is given"
fails "RSpec::Mocks::Matchers::HaveReceived expect(...).to have_received can generate a description after mocks have been torn down (e.g. when rspec-core requests it)"
fails "RSpec::Mocks::Matchers::HaveReceived expect(...).to have_received generates a useful description"
fails "RSpec::Mocks::Matchers::Receive allow(...).to receive behaves like an expect syntax allowance behaves like a receive matcher allows the caller to constrain the received arguments by matcher"
fails "RSpec::Mocks::Matchers::Receive allow(...).to receive behaves like an expect syntax allowance behaves like a receive matcher allows the caller to constrain the received arguments"
fails "RSpec::Mocks::Matchers::Receive allow(...).to receive behaves like resets partial mocks cleanly on a frozen object includes the spec location in the warning"
fails "RSpec::Mocks::Matchers::Receive allow(...).to receive behaves like resets partial mocks cleanly on a frozen object warns about being unable to remove the method double"
fails "RSpec::Mocks::Matchers::Receive allow_any_instance_of(...).to receive behaves like an expect syntax allowance behaves like a receive matcher allows the caller to constrain the received arguments by matcher"
fails "RSpec::Mocks::Matchers::Receive allow_any_instance_of(...).to receive behaves like an expect syntax allowance behaves like a receive matcher allows the caller to constrain the received arguments"
fails "RSpec::Mocks::Matchers::Receive expect(...).to receive behaves like an expect syntax expectation behaves like a receive matcher allows the caller to constrain the received arguments by matcher"
fails "RSpec::Mocks::Matchers::Receive expect(...).to receive behaves like an expect syntax expectation behaves like a receive matcher allows the caller to constrain the received arguments"
fails "RSpec::Mocks::Matchers::Receive expect(...).to receive behaves like an expect syntax expectation reports the line number of expectation of unreceived message"
fails "RSpec::Mocks::Matchers::Receive expect(...).to receive behaves like an expect syntax expectation sets up a message expectation that formats argument matchers correctly"
fails "RSpec::Mocks::Matchers::Receive expect(...).to receive behaves like resets partial mocks cleanly on a frozen object includes the spec location in the warning"
fails "RSpec::Mocks::Matchers::Receive expect(...).to receive behaves like resets partial mocks cleanly on a frozen object warns about being unable to remove the method double"
fails "RSpec::Mocks::Matchers::Receive expect_any_instance_of(...).to receive behaves like an expect syntax expectation behaves like a receive matcher allows the caller to constrain the received arguments by matcher"
fails "RSpec::Mocks::Matchers::Receive expect_any_instance_of(...).to receive behaves like an expect syntax expectation behaves like a receive matcher allows the caller to constrain the received arguments"
fails "RSpec::Mocks::Matchers::Receive expectations/allowances on any instance recorders includes the correct call site in the allow warning"
fails "RSpec::Mocks::Matchers::Receive expectations/allowances on any instance recorders includes the correct call site in the expect warning"
fails "RSpec::Mocks::Matchers::Receive when used in a test framework without rspec-expectations can toggle the available syntax"
fails "RSpec::Mocks::Space can be diffed in a failure when it has references to an error generator via a proxy"
fails "RSpec::Mocks::Space#any_instance_recorder_for returns the recorder for the given class"
fails "RSpec::Mocks::Space#proxies_of(klass) returns proxies"
fails "RSpec::Mocks::TestDouble#freeze gives the correct call site for the warning"
fails "Using the legacy should syntax #any_instance can get method objects for the fluent interface"
fails "Using the legacy should syntax #should_receive with an options hash reports the file and line submitted with :expected_from"
fails "an expectation set on nil issues a warning with file and line number information"
fails "and_call_original on a partial double for singleton methods works for SimpleDelegator subclasses"
fails "and_call_original on a partial double warns when you override an existing implementation"
fails "and_wrap_original on a partial double passes in the original method"
fails "argument matchers matching duck_type rejects goose when expecting a duck"
fails "argument matchers matching handling non-matcher arguments fails a class against an object of a different type"
fails "argument matchers matching handling non-matcher arguments fails for a hash w/ wrong keys"
fails "argument matchers matching handling non-matcher arguments fails for a hash w/ wrong values"
fails "argument matchers matching hash_excluding handles non matching instances nicely"
fails "argument matchers matching hash_including fails hash_including with missing key"
fails "expect(...).to receive_messages(:a => 1, :b => 2) fails with the correct location"
fails "expection set on previously stubbed method outputs arguments of similar calls"
fails "the spy family of methods class_spy behaves like a verifying spy with a foo method does not respond to methods that are not on the verified object"
fails "the spy family of methods class_spy behaves like a verifying spy with a foo method fails fast when `have_received` is passed an undefined method name"
fails "the spy family of methods class_spy behaves like a verifying spy with a foo method fails fast when negative `have_received` is passed an undefined method name"
fails "the spy family of methods class_spy behaves like a verifying spy with a foo method records called methods"
fails "the spy family of methods class_spy behaves like a verifying spy with a foo method responds to methods on the verified object"
fails "the spy family of methods class_spy takes a class and a hash of method names and return values"
fails "the spy family of methods object_spy takes an instance and a hash of method names and return values"
fails "with default syntax configuration includes the call site in the deprecation warning"
end
16 changes: 16 additions & 0 deletions lib-opal/opal/rspec/upstream-specs-support/mocks/require_specs.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
class ::RSpec::Core::Ordering::Random
# there are a lot of these in the RSpec specs that create noise
HIDE_RANDOM_WARNINGS = true
end

# dealing with dynamic requires
require 'spec_helper'
require 'rspec/support/spec/deprecation_helpers'
require 'rspec/support/spec/with_isolated_stderr'
require 'rspec/support/spec/formatting_support'
require 'rspec/support/spec/with_isolated_directory'
require 'opal-parser'
require 'opal/rspec/upstream-specs-support/core/fixes/shared_examples'
require 'corelib/marshal'
require_relative 'config'
require_relative 'filters'
35 changes: 27 additions & 8 deletions lib-opal/opal/rspec/upstream-specs-support/opal_filters.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,25 +21,44 @@ def group(name, &block)
@name = old_name
end

def fails full_description, note = nil
FIXME = 'FIXME'

def fails(full_description, note = nil)
note = "#{name}: #{note || FIXME}"
@filters[full_description] = note || full_description
end

def filtered?(example)
@filters[example.full_description]
alias fails_context fails

def filtered?(full_description)
@filters[full_description]
end

def pending_message(example)
note = @filters[example.full_description]
def pending_message(full_description)
note = @filters[full_description]
"#{@name}: #{note}"
end
end

module SkipContextSupport
def context(description, *args, &block)
full_description = metadata[:full_description] + ' ' + description
if OpalFilters.filtered?(full_description)
puts "SKIPPING #{full_description}"
else
super
end
end
end

RSpec.configure do |config|
config.extend(SkipContextSupport)

config.around(:each) do |example|
# puts '|||'+example.full_description+'|||' if example.full_description.include? 'when a custom order'
pending OpalFilters.pending_message(example) if OpalFilters.filtered?(example)
example.call
if OpalFilters.filtered?(example.full_description)
pending OpalFilters.pending_message(example.full_description)
else
example.call
end
end
end
12 changes: 11 additions & 1 deletion spec/integration/verify_rspec_specs_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,13 @@ def expect_results_to_be(expected_results)
expect(results.json[:summary_line]).to eq(expected_results)
expect(failures).to eq([])
expect(results).to be_successful
rescue
rescue => e
print_results(results)
raise e
end

def print_results(results)
return if results.nil?
puts "=========== Output of failed run ============"
puts results.quoted_output
puts "============================================="
Expand Down Expand Up @@ -52,4 +54,12 @@ def spec_glob
end
end

context 'Mocks' do
include Opal::RSpec::OpalRSpecSpecLoader
let(:short_name) { 'mocks' }

it 'runs correctly' do
expect_results_to_be('1306 examples, 0 failures, 102 pending')
end
end
end
1 change: 1 addition & 0 deletions spec/rspec/opal_rspec_spec_loader.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ def stub_requires
'rspec/support/spec/shell_out', # only does stuff Opal can't support anyways
'rspec/support/spec/prevent_load_time_warnings',
'timeout',
'yaml',
].each { |f| ::Opal::Config.stubbed_files << f }
end

Expand Down