`
jarry-li
  • 浏览: 41589 次
  • 性别: Icon_minigender_1
  • 来自: 上海
社区版块
存档分类
最新评论
阅读更多

今天重新在depot运行测试,用静态测试数据测试商品标题的唯一性,发现有个断言过不去:

 

assert_equal I18n.translate('activerecord.errors.messages.taken'), product.errors[:title]

错误信息:

 

 

  1) Failure:
test_product_is_not_valid_without_a_unique_title_-_i18n(ProductTest) [E:/works/rubyaptana/rails/test/unit/product_test.rb:67]:
<"has already been taken"> expected but was
<["has already been taken"]>.

5 tests, 24 assertions, 1 failures, 0 errors, 0 skips

 

 

后面发现在是因为没有照Agile Web Development with Rails Fourth Edition书上说的写。product.errors[:title]后还有join("; ")

看日志应该是一个字符串,和一个只有一个字符串元素的数组的区别。

经乱试,发现两种方式都可以通过:

1.

 

assert_equal I18n.translate('activerecord.errors.messages.taken'), product.errors[:title].join("")

 2.

assert_equal I18n.translate(['activerecord.errors.messages.taken']), product.errors[:title]

 

product_test.rb的测试方法是这样的:

  test "product is not valid without a unique title - i18n" do
    product = Product.new(title:       products(:ruby).title,
                          description: "yyy", 
                          price:       1, 
                          image_url:   "fred.gif")

    assert product.invalid?
    assert_equal I18n.translate(['activerecord.errors.messages.taken']), product.errors[:title]
    #assert_equal I18n.translate('activerecord.errors.messages.taken'), product.errors[:title].join("")
   end

 

 

1
0
分享到:
评论

相关推荐

    assert_param-转载.txt

    assert_param-转载

    GENESIS 2000 DFM PE

    The DFM Programming Environment is one of the many unique concepts of the Genesis 2000 system. Unlike any existing tool, the DFM Programming Environment (DFMPE) enables any user with elementary ...

    minitest-ok:'ok {1 + 1} == 2',而不是'assert_equal 2,1 + 1'

    ok { 1 + 1 } == 2 # same as assert_equal 2, 1+1 ok { 1 + 1 } &gt; 1 # same as assert_operator 1+1, :&gt;, 1 ok { '123' } =~ / \d +/ # same as assert_match /\d+/, '123' ok { [ ] } . kind_of? ( Array ) # ...

    Python库 | pytest_cache_assert-1.1.1.tar.gz

    资源分类:Python库 所属语言:Python 资源全名:pytest_cache_assert-1.1.1.tar.gz 资源来源:官方 安装方法:https://lanzao.blog.csdn.net/article/details/101784059

    STM32中assert_param的使用

    STM32中assert_param的使用,综合网上多种说法,看完不一样的感觉。

    关于assert_param的疑惑

    本文是关于assert_param的疑惑。

    assert_matches:提供宏`assert_matches`来测试模式匹配

    assert_matches 提供一个... 要包含在您的项目中,仅当编译测试时,才将以下内容添加到您的Cargo.toml中: [ dev-dependencies ]assert_matches = " 1.5 " 并将以下内容添加到您的板条箱根目录中: #[cfg(test)] #[m

    ZendFramework中文文档

    2.3.2. 使用声明(Assert)来编写条件性的 ACL 规则 3. Zend_Auth 3.1. 简介 3.1.1. 适配器 3.1.2. 结果 3.1.3. 身份的持久(Persistence) 3.1.3.1. 在PHP Session 中的缺省持久(Persistence) 3.1.3.2. 实现...

    contract:合约帮手

    合约帮手 该模块提供了一种在函数中...assert_equal 6 , Foo . new . foo ( 2 , 3 ) assert_equal false , Foo . new . foo ( 2 , "3" ) 当包含Contract模块时,方法contract和verify变得可用。 class Bar inclu

    人体姿态估计的强大算法

    parse_matlab\util\assert.m parse_matlab\util\printSkel.m parse_matlab\util\sampleWithR.m parse_matlab\util\isum.m parse_matlab\util\buildHistExps.m parse_matlab\util\local_sum_zero.m parse_...

    junit的jar包

    junit.framework.Assert.class junit.framework.AssertionFailedError.class junit.framework.ComparisonCompactor.class junit.framework.ComparisonFailure.class junit.framework.JUnit4TestAdapter.class junit....

    计算机图形学

    void CMyView::OnInitialUpdate() { CView::OnInitialUpdate(); BITMAP bm; // Windows BITMAP data structure; see Win32 help m_pBitmap[0].LoadBitmap(IDB_BITMAP1);... ASSERT(nTimer!=0); }

    assert,assert_valid,verify,trace用法

    对于开始学vc的人,对于assert,assert_valid,verify,trace的宏感到很奇怪,总是觉得很难掌握似的,其实这些主要是没有理清楚他们各自宏之间深层次的意义。

    assert_reached:详细说明constexpr滥用以启用ASSERT_REACHED

    提供对ASSERT_REACHED和ASSERT_REACHED_BEGIN / END的访问,可以按以下方式使用: # include &lt; iostream&gt;# include " assert_reached.h "ASSERT_REACHED_BEGIN (fooGuard)void foo( bool a, bool b) { if (a) { ...

    永久有效_python接口自动化+jmeter+soapui接口测试视频

    01_为什么要进行接口测试、02_认识测试对象、03_postman、04_postman_and_newman、05_鉴权、06_python_http、07_assert、08_unittest、09_test_get、10_test_post11_start_mock_server、12_implement_get..............

    肖申克-一种有效的通用实习结构-Rust开发

    assert_eq!(sp.intern(“ hello”),Ok(0)); assert_eq!(sp.intern(“ world”),Ok(1)); assert_eq!(sp.intern(“ hello”),Ok(0)); assert_eq!(sp.resolve(1),Ok(“ world”))); /...

    assertpy:简单的断言库,可使用流畅的API在python中进行单元测试

    is_equal_to ( 3 ) assert_that ( 'foobar' ). is_length ( 6 ). starts_with ( 'foo' ). ends_with ( 'bar' ) assert_that ([ 'a' , 'b' , 'c' ]). contains ( 'a' ). does_not_contain ( 'x' ) 当然, assertpy最...

    ( ap6181_sina33m_sc3817r验证通过_20170710_1608没有外层目录.7z

    write /sys/module/printk/parameters/console_suspend N write /proc/sys/kernel/printk 0 on fs # UDISK would be mounted as data partition when multiple user enabled. #format_userdata /dev/block/by-...

    tinystr-一个小的仅ASCII的有界长度字符串表示形式-Rust开发

    用法使用tinystr :: {TinyStr4,TinyStr8,TinyStr16}; fn main(){让我们tinystr tinystr是一个小的纯ASCII的有界长度字符串表示形式。 用法使用tinystr :: {TinyStr4,TinyStr8,TinyStr16}; fn main(){让s1:...

Global site tag (gtag.js) - Google Analytics