Skip to content

Instantly share code, notes, and snippets.

@rcarver
Created February 26, 2010 19:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rcarver/316032 to your computer and use it in GitHub Desktop.
Save rcarver/316032 to your computer and use it in GitHub Desktop.
Sample cucumber support for Vanity
Scenario: Choose a free plan, then create an account
When I go to the homepage
And I follow "Register"
Then I should see "Find the plan that's right for you"
When I follow "signup-trial"
Then I fill in "First Name" with "Joe"
And I fill in "Last Name" with "Johnson"
And I fill in "Email" with "joe@joe.com"
And I fill in "Password" with "test"
And I fill in "user[password_confirmation]" with "test"
And I check "I agree"
And I press "Create my account"
Then I should see "Thanks for signing up!"
And only these metrics were recorded:
| 1 | accounts created |
| 1 | subscriptions activated |
| 1 | trial subscriptions activated |
Then /^(only )?these metrics were recorded:$/ do |only, table|
expected_metrics = {}
if only
# Expect 0 on all unnamed metrics
Vanity.playground.metrics.keys.each do |metric_id|
expected_metrics[metric_id] = 0
end
end
# Map given names to metric names and their expected value.
table.raw.each do |(value, metric_name)|
metric_id = metric_name.gsub(/\s+/, '_').to_sym
Vanity.playground.metric(metric_id) # ensure the metric name is valid
expected_metrics[metric_id] = value.to_i
end
# Check all expectations.
expected_metrics.each do |metric_id, expected_value|
actual = Vanity::Aggregation.new(metric_id).sum
unless actual == expected_value
raise Spec::Expectations::ExpectationNotMetError, "Expected #{metric_id} to be #{expected_value}, but was #{actual}"
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment