Rails 3.1, RSpec: testing model validations

后端 未结 7 1548
不知归路
不知归路 2021-01-30 03:51

I have started my journey with TDD in Rails and have run into a small issue regarding tests for model validations that I can\'t seem to find a solution to. Let\'s say I have a U

7条回答
  •  孤独总比滥情好
    2021-01-30 04:31

    I have traditionally handled error content specs in feature or request specs. So, for instance, I have a similar spec which I'll condense below:

    Feature Spec Example

    before(:each) { visit_order_path }
    
    scenario 'with invalid (empty) description' , :js => :true do
    
      add_empty_task                                 #this line is defined in my spec_helper
    
      expect(page).to have_content("can't be blank")
    

    So then, I have my model spec testing whether something is valid, but then my feature spec which tests the exact output of the error message. FYI, these feature specs require Capybara which can be found here.

提交回复
热议问题