简体   繁体   中英

Utilizing RSpec w/ Capybara on Rails 4.2

In my app/controllers/pet_controller.rb file I have some code

class PetsController < ApplicationController
  before_action :set_pet, only: [:show, :edit, :update, :destroy]
  before_action :process_params, only: [:create, :edit]
  # GET /pets
  # GET /pets.json
  def index
    @pets = Pet.find_by_sql ["SELECT * FROM pets WHERE \"userId\" = ?", params[:userId].to_i]
  end
.
.
.

I have some code in my spec/pets_spec.rb that looks like

describe PetsController do
    describe 'GET #index' do
        it { is_expected.to respond_with :ok }
    end
end

To have a simple test if the controller responds correctly. When I invoke bundle exec rspec , I get a

/spec/pets_spec.rb:1:in `<top (required)>': uninitialized constant PetsController (NameError)

I am very new to using this testing tool, any help to get this started would be greatly appreciated.

-Otterman

You probably didn't install rspec all the way for Rails.

Read this introduction .

That will generate two files: spec/spec_helper.rb and spec/rails_helper.rb . Open those up and read the comments of how they work and what they are for.

Then run bundle exec rake spec or bundle exec rspec spec .

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