2012-08-13 36 views
0

我已經使用RSpec創建了一個單元測試。Ruby RSpec單元測試給出了未定義的方法錯誤

的app.rb有:

module AppModule 
    class App 
    def get_item 
     str = self.get_string 
     puts "in get_item - #{str}" 
    end 

    def get_string 
     puts "hello, world" 
    end 
    end 
end 

的app_test.rb有:

require 'test_helper' 
require 'env' 

describe App do 
    before :each do 
    @var = App.new 
    end 

    describe "firsttest" do 
    it "should print string" do 
     @var.get_item 
    end 
    end 
end 

我發現的是,get_item正確調用。但是,當它到達get_string,我得到一個錯誤:

爲#APP

未定義的方法get_string:0x2eaqc4600

感謝。

+0

(不相關,但你知道'str = get_string',即使它工作了,也會將'str'設置爲'nil',對不對?) – 2012-08-13 23:23:34

回答

0

看起來像一個命名空間問題。我不知道你的環境,但你確定@var是一個AppModule :: App的實例,而不僅僅是:: App?

相關問題