[英]uninitialized constant BikeShare (NameError)
我正在尝试在rspec中为我正在编写的gem进行一些简单的测试。 当我注释掉describe BikeShare do
end
运行该文件时,该文件将加载并成功运行。 我确定这是我所想不到的东西。
我的测试文件非常简单,看起来像这样:
require 'spec_helper'
describe BikeShare do
it "should run" do
# response = BikeShare.new
# response.should_be present
end
end
运行时,在第3行出现错误uninitialized constant BikeShare (NameError)
。
我的bikeshare.rb
文件看起来像这样,非常简单:
class BikeShare
def initialize
response = JSON.parse(open("http://bayareabikeshare.com/stations/json").read)
@response = response["stationBeanList"]
end
def get_last_station
@response.last["id"]
end
end
我的Rakefile
看起来像这样:
require 'rubygems'
require 'bundler'
Bundler.setup
Bundler::GemHelper.install_tasks
require 'rspec/core/rake_task'
RSpec::Core::RakeTask.new do |spec|
# spec.libs << 'lib' << 'spec'
spec.pattern = 'spec/*_spec.rb'
end
task :default => :spec
您的测试没有意识到BikeShare。
您需要提供定义BikeShare类的文件。 我不使用rspec,但我认为您通常在spec_helper.rb
设置测试环境。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.