我正试图在rspec中为我正在写的一个gem实现一些简单的测试。当我将describe BikeShare do
注释掉到end
并运行该文件时,该文件将加载并成功运行。我相信这是我错过的小事。未初始化的常量BikeShare(NameError)
我的测试文件是非常简单的,看起来像这样:
require 'spec_helper'
describe BikeShare do
it "should run" do
# response = BikeShare.new
# response.should_be present
end
end
运行时,我得到的错误uninitialized constant BikeShare (NameError)
在第3行
我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
我不使用rspec,所以我可能会错,但它是如何知道你的自行车共享类?你可能只需要它。 –
工作。谢谢!如果你想写一个答案,很高兴给你信用。 –