[英]uninitialized constant BikeShare (NameError)
I'm trying to implement some simple testing in rspec for a gem I'm writing. 我正在尝试在rspec中为我正在编写的gem进行一些简单的测试。 When I comment out
describe BikeShare do
down to end
and run the file, the file loads in and runs successfully. 当我注释掉
describe BikeShare do
end
运行该文件时,该文件将加载并成功运行。 I'm sure it's something tiny I'm missing. 我确定这是我所想不到的东西。
My test file is really simple and looks like this: 我的测试文件非常简单,看起来像这样:
require 'spec_helper'
describe BikeShare do
it "should run" do
# response = BikeShare.new
# response.should_be present
end
end
When run, I get the error uninitialized constant BikeShare (NameError)
at line 3. 运行时,在第3行出现错误
uninitialized constant BikeShare (NameError)
。
My bikeshare.rb
file looks like this, fairly simple: 我的
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
My Rakefile
looks like this: 我的
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
Your tests arent aware of BikeShare. 您的测试没有意识到BikeShare。
You need to require the file that defines your BikeShare class. 您需要提供定义BikeShare类的文件。 I dont use rspec but I think that you normally set up your testing environment in
spec_helper.rb
. 我不使用rspec,但我认为您通常在
spec_helper.rb
设置测试环境。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.