我得到 NameError 未初始化的常量,如下所示:
Failures:
1) Direction turn right faced south rotates to west
Failure/Error: expect(Move.right(Direction::South)).to eq(Direction::West)
NameError:
uninitialized constant Move
# ./spec/unit_tests/direction_spec.rb:11:in `block (4 levels) in <top (required)>'
2) Direction turn right faced west rotates to north
Failure/Error: expect(Move.right(Direction::West)).to eq(Direction::North)
NameError:
uninitialized constant Move
# ./spec/unit_tests/direction_spec.rb:16:in `block (4 levels) in <top (required)>'
3) Direction turn right faced north rotates to east
Failure/Error: expect(Move.right(Direction::North)).to eq(Direction::East)
NameError:
uninitialized constant Move
# ./spec/unit_tests/direction_spec.rb:21:in `block (4 levels) in <top (required)>'
4) Direction turn right faced east rotates to south
Failure/Error: expect(Move.right(Direction::East)).to eq(Direction::South)
NameError:
uninitialized constant Move
# ./spec/unit_tests/direction_spec.rb:26:in `block (4 levels) in <top (required)>'
Finished in 0.02345 seconds
14 examples, 4 failures
这是我的代码:
require_relative '../spec_helper'
require 'direction'
describe Direction do
subject(:Move) { Direction::Move.new }
describe 'turn right' do
context 'faced south' do
it 'rotates to west' do
expect(Move.right(Direction::South)).to eq(Direction::West)
end
end
context 'faced west' do
it 'rotates to north' do
expect(Move.right(Direction::West)).to eq(Direction::North)
end
end
context 'faced north' do
it 'rotates to east' do
expect(Move.right(Direction::North)).to eq(Direction::East)
end
end
context 'faced east' do
it 'rotates to south' do
expect(Move.right(Direction::East)).to eq(Direction::South)
end
end
end
end
主题不工作是否有原因?我也试过let
,但这也不起作用