I have some test set up code that I need to run before any Capybara tests that are running JavaScript with the @javascript
tag. I don't want the code to run the rest of the time since this test set up is expensive in terms of system resources and cognitive load.
I've searched the documentation extensively and was unable to find any examples of running arbitrary ruby before tests based in tagging. Can anyone help me out?
Edit: after thinking about this some more, I only need the code to run once before any tests are run, so this is probably a simpler problem then I first described.
Since you're asking about an @javascript tag I'm assuming you're talking about Cucumber driven tests, if you're not then please clarify.
To run code before a test you use Before
Before('@javascript') do
# any code here will get run before each test tagged with @javascript
end
To make it only run that code once you'd need to use a global variable
Before('@javascript') do
$already_run ||= false
return $already_run if $already_run
# code here will get run once before the first test tagged @javascript
$already_run = true
end