title: How to create stub methods in rails 5 and minitest
body: <p>I have the following code and I am trying to create a stub for it so I can place tests without it making a real order.</p>
  
  <pre><code>def order
      client = StraightServerKit::Client.new(
          gateway_id: "123",
          secret: "123"
      )
      o = StraightServerKit::Order.new(amount: 1)
      mycelium_order = client.orders.create(o)
  end
  </code></pre>
  
  <p>How do I stub the create method? This is my attempt but it doesn't call the stubbed method and tries to make a real api call (this method => client.orders.create(o))</p>
  
  <pre><code>test "should create order" do
    mock = Minitest::Mock.new
    def mock.apply; true; end
  
    client =  StraightServerKit::Client.new(
      gateway_id: "xxx",
      secret: "xxx"
    )
  
    client.orders.stub :create, mock do
    {
      return_data = "data"
    }
  
    post post_order_path, params: { order: { amount: 10 } }
    assert_response :success
  end
  </code></pre>
  
  <p>METHOD1</p>
  
  <p>Have updated using the stub_any_instance gem but still not working due to the method being nested</p>
  
  <pre><code>require 'minitest/stub_any_instance'
  test "should create order" do
      client = StraightServerKit::Client.new(
        gateway_id: "asdf",
        secret: "asdf"
      );
      client.stub_any_instance(:order, "data")
  
      post post_order_path, params: { order: { amount: 10 } }
      assert_response :success
  
    end
  </code></pre>
  
  <p>Error:
  DashboardControllerTest#test_should_create_order:
  NoMethodError: undefined method `stub_any_instance' for #
  (although stub_any_instance works fine with stubbing String.length)</p>
  
  <p>METHOD2:</p>
  
  <pre><code>require 'mocha/mini_test'
  test "should create order" do
      StraightServerKit::Client.any_instance.stubs(:new).returns("test")
  
      post post_order_path, params: { order: { amount: 10 } }
      assert_response :success
    end
  </code></pre>
  
  <p>this loads the real implementation rather than the stub</p>
  
  <p>METHOD3:</p>
  
  <pre><code>test "should create order" do
      StraightServerKit::Client.stub_any_instance(:new, "data")
  
      post post_order_path, params: { order: { amount: 10 } }
      assert_response :success
    end
  </code></pre>
  
  <p>DashboardControllerTest#test_should_create_order:
  NameError: undefined method <code>new' for class</code>StraightServerKit::Client'</p>