rspec_rails_4 icon indicating copy to clipboard operation
rspec_rails_4 copied to clipboard

Ch.11 - Issues in the pending scenario

Open JunichiIto opened this issue 11 years ago • 2 comments
trafficstars

I tried the following pending scenario by myself and found some issues.

  context "as a guest" do
    scenario "reads a news release" do
      pending "You write this one!"
      visit root_path
      click_link "News"

      expect(page).to_not have_content
        "Today, BigCo's CFO announced record growth."
      expect(page).to_not have_content 'Add News Release'

      click_link "2013-08-01: Record profits for BigCo!"

      expect(page).to have_content
        "Today, BigCo's CFO announced record growth."
    end
  end

First, the following expectations do not work well because they are treated as four sentences.

      expect(page).to_not have_content
        "Today, BigCo's CFO announced record growth."

      expect(page).to have_content
        "Today, BigCo's CFO announced record growth."

The first one failed so I noticed the problem, but the second passed, so without false-positive test it is hard to notice that the test is imperfect.

Second, this scenario requires setting up for test data(news releases). I feel it should be indicated in the test code like this:

  context "as a guest" do
    background do
      # set up news release
    end
    scenario "reads a news release" do
      pending "You write this one!"
      # etc
    end
  end

Finally, I cannot understand the purpose of the following expectation for the guest context:

      expect(page).to_not have_content
        "Today, BigCo's CFO announced record growth."

This expectation does not rely on user or guest context.(Neither would display it.)

In conclusion, my ideal sample code would be like this:

  context "as a guest" do
    background do
      # set up news release
    end
    scenario "reads a news release" do
      pending "You write this one!"
      visit root_path
      click_link "News"

      expect(page).to_not have_content 'Add News Release'

      click_link "2013-08-01: Record profits for BigCo!"

      expect(page).to have_content "Today, BigCo's CFO announced record growth."
    end
  end

I would appreciate if you could take it into consideration.

JunichiIto avatar Feb 25 '14 06:02 JunichiIto

I'll look into this, but probably won't be able to get to it until after March 3.

ruralocity avatar Feb 25 '14 15:02 ruralocity

No problem. This is not so urgent issue.

JunichiIto avatar Feb 26 '14 20:02 JunichiIto