# How to run a before action method in rspec. I am getting this error

**URL:** <https://www.ruby-forum.com/t/how-to-run-a-before-action-method-in-rspec-i-am-getting-this-error/260761>\
**Category:** Rails\
**Tags:** rspec\
**Created:** [January 5, 2021, 6:40am UTC](https://www.ruby-forum.com/t/how-to-run-a-before-action-method-in-rspec-i-am-getting-this-error/260761 "2021-01-05T06:40:58Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![suhasmv](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/e95f7d/32.png) [@suhasmv](https://www.ruby-forum.com/u/suhasmv)\
**Post date:** [January 5, 2021, 6:40am UTC](https://www.ruby-forum.com/t/how-to-run-a-before-action-method-in-rspec-i-am-getting-this-error/260761/1 "2021-01-05T06:40:58Z")

</div>

Hello I,m new to rails

I am writing test cases for using rspec gem

In my controller I have edit function. I have before action for edit function  
**This is my controller**

```auto
before_action :authorize_user, only: %i[edit update destroy]
def edit
end

**private**

  def authorize_user
    id = Question.find(params[:id]).user_id
    redirect_to root_path if id != current_user.id
  end

```

**This is my rspec/requests/question\_rspec.rb**

```auto
  describe "GET /edit" do
    before do
      sign_in(create(:user)) # Factory Bot user
    end
    it "render a successful response" do
      question = create(:question) #Factory bot question
      # question.user = current_user
      question.save
      get edit_question_url(question)
      expect(response).to be_successful
    end

  end

```

**I’m getting an error like**

```auto
Failure/Error: expect(response).to be_successful
       expected `#<ActionDispatch::TestResponse:0x00005652448f4c50 @mon_data=#<Monitor:0x00005652448f4c00>, @mon_data_..., @method=nil, @request_method=nil, @remote_ip=nil, @original_fullpath=nil, @fullpath=nil, @ip=nil>>.successful?` to be truthy, got false
     # ./spec/requests/questions_spec.rb:105:in `block (3 levels) in <main>'

```

**Could anyone please let me know**
