简体   繁体   中英

uninitialized constant BikeShare (NameError)

I'm trying to implement some simple testing in rspec for a gem I'm writing. When I comment out describe BikeShare do down to end and run the file, the file loads in and runs successfully. 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.

My bikeshare.rb file looks like this, fairly simple:

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:

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.

You need to require the file that defines your BikeShare class. I dont use rspec but I think that you normally set up your testing environment in spec_helper.rb .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM