title: Rspec test doesn't work well
body: <h3>What I want to do</h3>
  
  <p>I want to examine if an action that includes some processes about changing databases of the controller works successfully.</p>
  
  <h3>errors</h3>
  
  <p>"no save"
    F</p>
  
  <p>Failures:</p>
  
  <p>1) BuysController check #new's behavior return done
       Failure/Error: expect(buy.trading_status).to eq("done")</p>
  
  <pre><code>   expected: "done"
          got: "pending"
  
     (compared using ==)
   # ./spec/controllers/buys_controller_spec.rb:27:in `block (3 levels) in &lt;top (required)&gt;'
  </code></pre>
  
  <p>Finished in 0.14739 seconds (files took 3.68 seconds to load)
    1 example, 1 failure</p>
  
  <p>Failed examples:</p>
  
  <p>rspec ./spec/controllers/buys_controller_spec.rb:6 # BuysController check #new's behavior return done</p>
  
  <h3>code</h3>
  
  <pre><code>require 'rails_helper'
  include BuysHelper
  
   RSpec.describe BuysController, type: :controller do
        describe "check #new's behavior" do
         it "return done" do
          User.create(name:"hhhvv",email:"gggjggg@gmail.com")
         p User.find(1)
         Currency.create(name:"hello",user_id:1)
         Sell.create(
             id:1,
            user_id: 1,
           currency_id:1,
            amount:100,
            price:100,
           trading_status:"pending")
         buy = Buy.new(
             id:1,
             user_id: 1,
             currency_id:1,
             amount:100,
             price:100,
            trading_status:"pending"
            )
        if buy.save
            market_checker
         else
            p "no save"
          end
          expect(buy.trading_status).to eq("done")
       end
      end
   end
  </code></pre>
  
  <h3>What I have tried</h3>
  
  <pre><code>  rake db:test:prepare 
    rake db:migrate RAILS_ENV=test
  </code></pre>