我正在尝试在 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