title: How to use the allow method in RSpec to mock a function inside a controller that is inside a module (Module > Controller > Function)
body: <p>I am trying to write the <code>allow</code> method in RSpec. My rails controller is</p>
  <pre><code>module Users
    class ProfilesController &lt; ApplicationController
  
      # Update user profile
      def update
  
        payload = { name: params[:user][:name],email: params[:user][:email]}
        response = send_request_to_update_in_company(payload)
        if response['code'] == 200
          if  User.first.update(user_params) 
            render json: { message: &quot;User successfully updated&quot;}, status: :ok
          else
            head :unprocessable_entity
          end
        else
         render json: { error: 'Error updating user in Company' },status: :unprocessable_entity
       end
  
     end
  
     private
  
     def send_request_to_update_in_comapny(payload)
      response = Api::V1::CompanyRequestService.new(
        payload: payload.merge(company_api_access_details),
        url: 'customers/update_name_email',
        request_method: Net::HTTP::Post
        ).call
      JSON.parse(response.body)
     end
    end
  end
  </code></pre>
  <p>When I write the bellow code in my test file</p>
  <pre><code>allow(Users::ProfilesController).to receive(:send_request_to_update_in_company).and_return({ 'code' =&gt; 500 })
  </code></pre>
  <p>I am getting the following error in terminal</p>
  <pre><code>Users::ProfilesController does not implement: send_request_to_update_in_comapny
  enter code here
  </code></pre>
  <p>With allow_any_instance_of I am able to get the code working. But how can I implement it using allow?</p>