Ruby RSpec单元测试给出未定义的方法错误

Ruby RSpec单元测试给出未定义的方法错误,ruby,unit-testing,rspec,Ruby,Unit Testing,Rspec,我已经使用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' req

我已经使用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_项调用正确。但当它得到_字符串时,我得到一个错误:

#App:0x2eaqc4600的未定义方法get_字符串


谢谢。

看起来像是命名空间问题。我不知道您的环境,但您确定@var是AppModule::App的一个实例,而不仅仅是::App吗?

(不相关,但您知道
str=get_string
,即使它起作用,也会将
str
设置为
nil
,对吗?)