实用程序员的RSpec书中的练习是编写一个名为Codebreakers的问题解决游戏。目的是使用Ruby中的Cucumber和Rspec来接触BDD。
以下是代码破解程序的目录树概述:
-features
-step_definitions
-codebreaker_steps
-support
-env.rb
-codebreaker_starts_game.feature
-codebreaker_submits_guess.feature
-lib
-codebreaker
-codebreaker.rb
-game.rb
-spec
-codebreaker
-game_spec
-spec_helper.rb
代码破解程序的LoadError消息:
rspec spec/codebreaker/game_spec.rb
/Documents/rubyProjects/codebreaker/spec/spec_helper.rb:1:in `require': cannot load such file -- codebreaker (LoadError)
from /Documents/rubyProjects/codebreaker/spec/spec_helper.rb:1:in `<top (required)>'
from /Documents/rubyProjects/codebreaker/spec/codebreaker/game_spec.rb:1:in `require'
from /Documents/rubyProjects/codebreaker/spec/codebreaker/game_spec.rb:1:in `<top (required)>'
spec / codebreaker / game_spec.rb需要'spec_helper':
require 'spec_helper'
module Codebreaker
describe Game do
describe "#start" do
it "sends a welcome message"
it "prompts for the first guess"
end
end
end
spec / spec_helper.rb需要'codebreaker',不按错误加载:
require 'codebreaker'
lib / codebreaker / codebreaker.rb需要codebreaker / game
require 'codebreaker/game'
LIB /密码破译者/ game.rb:
module Codebreaker
class Game
def initialize(output)
end
def start
end
end
end
赞赏建议和见解!
谢谢。
答案 0 :(得分:1)
我相信您需要在spec_helper.rb中将您的要求更改为此
require 'codebreaker/codebreaker'
因为您的lib目录树看起来像这样
-lib
-codebreaker
-codebreaker.rb
-game.rb