Skip to content

Commit 096736d

Browse files
authored
Merge pull request #95 from rspec/fix-example-usage
Fix example usage
2 parents 14297a7 + 0fd24f5 commit 096736d

File tree

4 files changed

+31
-11
lines changed

4 files changed

+31
-11
lines changed

.github/workflows/ci.yml

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,6 @@ jobs:
3535
- ruby: jruby-9.2.13.0
3636
env:
3737
JRUBY_OPTS: "--dev"
38-
- ruby: jruby-9.1.17.0
39-
bundler: 1
40-
os: ubuntu-18.04
41-
env:
42-
JRUBY_OPTS: "--dev"
4338
# Compatibility builds
4439
- ruby: '3.2'
4540
name_extra: "against RSpec 3.12"
@@ -110,18 +105,24 @@ jobs:
110105
legacy:
111106
name: Legacy Ruby Builds (${{ matrix.container.version }})
112107
runs-on: ubuntu-20.04
113-
container: ${{ matrix.container.tag }}
108+
container:
109+
image: ${{ matrix.container.tag }}
110+
options: ${{ matrix.container.options || '--add-host github-complains-if-this-is-empty.com:127.0.0.1' }}
114111
strategy:
115112
fail-fast: false
116113
matrix:
117114
container:
118115
- version: "2.0"
119-
tag: rspec/ci:2.0.0
116+
tag: ghcr.io/rspec/docker-ci:2.0.0
120117
- version: "1.9.3"
121-
tag: rspec/ci:1.9.3
118+
tag: ghcr.io/rspec/docker-ci:1.9.3
122119
- version: "JRuby 1.7"
123-
tag: rspec/ci:jruby-1.7
120+
tag: ghcr.io/rspec/docker-ci:jruby-1.7
121+
- version: "JRuby 9.1.17.0"
122+
tag: ghcr.io/rspec/docker-ci:jruby-9.1.17.0
123+
options: "--add-host rubygems.org:151.101.129.227 --add-host api.rubygems.org:151.101.129.227"
124124
env:
125+
ACTIONS_ALLOW_USE_UNSECURE_NODE_VERSION: true
125126
LEGACY_CI: true
126127
JRUBY_OPTS: ${{ matrix.container.jruby_opts || '--dev' }}
127128
steps:

Gemfile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,11 @@ gemspec
66
%w[rspec rspec-core rspec-expectations rspec-mocks rspec-support].each do |lib|
77
branch = ENV.fetch('BRANCH','main')
88
library_path = File.expand_path("../../#{lib}", __FILE__)
9+
910
if File.exist?(library_path) && !ENV['USE_GIT_REPOS']
1011
gem lib, :path => library_path
12+
elsif lib == 'rspec'
13+
gem 'rspec', :git => "https://github.com/rspec/rspec-metagem.git", :branch => branch
1114
else
1215
gem lib, :git => "https://github.com/rspec/#{lib}.git", :branch => branch
1316
end

lib/rspec/its.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
require 'rspec/its/version'
22
require 'rspec/core'
33

4+
RSpec::Core::ExampleGroup.define_example_method :__its_example
5+
46
module RSpec
57
module Its
68

@@ -166,7 +168,7 @@ def should_not(matcher=nil, message=nil)
166168
options << {} unless options.last.kind_of?(Hash)
167169
options.last.merge!(:caller => its_caller)
168170

169-
example(nil, *options, &block)
171+
__its_example(nil, *options, &block)
170172

171173
end
172174
end

spec/rspec/its_spec.rb

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ module RSpec
99
its([]) { expect(described_class).to be Its }
1010
end
1111
end
12+
1213
context "with explicit subject" do
1314
subject do
1415
Class.new do
@@ -269,7 +270,6 @@ def bad
269270
end
270271

271272
its(:good) { will_not raise_error }
272-
its(:bad) { will raise_error }
273273
its(:bad) { will raise_error(ArgumentError) }
274274
its(:bad) { will raise_error("message") }
275275
its(:bad) { will raise_error(ArgumentError, "message") }
@@ -375,6 +375,20 @@ def terminator
375375
raise_error(ArgumentError, '`will_not` only supports block expectations')
376376
end
377377
end
378+
379+
context "when example is redefined" do
380+
subject do
381+
Class.new do
382+
def will_still_work; true; end
383+
end.new
384+
end
385+
386+
def self.example(*_args)
387+
raise
388+
end
389+
390+
its(:will_still_work) { is_expected.to be true }
391+
end
378392
end
379393
end
380394
end

0 commit comments

Comments
 (0)