SitePoint Sponsor

User Tag List

Results 1 to 2 of 2

Hybrid View

  1. #1
    SitePoint Member
    Join Date
    Nov 2009
    Posts
    4
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Are these tests the same?

    (this is a cross-post from Rails Forums that I haven't been able to get an answer too yet)

    I noticed that the generated test when using script/generate vs. what's in the book "Simply Rails 2", that both of these tests pass fine.
    Are both the correct way of writing assertions, or has one replaced the other?

    Simply Rails 2
    Code:
    def test_should_not_be_valid_without_name
      s = Story.create(:name => nil, :link => 'link')
      assert s.errors.on(:name)
    end
    Generated Test Style
    Code:
    test "Should not be valid without a name" do
        s = Story.create(:name => nil, :link => 'link')
        assert s.errors.on(:name)
    end
    Both pass using the rake test:units command using my model.

  2. #2
    Team ********* Louis Simoneau's Avatar
    Join Date
    Sep 2009
    Location
    Melbourne, Australia
    Posts
    228
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Yep, they're the same. The second type of test was added to edge rails shortly after the 2.1 release (http://weblog.rubyonrails.org/2008/6...rformancetests ), and the stub generators were modified to use the new syntax. If you look at the detail of the changeset, though, you'll see that rails is just using the test...do syntax to dynamically generate a method named test_name_of_your_test, so it's just passing it on to the previously existing infrastructure.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •