Rspec test to request controller action but seems action wasn't executed

1k views Asked by At

I am new to Rails and Rspec and trying to write spec to test one non RESTful controller action.

Spec code:

require 'rails_helper'

RSpec.describe ReportsController, type: :controller do
  describe "GET /full_members" do
    context "when current account doesn't have contacts" do
      let!(:current_account) { create(:account) }

      it "hit full_members action" do
        expect(get: '/reports/full_members').to be_routable

        expect(:get => "/reports/full_members").to route_to(
          controller: "reports",
          action: "full_members")

        get :full_members

      end
    end
  end
end

Controller code:

class ReportsController < ApplicationController
  def full_members
    require "pry"
    binding.pry
    
    set_select_options_full_members
    @members = @current_account.contacts
  end
...

I was expecting to execute spec and stop at the breaking point pry. But the actual result is spec passed and pry didn't work.

Finished in 0.17359 seconds (files took 1.16 seconds to load)
1 example, 0 failures

From rails routes I can see the route exists(the spec first two assertions also prove that)

~ยป rails routes | ag full_members                                                                     
>> full_members_reports GET    /reports/full_members(.:format)  

My routes.rb

resources :reports, only: [:index] do
    collection do
      get 'full_members'
    end
end

Can not figure out why the pry didn't work in controller action. Can anyone help with that? Thanks

0

There are 0 answers