Skip to content

Instantly share code, notes, and snippets.

@y0t4
Last active December 22, 2023 06:17
Show Gist options
  • Save y0t4/5d8b4ef4462dba7db98e0d6d9c7c2da0 to your computer and use it in GitHub Desktop.
Save y0t4/5d8b4ef4462dba7db98e0d6d9c7c2da0 to your computer and use it in GitHub Desktop.
rspec-parameterized使っていてletされた変数へのアクセスで不思議な挙動があったので、その挙動を再現したコード
require 'bundler/inline'
gemfile do
source 'https://rubygems.org'
gem 'rspec'
gem 'rspec-parameterized'
end
require 'rspec'
require 'rspec-parameterized'
# super: no superclass method `foo' for #<RSpec::ExampleGroups::FailureCase::Context1::Context2 (no description provided)>
describe "Failure case" do
let(:foo) { 'foo' }
context 'context1' do
let(:bar) { 'bar' }
context 'context2' do
where(:expected_string) do
[
[foo], # ここは ref(:foo) を使わないといけない
]
end
with_them do
it "return foo" do
expect(foo).to eq expected_string
end
end
end
end
end
require 'bundler/inline'
gemfile do
source 'https://rubygems.org'
gem 'rspec'
gem 'rspec-parameterized'
end
require 'rspec'
require 'rspec-parameterized'
describe "Success case" do
let(:foo) { 'foo' }
context 'context1' do
context 'context2' do
let(:bar) { 'bar' }
where(:expected_string) do
[
[foo], # ここは ref(:foo) を使わないといけないはずだが、これでも動く
]
end
with_them do
it "return foo" do
expect(foo).to eq expected_string
end
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment