首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用Rails 5进行敏捷Web开发,测试失败

使用Rails 5进行敏捷Web开发,测试失败
EN

Stack Overflow用户
提问于 2018-01-04 05:02:55
回答 1查看 99关注 0票数 0

嗨,我运行了测试,似乎他失败了,我找不到有什么特别的错误。以下是一条信息:

代码语言:javascript
复制
Failure:
ProductsControllerTest#test_can't_delete_product_in_cart [/home/magvin/work/depot/test/controllers/products_controller_test.rb:53]:
"Product.count" didn't change by 0.
Expected: 3
  Actual: 2

这样他就不会删除。我也查看了model/product.rb,看起来一切正常。

代码语言:javascript
复制
class Product < ApplicationRecord
    has_many :line_items
    before_destroy :ensure_not_referenced_by_any_line_item

    validates :title, :description, :image_url, presence: true
    validates :price, numericality: {greater_than_or_equal_to: 0.01, message: "%{value} seems wrong"}
    validates :title, uniqueness: true
    validates :image_url, allow_blank: true, format: { 
        with: %r{\.(gif|jpg|png)\z}i,
        message: 'must be GIF, JPG or PNG file.'
    } #i stands for case insensitive
    validates :title, :length => {:minimum => 2}
    validates :description, :length => { :in => 3..150 }

    #...
    #...

    private

    #ensure that there are no line items referencing this product

    def ensure_not_referenced_by_any_line_item
        unless line_items.empty?
            errors.add(:base, 'Line Items Presents')
            throw :abort
        end
    end
end

我也在测试失败的地方重新检查了一行,计算了解错误的地方。

代码语言:javascript
复制
  test "can't delete product in cart" do
assert_difference('Product.count', 0) do
  delete product_url(products(:two))
end

assert_redirected_to products_url
end
EN

回答 1

Stack Overflow用户

发布于 2018-01-05 04:46:28

是fixture问题:)改变了,一切都正常了)

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/48085086

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档