Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

fix cucumber features

  • Loading branch information...
commit 19c2b5b23665fce6ff40da84643d25bd68b015e0 1 parent 29f05f4
@svenfuchs svenfuchs authored
View
4 config/environments/test.rb
@@ -1,3 +1,5 @@
+require 'cucumber/fake_parameter_middleware'
+
Travis::Application.configure do
# Settings specified here will take precedence over those in config/application.rb
@@ -36,4 +38,6 @@
# Print deprecation notices to the stderr
config.active_support.deprecation = :stderr
+
+ config.middleware.use 'Cucumber::FakeParameterMiddleware'
end
View
93 features/order.feature
@@ -4,18 +4,18 @@ Feature: Ordering a package
When I go to the order page for the "Medium" package
Then I should see "Package: Medium"
When I fill in the following:
- | Name | Sven Fuchs |
- | Email | sven@email.com |
- | Github handle | svenfuchs |
- | Twitter handle | svenfuchs |
- | Password | my-password |
- | Street | Grünberger 65 |
- | Zip | 10245 |
- | City | Berlin |
- | Country | Germany |
- | Number | 123456 |
- | Security code | 123 |
- And the credit card service returns a credit card token
+ | Name | Sven Fuchs |
+ | Email | sven@email.com |
+ | Github | svenfuchs |
+ | Twitter | @svenfuchs |
+ | Password | my-password |
+ | Street | Grünberger 65 |
+ | Zip | 10245 |
+ | City | Berlin |
+ | Country | Germany |
+ | Number | 123456 |
+ | CVC | 123 |
+ And the credit card service returns the credit card token "12345678"
And the credit card service will create a customer for:
| email | sven@email.com |
| card | 12345678 |
@@ -26,10 +26,11 @@ Feature: Ordering a package
| currency | usd |
And I press "Confirm"
Then I should see "Thank you"
- And I should see "sven@email.com"
- And I should see "Medium"
+ And I should see "Package: Medium"
When I go to my profile page
- Then I should see "Medium" within the packages list
+ Then I should see "sven@email.com"
+ And I should see "Medium" within the packages list
+ And I should see "70" within the packages list
Scenario: Ordering a package being signed in
Given I am signed in as "sven@email.com" and I have the stripe customer id "1"
@@ -37,12 +38,11 @@ Feature: Ordering a package
Then I should see "Package: Medium"
And I should not see the following form fields: Email, Password
When I fill in the following:
- | Street | Grünberger 65 |
- | Zip | 10245 |
- | City | Berlin |
- | Country | Germany |
- | Number | 123456 |
- | Security code | 123 |
+ | Name | Sven Fuchs |
+ | Street | Grünberger 65 |
+ | Zip | 10245 |
+ | City | Berlin |
+ | Country | Germany |
And the credit card service will not create a customer
And the credit card service will create the following charge:
| customer | 1 |
@@ -52,27 +52,28 @@ Feature: Ordering a package
And I press "Confirm"
Then I should see "Thank you"
And I should see "Medium"
- And I should see "sven@email.com"
And I should see "Berlin"
When I go to my profile page
- Then I should see "Medium" within the packages list
+ Then I should see "sven@email.com"
+ And I should see "Medium" within the packages list
+ And I should see "70" within the packages list
Scenario: Ordering a subscription not being signed in
When I go to the order page for the "Medium" subscription
Then I should see "Subscription: Medium"
When I fill in the following:
- | Name | Sven Fuchs |
- | Email | sven@email.com |
- | Github handle | svenfuchs |
- | Twitter handle | svenfuchs |
- | Password | my-password |
- | Street | Grünberger 65 |
- | Zip | 10245 |
- | City | Berlin |
- | Country | Germany |
- | Number | 123456 |
- | Security code | 123 |
- And the credit card service returns a credit card token
+ | Name | Sven Fuchs |
+ | Email | sven@email.com |
+ | Github | svenfuchs |
+ | Twitter | @svenfuchs |
+ | Password | my-password |
+ | Street | Grünberger 65 |
+ | Zip | 10245 |
+ | City | Berlin |
+ | Country | Germany |
+ | Number | 123456 |
+ | CVC | 123 |
+ And the credit card service returns the credit card token "12345678"
And the credit card service will create a customer for:
| email | sven@email.com |
| plan | medium |
@@ -80,10 +81,11 @@ Feature: Ordering a package
And I press "Confirm"
Then I should see "Thank you"
And I should see "Medium"
- And I should see "sven@email.com"
And I should see "Berlin"
When I go to my profile page
- Then I should see "Medium" within the subscriptions list
+ Then I should see "sven@email.com"
+ And I should see "Medium" within the subscriptions list
+ And I should see "20" within the subscriptions list
Scenario: Ordering a subscription being signed in
Given I am signed in as "sven@email.com" and I have the stripe customer id "1"
@@ -91,19 +93,18 @@ Feature: Ordering a package
Then I should see "Subscription: Medium"
And I should not see the following form fields: Email, Password
When I fill in the following:
- | Name | Sven Fuchs |
- | Street | Grünberger 65 |
- | Zip | 10245 |
- | City | Berlin |
- | Country | Germany |
- | Number | 123456 |
- | Security code | 123 |
+ | Name | Sven Fuchs |
+ | Street | Grünberger 65 |
+ | Zip | 10245 |
+ | City | Berlin |
+ | Country | Germany |
And the credit card service will not create a customer
And I press "Confirm"
Then I should see "Thank you"
And I should see "Medium"
- And I should see "sven@email.com"
And I should see "Berlin"
When I go to my profile page
- Then I should see "Medium" within the subscriptions list
+ Then I should see "sven@email.com"
+ And I should see "Medium" within the subscriptions list
+ And I should see "20" within the subscriptions list
View
14 features/step_definitions/ordering_steps.rb
@@ -4,11 +4,15 @@
end
end
-When /^the credit card service returns a credit card token/ do
- # page.execute_script('$("#user_stripe_card_token").val("12345678");')
- @set_strip_card_token ||= OrdersController.before_filter(only: :create) do
- params[:user][:stripe_card_token] = '12345678' if params.key?(:user)
- end
+When /^the credit card service returns the credit card token "(.*)"/ do |token|
+ # page.execute_script('$("#user_stripe_card_token").val(token);')
+ #
+ # Big hack around the fact that we can't set form fields from js in cucumber/rack
+ # The order creation form will first post to Stripe through js and fetch a token.
+ # It will then set this token to a new field stripe_card_token before it then
+ # actually submits the form. We fake adding this parameter here.
+ #
+ Cucumber::FakeParameterMiddleware.params = { 'user' => { 'stripe_card_token' => token } }
end
When /^the credit card service will create a customer for:$/ do |attrs|
View
24 features/support/env.rb
@@ -4,17 +4,29 @@
ActionController::Base.allow_rescue = false
-begin
- DatabaseCleaner.strategy = :transaction
-rescue NameError
- raise "You need to add database_cleaner to your Gemfile (in the :test group) if you wish to use it."
-end
+require 'database_cleaner'
+require 'database_cleaner/cucumber'
+
+DatabaseCleaner.strategy = :truncation
Cucumber::Rails::Database.javascript_strategy = :truncation
+Before do
+ DatabaseCleaner.start
+end
+
+After do |scenario|
+ DatabaseCleaner.clean
+end
+
+require 'cucumber/fake_parameter_middleware'
+Before do
+ Cucumber::FakeParameterMiddleware.params = nil
+end
+
require 'mocha'
-World(Mocha::Standalone)
+World(Mocha::API)
Before do
mocha_setup
View
52 features/support/oauth.rb
@@ -1,28 +1,28 @@
# http://pivotallabs.com/users/mgehard/blog/articles/1595-testing-omniauth-based-login-via-cucumber
-OmniAuth.config.test_mode = true
-
-module Accounts
- PAYLOADS = {
- twitter: {
- svenfuchs: {
- provider: 'twitter',
- uid: '12345678',
- info: {
- name: 'Sven Fuchs',
- nickname: 'svenfuchs',
- description: 'My bio',
- urls: {
- website: 'http://svenfuchs.com'
- }
- }
- }
- }
- }
-
- def oauth_payload_for(provider, name)
- Hashr.new(PAYLOADS[provider.to_sym][name.to_sym])
- end
-end
-
-World(Accounts)
+# OmniAuth.config.test_mode = true
+#
+# module Accounts
+# PAYLOADS = {
+# twitter: {
+# svenfuchs: {
+# provider: 'twitter',
+# uid: '12345678',
+# info: {
+# name: 'Sven Fuchs',
+# nickname: 'svenfuchs',
+# description: 'My bio',
+# urls: {
+# website: 'http://svenfuchs.com'
+# }
+# }
+# }
+# }
+# }
+#
+# def oauth_payload_for(provider, name)
+# Hashr.new(PAYLOADS[provider.to_sym][name.to_sym])
+# end
+# end
+#
+# World(Accounts)
View
4 features/support/paths.rb
@@ -6,9 +6,9 @@ def path_to(name)
when 'my profile page'
profile_path
when 'the order page for the "Medium" package'
- new_order_path(package: :medium)
+ new_package_path(package: :medium)
when 'the order page for the "Medium" subscription'
- new_order_path(package: :medium, subscription: true)
+ new_subscription_path(package: :medium)
else
raise "Could not find path to: #{name}"
end
View
20 lib/cucumber/fake_parameter_middleware.rb
@@ -0,0 +1,20 @@
+require 'active_support/core_ext/hash/deep_merge'
+
+module Cucumber
+ class FakeParameterMiddleware
+ class << self
+ attr_accessor :params
+ end
+
+ delegate :params, to: 'self.class'
+
+ def initialize(app)
+ @app = app
+ end
+
+ def call(env)
+ env['rack.request.form_hash'].deep_merge!(params) if env.key?('rack.request.form_hash') && params
+ @app.call(env)
+ end
+ end
+end
Please sign in to comment.
Something went wrong with that request. Please try again.