在特定命名空间中测试

meg*_*gas 4 ruby rspec

我正在尝试测试命名空间中的一些类,目前我有以下代码:

describe Server::SessionController do

  it "should create session" do
    Server::LoginController.stub(:authenitcate).and_return(session_id)
    Server::SessionController....
    Server::SessionController....
  end
end
Run Code Online (Sandbox Code Playgroud)

如何摆脱可重复的Server命名空间?

Ber*_*rdK 5

RSpec Book ( http://pragprog.com/book/achbd/the-rspec-book ) 给出了一个解决方案:

3 module Codebreaker
4    describe Game do
5        describe "#start" do
Run Code Online (Sandbox Code Playgroud)

... 第二个语句声明了一个名为 Codebreaker 的 Ruby 模块。这不是运行规范所必需的,但它提供了一些便利。例如,我们不必完全限定第 4 行的 Game。

所以,试着把你的规范放在一个Server模块中。哈。