简体   繁体   中英

How to get RSpec to test controllers in subdirectories?

I have some controllers that are in subdomains of the controllers folder.

for example, i have a controller in app/controllers/api/v1/offers_controller.rb that looks like this:

class Api::V1::OffersController < ApplicationController
  respond_to :json

  def index
   ...some code here
  end
end

I tried putting a controller in spec/controllers/api/v1/offers_controller.rb that looks like this:

require 'spec_helper'

descripe Api::V1::OffersController do
  describe "GET 'index'" do
    it "returns http success" do
      get 'index'
      response.should be_success
    end
  end
end

however, when I run rspec spec , this test does not get run at all. I also tried putting it in the spec/controllers directory, named api_v1_offers_controller.rb, and the test is still not run.

How can I write RSpec tests for these types of controllers?

It actually seems it was a mistake it how I named the file. it seems all RSpec tests need to end it _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