DHH on Unit Testing : Is RSpec indeed needlessly complicated?

前端 未结 3 1478
一生所求
一生所求 2021-02-08 08:15

I happen to be a subscriber of Ruby Inside, since I\'m particularly interested in Rails. Yesterday, the creator of Rails, David Heinemeier Hansson, pretty much said that he\'s j

3条回答
  •  情话喂你
    2021-02-08 08:29

    It's a matter of personal taste.

    I like to write easy cucumber tests without worrying about details. Just testing the "happy" paths of my app. (portable, understandable, slow)

    I leave the details to Test/Unit. (easy, fast)

    It takes more time to understand:

    get :products, :session => @session_id_for_product_banana
    assert_select "table" do
      assert_select "td#name", "Banana"
    end
    

    instead of

    When I go to the banana page
    Then I should see "Banana"
    

    Sure those tests are not equal but who cares whether "Banana" is in a div or a table or doesn't have the right html-id.

    I dont' like functional tests because after refactoring, the id's could be gone, the session expectation could be changed. If that's the case you will need to refactor your code AND tests. If you'd use cucumber you wouldn't have to change your scenario's.

提交回复
热议问题