https://gist.github.com/7wQvRTU2/3c95e82943d2640986fe6bf53a73cb01
下:
describe('#anagram_check')
我正在测试:
it("returns similar letters if not an anagram") do
testing = AnagramCheck.new("quick", "quack'")
expect(testing.anagram_check()).to(eq("Not an Anagram or an Antigram but "
+ (@word1 - antigram).join(',') + " " + "are alike"))
end
但是得到:
NameError:
undefined local variable or method `antigram' for
#<RSpec::ExampleGroups::AnagramCheck:0x007f97f11980d0>
# ./spec/anagram_test_spec.rb:20:in `block (2 levels) in <top (required)>'
从我读到的内容来看,它与范围有关吗?
也许涉及让吗?
如何在RSpec中正确格式化此格式,以便可以测试从方法内部返回变量的方法输出?
答案 0 :(得分:1)
如果您希望它在整个规范中都可用,请将其放在文件顶部。
RSpec.describe Whatever do
context 'something' do
describe 'some function' do
context 'with new record' do
let(:mode) { create(:mode) }
...
it 'returns similar letters if not an anagram' do
...
然后,您不必继续声明它。如果是那样的话。