私は現在、請求書の作成を含む作業用のイントラネットに取り組んでいます。
テストを書いている間、私はテストにRspecとCapybaraを使用しており、リクエストテストを実行している間、請求書を作成し、バットが正しく計算されることを確認するためにいくつかの項目を追加したいと思います。
ただし、Capybaraが最初の#item_priceを見つけて、新しく作成されたアイテムの代わりにそれに一致させようとするという問題が発生しているようです。
以下は私のリクエストテストのコードの一部です。
...
...
# Laptop for 369.96 inc vat
click_link "Add Item"
fill_in "Quantity", :with => 1
fill_in "Price", :with => 369.96
fill_in "Description", :with => "laptop for 369"
click_button "Create Item"
page.should have_content("Item was successfully created")
find('#item_quantity').should have_content(1)
find('#item_price').should have_content(369.96)
find('#item_description').should have_content("laptop for 369")
find('#item_total').should have_content(369.96)
find('#invoice_subtotal').should have_content(308.30)
find('#invoice_vat').should have_content(61.66)
find('#invoice_total').should have_content(369.96)
# Laptop for 337.53 inc vat
click_link "Add Item"
fill_in "Quantity", :with => 1
fill_in "Price", :with => 337.53
fill_in "Description", :with => "laptop for 337"
click_button "Create Item"
page.should have_content("Item was successfully created")
find('#item_quantity').should have_content(1)
### the offending code below
find('#item_price').should have_content(337.53)
###
find('#item_description').should have_content("laptop for 337")
...
...
#item_price_2
2がアイテムIDになる場所を追加できるようにしたいと思います。これを行ってに変更find('#item_price').should have_content(337.53)
するfind('#item_price_#{invoice.id}').should have_content(337.53)
と、例外が発生します。
Nokogiri::CSS::SyntaxError:
unexpected '#' after '[#<Nokogiri::CSS::Node:0x007f991889f270 @type=:CONDITIONAL_SELECTOR, @value=[#<Nokogiri::CSS::Node:0x007f991889f3d8 @type=:ELEMENT_NAME, @value=["*"]>, #<Nokogiri::CSS::Node:0x007f991889f9c8 @type=:ID, @value=["#item_price_"]>]>]'
また、二重引用符に変更すると、"#item_price_{invoice.id}"
この例外が発生します。
undefined local variable or method
#の請求書
これは、FactoryGirlを使用していないためinvoice
、メソッドとして設定されていないためだと思います。ユーザーが請求書とアイテムのフォームをどのように操作するかをテストしたいので、今回はFactoryGirlを使用していません。
この問題を解決するための最良の方法は何でしょうか?私がやろうとしていることを行うためのより良い方法はありますか?
よろしくお願いします!