Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: jruby/jruby
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: c7f5058823ea
Choose a base ref
...
head repository: jruby/jruby
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 18861878363c
Choose a head ref
  • 4 commits
  • 507 files changed
  • 1 contributor

Commits on Jan 29, 2018

  1. Squashed 'spec/mspec/' changes from 5f563e4..5d49a6c

    5d49a6c The frozen_error_class helper should check respond_to? including private methods
    d1d2cc4 Fix error message when installing both a stub and a mock and arguments do not match
    a26c990 Print mock arguments more clearly
    
    git-subtree-dir: spec/mspec
    git-subtree-split: 5d49a6c928cd753cf12438f15fd5ed67e9e98171
    eregon committed Jan 29, 2018
    Copy the full SHA
    fff6ad0 View commit details
  2. Copy the full SHA
    9a3ed41 View commit details
  3. Squashed 'spec/ruby/' changes from 0fe33ac..83063a3

    83063a3 Guard spec causing SEGV on MRI on Windows
    670e8e5 Version transform_keys spec as it is not yet clear if it will be backported
    fd56cd4 Add version guards for defined?(top-level constant lookup)
    577bfbc Add missing version guard
    d3ff8f7 Avoid 2.5-specific syntax
    8b385ca Add missing version guard
    faba5e2 defined? returns nil for toplevel constant lookup
    a17f11c Fix rubyspec against the change in Hash#transform_keys!
    18bd9bd Group related File.umask specs together
    3adf01b Remove specs trying arbitrary values for chmod and umask
    2ab64e9 system_spec.rb: add RubySpec for r62025
    de141fd r61950 changes mode_t to ushort on FreeBSD and Darwin
    c390e3d matrix.rb: add Matrix#antisymmetric?
    5672af0 spec/: skip some specs so that no failure occurs in root privilege
    c2023d6 spec/ruby/library/etc/getlogin_spec.rb: Use `logname` as an expected result
    e5d045e `$SAFE` as a process global state. [Feature #14250]
    726e32e There are no signals on Windows
    3585f7c Fix style
    17ebd61 [spec] Complex() with nil argument - according to how MRI (2.4) behaves
    2295c9f Add spec for Hash#rehash with duplicate keys
    acef8e2 Isolate threads and ensure they are alive before testing.
    5cd975a Revert "Allow more GC cycles for the reference to be vacated."
    0dbbac1 Add an extra spec when inspecting the receiver of a NoMethodError fails
    16de198 Fix NoMethodError#inspect spec
    8840483 It seems that = and ~ are not escaped in MRI
    e73e0a6 Add spec for Method#to_proc.binding.receiver.
    5dc2090 Add spec for IO#ungetc
    e716a09 Add spec for when inspect is called when a NoMethodError is thrown.
    47f70ee Make sure the number for ABRT signal does not lead to IOT
    657640c Add spec to check that files aren't closed if autoclose = false.
    823eabe Add new spec for Signal.trap
    143fa1d Fix a few descriptions in C-API Numeric specs
    42542b6 Add specs for rb_ull2inum()
    3154730 Ensure Array#[]=(range, scalar) returns the correct value.
    c38a0c5 Simplify Module#const_missing spec by using private visibility
    718ca7b Add spec to verify `const_missing' is called for missing constants even when visibility is non-public.
    239785b Remove hack in Kernel#yield_self spec
    1afff14 Spec for defined global with nil value.
    fc27321 Add examples of nested methods resetting the visibility to public
    8165048 Add a spec about the default definee inside Module#define_method
    cf7b2db Make sure the method is not defined on Object in nested def spec
    f30246e Add Rational and Complex to != #hash in != processes spec
    ea1d7e2 Unshare Complex#hash specs since there is only one usage
    30b88e5 Add specs catching a bug when using a thread-pool for Fibers
    afa2c6a Use @method in the shared Fiber#resume/transfer spec
    da3aff2 Move Fiber#resume-specific spec out of shared specs
    bf6e49e Add specs for escaping in %r style regexp literals.
    826f776 One more expectation for String#-@
    3952a7d Clarify example
    a2fd7c4 Add an extra spec for String#-@ with frozen strings
    db9be93 [Code review] Add extra expectations
    50db73e Add specs for -"literal" (String#-@) optimized to return the same object
    fabe37e Add specs for String#-@ deduplicates unfrozen strings
    7fa2202 Add spec for IO#close when stream closed in another thread
    4e665c8 Add spec for Process#last_status
    0c41549 Unify usages of it_behaves_like to not include parenthesis
    5301f24 Show two usages of a shared spec to clarify
    8117d90 Move style section at the end
    af0e1ca Add missing quote
    b777f8c Documents the shared specs functionality
    fa85c3c Add spec for Thread#fetch
    10c1011 Add specs for ^ and $, and Regexp.last_match
    eb44155 Add spec for String#start_with? supporting regexp
    98bbaf3 [Code review] Fix and refactor #div and #divide specs
    f3aeb79 Remove specs for inherited from Numeric/Kernel methods - #zero?, #dup, #hash
    84c2867 Add missing specs and refactor some of them
    d6eac79 Remove Fixnum specs
    98658f9 Remove Bignum specs
    215c9b6 Adopt Bignum specs
    fcebb9b Adopt Fixnum specs
    394fb12 Remove ruby version guards from coerce shared examples
    8fd24d2 Move Fixnum#coerce specs to Numeric#coerce
    d776690 Move Fixnum#hash specs to Kernel#Hash
    8f5c639 Thread#backtrace should never be nil for a living Thread (#581)
    875da49 test Fiber#transfer between fibers in a non-main thread
    8c9960a Moves KeyError into Shared spec (#576)
    957a3cf Merge pull request #577 from andrykonchin/file-path-raises-an-ioerror
    3703d0f [Code review] Fix typo
    708e70c [Code review] Move new test case to the shared example
    e034de1 Use guard instead of if statement globally
    b0b7b02 [Code review] Use guard instead of if statement
    40d8c9a Add specs for File.path
    ece1a44 Add specs for raising IOError for unnamed files
    a6453bf Merge pull request #573 from andrykonchin/integer-pow-accepts-modulo-argument
    76b7bc0 Share specs between File#to_path and File#path
    172816b Move specs for File#to_path to shared file
    60a7239 Fix specs for Integer/Bignum class check in the old Ruby versions
    2e21673 [Code review] Share some cases with Integer#**
    968c4b4 [Code review] Mark the case as a bug
    05b4597 Adds coverage for KeyError#receiver / KeyError#key (#574)
    971ffe0 [Code review] Fix typo and add new cases
    ac92825 Suppress rubocop warnings
    00a0ac6 Add missing argument in expected call in Net::FTP#initialize spec
    be17ce5 Add spec for Enumerator::Lazy#chunk
    8e2ac9c Add specs for Net::FTP.new options
    7426d24 Adopt specs for Fixnum#**, refactor and add new cases for Integer#pow
    b95d7ed Clarify leap second specs
    88c68f3 Only run if leap second support is available
    46db21a Bad leap seconds are handled on all platforms
    
    git-subtree-dir: spec/ruby
    git-subtree-split: 83063a312d81113ebe5cfe8f90836da4024dcd35
    eregon committed Jan 29, 2018

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    39bc569 View commit details
  4. Copy the full SHA
    1886187 View commit details
Showing 507 changed files with 4,389 additions and 3,283 deletions.
2 changes: 1 addition & 1 deletion spec/mspec/lib/mspec/helpers/frozen_error_class.rb
Original file line number Diff line number Diff line change
@@ -2,7 +2,7 @@

# This helper makes it easy to write version independent
# specs for frozen objects.
unless respond_to? :frozen_error_class
unless respond_to? :frozen_error_class, true
ruby_version_is "2.5" do
def frozen_error_class
FrozenError
20 changes: 17 additions & 3 deletions spec/mspec/lib/mspec/mocks/mock.rb
Original file line number Diff line number Diff line change
@@ -54,6 +54,11 @@ def self.install_method(obj, sym, type=nil)
key = replaced_key obj, sym
sym = sym.to_sym

if type == :stub and mocks.key?(key)
# Defining a stub and there is already a mock, ignore the stub
return
end

if (sym == :respond_to? or mock_respond_to?(obj, sym, true)) and !replaced?(key.first)
meta.__send__ :alias_method, key.first, sym
end
@@ -73,6 +78,11 @@ def self.install_method(obj, sym, type=nil)
MSpec.actions :expectation, MSpec.current.state
end

if proxy.mock? and stubs.key?(key)
# Defining a mock and there is already a stub, remove the stub
stubs.delete key
end

if proxy.stub?
stubs[key].unshift proxy
else
@@ -87,6 +97,10 @@ def self.name_or_inspect(obj)
obj.instance_variable_get(:@name) || obj.inspect
end

def self.inspect_args(args)
"(#{Array(args).map(&:inspect).join(', ')})"
end

def self.verify_count
mocks.each do |key, proxies|
obj = objects[key]
@@ -106,7 +120,7 @@ def self.verify_count
end
unless pass
SpecExpectation.fail_with(
"Mock '#{name_or_inspect obj}' expected to receive '#{key.last}' " + \
"Mock '#{name_or_inspect obj}' expected to receive #{key.last}#{inspect_args proxy.arguments} " + \
"#{qualifier.to_s.sub('_', ' ')} #{count} times",
"but received it #{proxy.calls} times")
end
@@ -120,7 +134,7 @@ def self.verify_call(obj, sym, *args, &block)

key = replaced_key obj, sym
[mocks, stubs].each do |proxies|
proxies[key].each do |proxy|
proxies.fetch(key, []).each do |proxy|
pass = case proxy.arguments
when :any_args
true
@@ -166,7 +180,7 @@ def self.verify_call(obj, sym, *args, &block)
mock_respond_to? obj, *args
else
SpecExpectation.fail_with("Mock '#{name_or_inspect obj}': method #{sym}\n",
"called with unexpected arguments (#{Array(compare).join(' ')})")
"called with unexpected arguments #{inspect_args compare}")
end
end

65 changes: 64 additions & 1 deletion spec/mspec/spec/mocks/mock_spec.rb
Original file line number Diff line number Diff line change
@@ -313,6 +313,58 @@ class MockAndRaiseError < Exception; end
end
end

describe Mock, ".verify_call mixing mocks and stubs" do
before :each do
MSpec.stub(:actions)
MSpec.stub(:current).and_return(double("spec state").as_null_object)

@mock = double('verify_call')
end

after :each do
ScratchPad.clear
Mock.cleanup
end

it "checks the mock arguments when a mock is defined after a stub" do
Mock.install_method @mock, :method_call, :stub
Mock.install_method(@mock, :method_call, :mock).with("arg")

-> {
@mock.method_call
}.should raise_error(SpecExpectationNotMetError, /called with unexpected arguments \(\)/)

-> {
@mock.method_call("a", "b")
}.should raise_error(SpecExpectationNotMetError, /called with unexpected arguments \("a", "b"\)/)

-> {
@mock.method_call("foo")
}.should raise_error(SpecExpectationNotMetError, /called with unexpected arguments \("foo"\)/)

@mock.method_call("arg")
end

it "checks the mock arguments when a stub is defined after a mock" do
Mock.install_method(@mock, :method_call, :mock).with("arg")
Mock.install_method @mock, :method_call, :stub

-> {
@mock.method_call
}.should raise_error(SpecExpectationNotMetError, /called with unexpected arguments \(\)/)

-> {
@mock.method_call("a", "b")
}.should raise_error(SpecExpectationNotMetError, /called with unexpected arguments \("a", "b"\)/)

-> {
@mock.method_call("foo")
}.should raise_error(SpecExpectationNotMetError, /called with unexpected arguments \("foo"\)/)

@mock.method_call("arg")
end
end

describe Mock, ".verify_count" do
before :each do
MSpec.stub(:actions)
@@ -396,13 +448,23 @@ class MockAndRaiseError < Exception; end
it "verifies the calls to the mocked method when a mock is defined after a stub" do
Mock.install_method @mock, :method_call, :stub
Mock.install_method @mock, :method_call, :mock

-> {
Mock.verify_count
}.should raise_error(SpecExpectationNotMetError, /received it 0 times/)

@mock.method_call
Mock.verify_count
end

it "verifies the calls to the mocked method when a mock is defined before a stub" do
Mock.install_method @mock, :method_call, :mock
Mock.install_method @mock, :method_call, :stub

-> {
Mock.verify_count
}.should raise_error(SpecExpectationNotMetError, /received it 0 times/)

@mock.method_call
Mock.verify_count
end
@@ -415,7 +477,6 @@ class MockAndRaiseError < Exception; end

@mock = double('cleanup')
@proxy = Mock.install_method @mock, :method_call
@stub = Mock.install_method @mock, :method_call, :stub
end

after :each do
@@ -449,6 +510,8 @@ def @mock.already_here() :hey end
end

it "removes all stubs" do
Mock.cleanup # remove @proxy
@stub = Mock.install_method @mock, :method_call, :stub
Mock.stubs.should == { Mock.replaced_key(@mock, :method_call) => [@stub] }
Mock.cleanup
Mock.stubs.should == {}
5 changes: 5 additions & 0 deletions spec/ruby/.rubocop.yml
Original file line number Diff line number Diff line change
@@ -60,6 +60,11 @@ Lint/EmptyWhen:
- language/case_spec.rb
- optional/capi/spec_helper.rb

Lint/NestedMethodDefinition:
Exclude:
- language/def_spec.rb
- language/fixtures/def.rb

Lint/UriRegexp:
Exclude:
- 'library/uri/regexp_spec.rb'
5 changes: 0 additions & 5 deletions spec/ruby/.rubocop_todo.yml
Original file line number Diff line number Diff line change
@@ -89,11 +89,6 @@ Lint/MultipleCompare:
Exclude:
- 'language/precedence_spec.rb'

# Offense count: 8
Lint/NestedMethodDefinition:
Exclude:
- 'language/def_spec.rb'

# Offense count: 12
Lint/ParenthesesAsGroupedExpression:
Exclude:
72 changes: 71 additions & 1 deletion spec/ruby/CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -166,6 +166,76 @@ Use the implementation test suite for these.

If an implementation does not support some feature, simply tag the related specs as failing instead.

### Shared Specs

Often throughout Ruby, identical functionality is used by different methods and modules. In order
to avoid duplication of specs, we have shared specs that are re-used in other specs. The use is a
bit tricky however, so let's go over it.

Commonly, if a shared spec is only reused within its own module, the shared spec will live within a
shared directory inside that module's directory. For example, the `core/hash/shared/key.rb` spec is
only used by `Hash` specs, and so it lives inside `core/hash/shared/`.

When a shared spec is used across multiple modules or classes, it lives within the `shared/` directory.
An example of this is the `shared/file/socket.rb` which is used by `core/file/socket_spec.rb`,
`core/filetest/socket_spec.rb`, and `core/file/state/socket_spec.rb` and so it lives in the root `shared/`.

Defining a shared spec involves adding a `shared: true` option to the top-level `describe` block. This
will signal not to run the specs directly by the runner. Shared specs have access to two instance
variables from the implementor spec: `@method` and `@object`, which the implementor spec will pass in.

Here's an example of a snippet of a shared spec and two specs which integrates it:

``` ruby
# core/hash/shared/key.rb
describe :hash_key_p, shared: true do
it "returns true if the key's matching value was false" do
{ xyz: false }.send(@method, :xyz).should == true
end
end

# core/hash/key_spec.rb
describe "Hash#key?" do
it_behaves_like :hash_key_p, :key?
end

# core/hash/include_spec.rb
describe "Hash#include?" do
it_behaves_like :hash_key_p, :include?
end
```

In the example, the first `describe` defines the shared spec `:hash_key_p`, which defines a spec that
calls the `@method` method with an expectation. In the implementor spec, we use `it_behaves_like` to
integrate the shared spec. `it_behaves_like` takes 3 parameters: the key of the shared spec, a method,
and an object. These last two parameters are accessible via `@method` and `@object` in the shared spec.

Sometimes, shared specs require more context from the implementor class than a simple object. We can address
this by passing a lambda as the method, which will have the scope of the implementor. Here's an example of
how this is used currently:

``` ruby
describe :kernel_sprintf, shared: true do
it "raises TypeError exception if cannot convert to Integer" do
-> { @method.call("%b", Object.new) }.should raise_error(TypeError)
end
end

describe "Kernel#sprintf" do
it_behaves_like :kernel_sprintf, -> (format, *args) {
sprintf(format, *args)
}
end

describe "Kernel.sprintf" do
it_behaves_like :kernel_sprintf, -> (format, *args) {
Kernel.sprintf(format, *args)
}
end
```

In the above example, the method being passed is a lambda that triggers the specific conditions of the shared spec.

### Style

Do not leave any trailing space and respect the existing style.
Do not leave any trailing space and follow the existing style.
2 changes: 1 addition & 1 deletion spec/ruby/core/array/append_spec.rb
Original file line number Diff line number Diff line change
@@ -37,6 +37,6 @@

ruby_version_is "2.5" do
describe "Array#append" do
it_behaves_like(:array_push, :append)
it_behaves_like :array_push, :append
end
end
4 changes: 2 additions & 2 deletions spec/ruby/core/array/collect_spec.rb
Original file line number Diff line number Diff line change
@@ -3,9 +3,9 @@
require File.expand_path('../shared/collect', __FILE__)

describe "Array#collect" do
it_behaves_like(:array_collect, :collect)
it_behaves_like :array_collect, :collect
end

describe "Array#collect!" do
it_behaves_like(:array_collect_b, :collect!)
it_behaves_like :array_collect_b, :collect!
end
2 changes: 1 addition & 1 deletion spec/ruby/core/array/element_reference_spec.rb
Original file line number Diff line number Diff line change
@@ -3,7 +3,7 @@
require File.expand_path('../shared/slice', __FILE__)

describe "Array#[]" do
it_behaves_like(:array_slice, :[])
it_behaves_like :array_slice, :[]
end

describe "Array.[]" do
35 changes: 27 additions & 8 deletions spec/ruby/core/array/element_set_spec.rb
Original file line number Diff line number Diff line change
@@ -350,11 +350,13 @@ def obj.to_ary() [1, 2, 3] end
it "returns non-array value if non-array value assigned" do
a = [1, 2, 3, 4, 5]
(a[2..4] = 10).should == 10
(a.[]=(2..4, 10)).should == 10
end

it "returns array if array assigned" do
a = [1, 2, 3, 4, 5]
(a[2..4] = [7, 8]).should == [7, 8]
(a.[]=(2..4, [7, 8])).should == [7, 8]
end

it "just sets the section defined by range to nil even if the rhs is nil" do
@@ -394,15 +396,32 @@ def obj.to_ary() [1, 2, 3] end
a.should == [1, 2, 3, 8, 4, 5]
end

it "accepts Range subclasses" do
a = [1, 2, 3, 4]
range_incl = ArraySpecs::MyRange.new(1, 2)
range_excl = ArraySpecs::MyRange.new(-3, -1, true)
describe "Range subclasses" do
before :each do
@range_incl = ArraySpecs::MyRange.new(1, 2)
@range_excl = ArraySpecs::MyRange.new(-3, -1, true)
end

it "accepts Range subclasses" do
a = [1, 2, 3, 4]

a[@range_incl] = ["a", "b"]
a.should == [1, "a", "b", 4]
a[@range_excl] = ["A", "B"]
a.should == [1, "A", "B", 4]
end

it "returns non-array value if non-array value assigned" do
a = [1, 2, 3, 4, 5]
(a[@range_incl] = 10).should == 10
(a.[]=(@range_incl, 10)).should == 10
end

a[range_incl] = ["a", "b"]
a.should == [1, "a", "b", 4]
a[range_excl] = ["A", "B"]
a.should == [1, "A", "B", 4]
it "returns array if array assigned" do
a = [1, 2, 3, 4, 5]
(a[@range_incl] = [7, 8]).should == [7, 8]
a.[]=(@range_incl, [7, 8]).should == [7, 8]
end
end
end

2 changes: 1 addition & 1 deletion spec/ruby/core/array/index_spec.rb
Original file line number Diff line number Diff line change
@@ -2,5 +2,5 @@
require File.expand_path('../shared/index', __FILE__)

describe "Array#index" do
it_behaves_like(:array_index, :index)
it_behaves_like :array_index, :index
end
2 changes: 1 addition & 1 deletion spec/ruby/core/array/length_spec.rb
Original file line number Diff line number Diff line change
@@ -3,5 +3,5 @@
require File.expand_path('../shared/length', __FILE__)

describe "Array#length" do
it_behaves_like(:array_length, :length)
it_behaves_like :array_length, :length
end
4 changes: 2 additions & 2 deletions spec/ruby/core/array/map_spec.rb
Original file line number Diff line number Diff line change
@@ -3,9 +3,9 @@
require File.expand_path('../shared/collect', __FILE__)

describe "Array#map" do
it_behaves_like(:array_collect, :map)
it_behaves_like :array_collect, :map
end

describe "Array#map!" do
it_behaves_like(:array_collect_b, :map!)
it_behaves_like :array_collect_b, :map!
end
2 changes: 1 addition & 1 deletion spec/ruby/core/array/prepend_spec.rb
Original file line number Diff line number Diff line change
@@ -4,6 +4,6 @@

ruby_version_is "2.5" do
describe "Array#prepend" do
it_behaves_like(:array_unshift, :prepend)
it_behaves_like :array_unshift, :prepend
end
end
2 changes: 1 addition & 1 deletion spec/ruby/core/array/push_spec.rb
Original file line number Diff line number Diff line change
@@ -3,5 +3,5 @@
require File.expand_path('../shared/push', __FILE__)

describe "Array#push" do
it_behaves_like(:array_push, :push)
it_behaves_like :array_push, :push
end
Loading