Skip to content

Step04: First Static Page Test

Lev Brie edited this page Jul 27, 2013 · 1 revision
  1. Checkout a new branch and then generate an integration_test spec:

    $ git checkout -b step04-add-test-to-static-home
    $ rails generate integration_test static_pages
    
  2. Test for Home Page Content that includes Rangular (or whatever your title is) in spec/requests/static_pages_spec.rb:

    require 'spec_helper'
    
    describe "StaticPages" do
      describe "Home page" do                   # we're describing the home page
        it "should have the content 'Rangular'" do	# descriptive should
          visit '/static_pages/home'		        # actually visit this route (Capybara function visit)
          expect(page).to have_content('Rangular') 	# check for content and expect it using page variable
          		                                # provided by Capybara
          					        # if the content's not there, fail
        end
      end
    end
  3. Add config.include Capybara::DSL to spec/spec_helper.rb to require the Capybara DSL in RSpec.

  4. Run the test with $ bundle exec rspec spec/requests/static_pages_spec.rb (it should fail)

  5. Replace the home page content in app/views/static_pages/home.html.haml with %h1 Rangular Home and whatever else you want. Everything should now be passing.

  6. Commit your changes `git commit -am "First spec for static home page now passing" Now checkout the master, merge your changes, and push up to github:

    $ git checkout master
    $ git merge step04-add-test-to-static-home
    $ git push