jason328 jason328 - 1 year ago 74
Ruby Question

Multiple expects within scenario test

I have a scenario test:

scenario 'displays the form' do
# Build the setup for user coming from an external site.
expect(page).to have_selector('#braintree-dropin-frame', count: 1)

# User reloads the page
expect(page).to have_selector('#braintree-dropin-frame', count: 1)

# User visits page from within the website.
expect(page).to have_selector('#braintree-dropin-frame', count: 1)

First off, is this the proper usage of a scenario test? I'm essentially testing the same thing but in different scenarios. I feel like this should really be three separate scenario tests inside a context block. Am I misusing

Answer Source

If this isn't one user flow then they should be separate features/scenarios. You also need to be careful when setting expectations for the same selector multiple times in a test that you've checked it has gone away between (if you are checking it reappears again), otherwise you can end up with tests passing when they shouldn't due to timing and asynchronous behavior issues.

Additionally - since you're checking for a CSS selector you probably want to be using have_css rather than have_selector since it reads nicer and will mean the tests keep working if the default selector type is ever changed from :css

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download