`
Hooopo
  • 浏览: 329386 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

RSpec基础语法

    博客分类:
  • Ruby
阅读更多

下面是RSpec测试的一些基础语法,这些都是会运行通过的测试例:

Strings:

'foo'.should == 'foo'
'foo'.should === 'foo'
'foo'.should_not equal('foo')
''.should be_empty
'foo with bar'.should include('with')
'http://fr.ivolo.us'.should match(/http:\/\/.+/i)
nil.should be_nil

Numbers:

100.should < 200
200.should >= 100
(200 - 100).should == 100

# (100 - 80) is less than 21
100.should be_close(80,21)

Arrays:

[1,2,3].should have(3).items
[].should be_empty
[1,2,3].should include(2)

Hashes:

{}.should be_empty
{:post => {:title => 'test'}}.should have_key(:post)
{:post => {:title => 'test'}}.should_not have_key(:title)
false.should be_false
true.should be_true

Records:

# assuming @post = Post.new(:title => 'test')
@post.should be_instance_of(Post)
@post.should respond_to(:title)

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics