Skip to content

Commit 92ccc82

Browse files
committed
Update specs
PullRequest: truffleruby/537
2 parents 577e316 + 3fe7160 commit 92ccc82

File tree

151 files changed

+2543
-21334
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

151 files changed

+2543
-21334
lines changed

lib/cext/include/truffleruby/constants.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ VALUE rb_tr_get_Data(void);
1111
VALUE rb_tr_get_Encoding(void);
1212
VALUE rb_tr_get_EncodingError(void);
1313
VALUE rb_tr_get_Enumerable(void);
14+
VALUE rb_tr_get_Enumerator(void);
1415
VALUE rb_tr_get_FalseClass(void);
1516
VALUE rb_tr_get_File(void);
1617
VALUE rb_tr_get_Float(void);
@@ -83,6 +84,7 @@ VALUE rb_tr_get_default_rs(void);
8384
#define rb_cEncoding rb_tr_get_Encoding()
8485
#define rb_eEncodingError rb_tr_get_EncodingError()
8586
#define rb_mEnumerable rb_tr_get_Enumerable()
87+
#define rb_cEnumerator rb_tr_get_Enumerator()
8688
#define rb_cFalseClass rb_tr_get_FalseClass()
8789
#define rb_cFile rb_tr_get_File()
8890
#define rb_cFloat rb_tr_get_Float()

lib/truffle/truffle/cext_constants.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,10 @@ def rb_mEnumerable
4545
Enumerable
4646
end
4747

48+
def rb_cEnumerator
49+
Enumerator
50+
end
51+
4852
def rb_cFalseClass
4953
FalseClass
5054
end
@@ -270,7 +274,7 @@ def rb_eZeroDivError
270274
end
271275

272276
def rb_eFatal
273-
Truffle::CExt.rb_const_get(Object, "fatal")
277+
Truffle::CExt.rb_const_get(Object, 'fatal')
274278
end
275279

276280
def rb_stdin

spec/mspec/README.md

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,14 @@
22

33
## Overview
44

5-
MSpec is a specialized framework that is syntax-compatible with RSpec for
6-
basic things like 'describe', 'it' blocks and 'before', 'after' actions. MSpec
7-
contains additional features that assist in writing the RubySpecs used by
8-
multiple Ruby implementations.
5+
MSpec is a specialized framework that is syntax-compatible with RSpec 2 for
6+
basic things like `describe`, `it` blocks and `before`, `after` actions.
7+
MSpec contains additional features that assist in writing specs for
8+
Ruby implementations in [ruby/spec](https://github.com/ruby/spec).
99

1010
MSpec attempts to use the simplest Ruby language features so that beginning
11-
Ruby implementations can run the Ruby specs.
11+
Ruby implementations can run the Ruby specs. For example, no file from the
12+
standard library or RubyGems is necessary to run MSpec.
1213

1314
MSpec is not intended as a replacement for RSpec. MSpec attempts to provide a
1415
subset of RSpec's features in some cases and a superset in others. It does not
@@ -23,8 +24,6 @@ specs in a manner compatible with multiple Ruby implementations.
2324

2425
2. MSpec provides a different shared spec implementation specifically
2526
designed to ease writing specs for the numerous aliased methods in Ruby.
26-
The MSpec shared spec implementation should not conflict with RSpec's own
27-
shared behavior facility.
2827

2928
3. MSpec provides various helper methods to simplify some specs, for
3029
example, creating temporary file names.
@@ -33,6 +32,10 @@ specs in a manner compatible with multiple Ruby implementations.
3332
configuration facility with a default project file and user-specific
3433
overrides.
3534

35+
5. MSpec support "tagging", that is excluding specs known as failing on
36+
a particular Ruby implementation, and automatically adding and removing tags
37+
while running the specs.
38+
3639
## Requirements
3740

3841
MSpec requires Ruby 2.3 or more recent.
@@ -63,29 +66,21 @@ After installing the gem dependencies, the specs can be run as follows:
6366
ruby -S bundle exec rspec
6467
```
6568

66-
Or
67-
68-
```bash
69-
ruby -S rake
70-
```
71-
7269
To run an individual spec file, use the following example:
7370

7471
```bash
7572
ruby -S bundle exec rspec spec/helpers/ruby_exe_spec.rb
7673
```
7774

78-
7975
## Documentation
8076

81-
See http://ruby.github.io/rubyspec.github.io/
82-
77+
See [CONTRIBUTING.md](https://github.com/ruby/spec/blob/master/CONTRIBUTING.md) in ruby/spec
78+
for a list of matchers and how to use `mspec`.
8379

8480
## Source Code
8581

8682
See https://github.com/ruby/mspec
8783

88-
8984
## License
9085

9186
See the LICENSE in the source code.

spec/mspec/lib/mspec/helpers/ruby_exe.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,12 +101,12 @@ def ruby_exe_options(option)
101101
end
102102
when :name
103103
require 'rbconfig'
104-
bin = RUBY_ENGINE + (RbConfig::CONFIG['EXEEXT'] || RbConfig::CONFIG['exeext'] || '')
104+
bin = RUBY_ENGINE + (RbConfig::CONFIG['EXEEXT'] || '')
105105
File.join(".", bin)
106106
when :install_name
107107
require 'rbconfig'
108108
bin = RbConfig::CONFIG["RUBY_INSTALL_NAME"] || RbConfig::CONFIG["ruby_install_name"]
109-
bin << (RbConfig::CONFIG['EXEEXT'] || RbConfig::CONFIG['exeext'] || '')
109+
bin << (RbConfig::CONFIG['EXEEXT'] || '')
110110
File.join(RbConfig::CONFIG['bindir'], bin)
111111
end
112112
end

spec/mspec/lib/mspec/matchers/complain.rb

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,25 @@
11
require 'mspec/helpers/io'
22

33
class ComplainMatcher
4-
def initialize(complaint)
5-
@complaint = complaint
4+
def initialize(complaint = nil, options = nil)
5+
# the proper solution is to use double splat operator e.g.
6+
# def initialize(complaint = nil, **options)
7+
# but we are trying to minimize language features required to run MSpec
8+
if complaint.is_a?(Hash)
9+
@complaint = nil
10+
@options = complaint
11+
else
12+
@complaint = complaint
13+
@options = options || {}
14+
end
615
end
716

817
def matches?(proc)
918
@saved_err = $stderr
1019
@verbose = $VERBOSE
1120
begin
1221
err = $stderr = IOStub.new
13-
$VERBOSE = false
22+
$VERBOSE = @options.key?(:verbose) ? @options[:verbose] : false
1423
Thread.current[:in_mspec_complain_matcher] = true
1524
proc.call
1625
ensure
@@ -54,7 +63,7 @@ def negative_failure_message
5463
end
5564

5665
module MSpecMatchers
57-
private def complain(complaint=nil)
58-
ComplainMatcher.new(complaint)
66+
private def complain(complaint = nil, options = nil)
67+
ComplainMatcher.new(complaint, options)
5968
end
6069
end

spec/mspec/lib/mspec/matchers/raise_error.rb

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ def matches?(proc)
1212
rescue Exception => actual
1313
@actual = actual
1414
if matching_exception?(actual)
15+
# The block has its own expectations and will throw an exception if it fails
16+
@block[actual] if @block
17+
1518
return true
1619
else
1720
raise actual
@@ -20,6 +23,7 @@ def matches?(proc)
2023

2124
def matching_exception?(exc)
2225
return false unless @exception === exc
26+
2327
if @message then
2428
case @message
2529
when String
@@ -29,9 +33,6 @@ def matching_exception?(exc)
2933
end
3034
end
3135

32-
# The block has its own expectations and will throw an exception if it fails
33-
@block[exc] if @block
34-
3536
return true
3637
end
3738

spec/mspec/lib/mspec/utils/warnings.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ def Warning.warn(message)
5151
when /hash\/shared\/index\.rb:\d+: warning: Hash#index is deprecated; use Hash#key/
5252
when /env\/shared\/key\.rb:\d+: warning: ENV\.index is deprecated; use ENV\.key/
5353
when /exponent(_spec)?\.rb:\d+: warning: in a\*\*b, b may be too big/
54-
when /enumerator\/(new|initialize_spec)\.rb:\d+: warning: Enumerator\.new without a block is deprecated/
54+
when /enumerator\/(new_spec|initialize_spec)\.rb:\d+: warning: Enumerator\.new without a block is deprecated/
5555
else
5656
$stderr.write message
5757
end

spec/mspec/spec/matchers/complain_spec.rb

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,4 +49,49 @@
4949
matcher.negative_failure_message.should ==
5050
["Expected warning not to match: /ou/", "but got: \"ouch\""]
5151
end
52+
53+
context "`verbose` option specified" do
54+
before do
55+
$VERBOSE, @verbose = nil, $VERBOSE
56+
end
57+
58+
after do
59+
$VERBOSE = @verbose
60+
end
61+
62+
it "sets $VERBOSE with specified second optional parameter" do
63+
verbose = nil
64+
proc = lambda { verbose = $VERBOSE }
65+
66+
ComplainMatcher.new(nil, verbose: true).matches?(proc)
67+
verbose.should == true
68+
69+
ComplainMatcher.new(nil, verbose: false).matches?(proc)
70+
verbose.should == false
71+
end
72+
73+
it "sets $VERBOSE with false by default" do
74+
verbose = nil
75+
proc = lambda { verbose = $VERBOSE }
76+
77+
ComplainMatcher.new(nil).matches?(proc)
78+
verbose.should == false
79+
end
80+
81+
it "does not have side effect" do
82+
proc = lambda { safe_value = $VERBOSE }
83+
84+
lambda do
85+
ComplainMatcher.new(nil, verbose: true).matches?(proc)
86+
end.should_not change { $VERBOSE }
87+
end
88+
89+
it "accepts a verbose level as single argument" do
90+
verbose = nil
91+
proc = lambda { verbose = $VERBOSE }
92+
93+
ComplainMatcher.new(verbose: true).matches?(proc)
94+
verbose.should == true
95+
end
96+
end
5297
end

spec/mspec/spec/matchers/raise_error_spec.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,18 @@ class UnexpectedException < Exception; end
7474
["Expected ExpectedException (expected)", "but got UnexpectedException (unexpected)"]
7575
end
7676

77+
it "provides a useful failure message when the proc raises the expected exception with an unexpected message" do
78+
exc = ExpectedException.new("unexpected")
79+
matcher = RaiseErrorMatcher.new(ExpectedException, "expected")
80+
81+
matcher.matching_exception?(exc).should == false
82+
lambda {
83+
matcher.matches?(Proc.new { raise exc })
84+
}.should raise_error(ExpectedException)
85+
matcher.failure_message.should ==
86+
["Expected ExpectedException (expected)", "but got ExpectedException (unexpected)"]
87+
end
88+
7789
it "provides a useful failure message when no exception is raised" do
7890
proc = Proc.new { 120 }
7991
matcher = RaiseErrorMatcher.new(ExpectedException, "expected")

spec/ruby/.travis.yml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,11 @@ matrix:
1515
env: CHECK_LEAKS=true
1616
- rvm: 2.6.0
1717
env: CHECK_LEAKS=true
18-
- rvm: ruby-head
1918
- env: RUBOCOP=true
2019
rvm: 2.4.5
2120
script:
2221
- gem install rubocop:0.61.0
2322
- rubocop
24-
allow_failures:
25-
- rvm: ruby-head
2623
branches:
2724
only:
2825
- master

0 commit comments

Comments
 (0)