railsrspec 입문

1521 단어 Railsrspec
상용 방법
  before(:all) do
  #  example 
  end
  before do
  #  before(:each) , example 
  end
  after(:each) do
  #  example 
    @post.destroy unless @post.new_record?
  end
  after(:all) do
    #  examples 
    Post.destroy_all
  end

기초
    String
'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)

 

좋은 웹페이지 즐겨찾기