Skip to content

Instantly share code, notes, and snippets.

@dgmora
Last active April 5, 2017 17:54
Show Gist options
  • Save dgmora/eee18f56d6f64c48583ccc67c76d03a1 to your computer and use it in GitHub Desktop.
Save dgmora/eee18f56d6f64c48583ccc67c76d03a1 to your computer and use it in GitHub Desktop.
Add a checkpoint inside an it/scenario to artificially create a passed test
So testing with capybara is nice, but doing it the way RSpec does it
does not really work, as these tests are slow: You can't have several
nested describe/context blocks because that would execute everything several times.
That is no problem for controllers but it sucks when the tests are (relatively) slow.
So we end up with long tests that test a bunch of things.
To make it a bit better, you can add "checkpoints". This is simply a way
to make it easy for you to know which point your test reached.
And to see what is tested by this scenario.
Making the checkpoint be inside the scenario, or after the scenario
would be quite difficult. The easy solution would be to use only features/describes
instead of scenarios.
class RSpec::Core::ExampleGroup
def checkpoint(title)
title = RSpec.current_example.description + " - ✓ checkpoint: " + title
example = RSpec::Core::Example.new(self.class, title, {}, Proc.new{ })
example.run(self, RSpec.configuration.reporter)
end
end
def checkpoint(title)
checkit(title) { true }
end
RSpec.feature 'User login' do
scenario 'with valid credentials' do |example|
checkpoint('you can submit your password')
expect(true).to eq 'you successfully logged in'
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment