2016-09-08 8 views
0

私はレールとrspecを学習しており、簡単なカートシステムを備えたアプリケーションを作成しました。それをテストするために、私は、しかし、私はかなり理解していないエラーに遭遇しましたが、要求仕様を書いた私のスペックは以下のとおりです。商品をショッピングカートに追加する

context 'add item to cart' do 
    Given!(:product){FactoryGirl.create(:product)} 
    Given {get "/"} 
    When {xhr get "/line_items?product_id=#{product.id}"} 
    Then { response.body.include? 'class="item_price"' } 
    end 

と指定されたエラーは次のとおりです。

Failure/Error: When {xhr get "/line_items?product_id=#{product.id}"} 

    ArgumentError: 
     wrong number of arguments (given 1, expected 2+) 

私はこれにはとても新しいので、何をすべきかわかりません。

答えて

0

ソリューションは、ことになった:

context "add item to cart" do 
    Given!(:product){FactoryGirl.create(:product)} 
    Given {get "/"} 
    When {xhr :post, "/line_items?product_id=#{product.id}"} 
    Then { response.body.include? "item_price" } 
    end 
xhr "get", "/line_items?product_id=#{product.id}" はこれを試してみてください
0

XHRは、より多くのパラメータを期待している:

context 'add item to cart' do 
    Given!(:product){FactoryGirl.create(:product)} 
    Given {get "/"} 
    When {xhr "get", "/line_items?product_id=#{product.id}"} 
    Then { response.body.include? 'class="item_price"' } 
    end 
関連する問題