From f45032acbf3e476ca9db894748bb1f4785a87875 Mon Sep 17 00:00:00 2001 From: Frederic Jean Date: Wed, 1 Oct 2014 15:40:20 -0600 Subject: [PATCH 1/4] Bumping rspec-rails to 2.14.x --- Gemfile | 2 +- spree_paypal_express.gemspec | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Gemfile b/Gemfile index 5ad72456..0716cf18 100644 --- a/Gemfile +++ b/Gemfile @@ -7,9 +7,9 @@ gem 'sqlite3' gem 'pg' group :test do - gem 'yarjuf' gem 'require_all' gem 'capybara' + gem 'capybara-screenshot' gem 'poltergeist' end diff --git a/spree_paypal_express.gemspec b/spree_paypal_express.gemspec index 1f2f58be..2577709e 100644 --- a/spree_paypal_express.gemspec +++ b/spree_paypal_express.gemspec @@ -30,7 +30,7 @@ Gem::Specification.new do |s| s.add_development_dependency 'database_cleaner', '1.0.1' s.add_development_dependency 'factory_girl', '~> 4.2' s.add_development_dependency 'ffaker' - s.add_development_dependency 'rspec-rails', '~> 2.13' + s.add_development_dependency 'rspec-rails', '~> 2.14.0' s.add_development_dependency 'sass-rails', '~> 4.0.2' s.add_development_dependency 'selenium-webdriver' s.add_development_dependency 'simplecov' From e101598eb0220606d256cdcdfec5436ec171f934 Mon Sep 17 00:00:00 2001 From: Frederic Jean Date: Wed, 1 Oct 2014 15:48:04 -0600 Subject: [PATCH 2/4] Taking a screenshot on failure. --- spec/spec_helper.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 7f6089c6..bf989a5c 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -22,6 +22,7 @@ require 'pry' require 'capybara/rspec' require 'capybara/rails' +require 'capybara-screenshot/rspec' # To stop these warnings: # WARN: tilt autoloading 'sass' in a non thread-safe way; explicit require 'sass' suggested. From 911e02be6ff13c5ad78978f1cb8124424dce4c12 Mon Sep 17 00:00:00 2001 From: Frederic Jean Date: Wed, 1 Oct 2014 17:04:07 -0600 Subject: [PATCH 3/4] Fixing acceptance tests broken by Paypal flow changes. --- spec/features/paypal_spec.rb | 98 +++++++++++++++++++++++++++--------- 1 file changed, 74 insertions(+), 24 deletions(-) diff --git a/spec/features/paypal_spec.rb b/spec/features/paypal_spec.rb index 3f835e55..78540457 100644 --- a/spec/features/paypal_spec.rb +++ b/spec/features/paypal_spec.rb @@ -30,11 +30,24 @@ def fill_in_billing def switch_to_paypal_login # If you go through a payment once in the sandbox, it remembers your preferred setting. # It defaults to the *wrong* setting for the first time, so we need to have this method. - unless page.has_selector?("#login_email") + unless page.has_selector?("#login #email") find("#loadLogin").click end end + def login_to_paypal + within("#loginForm") do + fill_in "Email", :with => "pp@spreecommerce.com" + fill_in "Password", :with => "thequickbrownfox" + click_button "Log in to PayPal" + end + end + + def within_transaction_cart(&block) + find(".transactionDetails").click + within(".transctionCartDetails") { block.call } + end + it "pays for an order successfully" do visit spree.root_path click_link 'iPad' @@ -50,10 +63,8 @@ def switch_to_paypal_login click_button "Save and Continue" find("#paypal_button").click switch_to_paypal_login - fill_in "login_email", :with => "pp@spreecommerce.com" - fill_in "login_password", :with => "thequickbrownfox" - click_button "Log In" - find("#continue_abovefold").click # Because there's TWO continue buttons. + login_to_paypal + click_button "Pay Now" page.should have_content("Your order has been processed successfully") Spree::Payment.last.source.transaction_id.should_not be_blank @@ -79,16 +90,14 @@ def switch_to_paypal_login click_button "Save and Continue" find("#paypal_button").click - page.should have_selector '#billingInfo', text: 'Test User' - page.should have_selector '#billingInfo', text: '1 User Lane' - page.should have_selector '#billingInfo', text: 'Adamsville, AL 35005' - page.should have_selector '#billingInfo', text: 'United States' - page.should have_field 'email', with: 'test@example.com' + login_to_paypal + click_button "Pay Now" - # PayPal arbitrarily removes or does not remove the hypenation in phone numbers, - # so our test needs to accept both cases - page.should have_field 'H_PhoneNumberUS' - page.find('#H_PhoneNumberUS').value.gsub('-', '').should == '5551234567' + page.should have_selector '[data-hook=order-bill-address] .fn', text: 'Test User' + page.should have_selector '[data-hook=order-bill-address] .adr', text: '1 User Lane' + page.should have_selector '[data-hook=order-bill-address] .adr', text: 'Adamsville AL 35005' + page.should have_selector '[data-hook=order-bill-address] .adr', text: 'United States' + page.should have_selector '[data-hook=order-bill-address] .tel', text: '555-123-4567' end end @@ -115,7 +124,22 @@ def switch_to_paypal_login # Delivery step doesn't require any action click_button "Save and Continue" find("#paypal_button").click - within("#miniCart") do + + within_transaction_cart do + page.should have_content("$5 off") + page.should have_content("$10 on") + end + + login_to_paypal + + within_transaction_cart do + page.should have_content("$5 off") + page.should have_content("$10 on") + end + + click_button "Pay Now" + + within("[data-hook=order_details_adjustments]") do page.should have_content("$5 off") page.should have_content("$10 on") end @@ -127,7 +151,7 @@ def switch_to_paypal_login calculator = Spree::Calculator::FlatPercentItemTotal.new(preferred_flat_percent: 10) action = Spree::Promotion::Actions::CreateItemAdjustments.create(:calculator => calculator) promotion.actions << action - end + end it "includes line item adjustments in PayPal summary" do @@ -152,7 +176,15 @@ def switch_to_paypal_login # Delivery step doesn't require any action click_button "Save and Continue" find("#paypal_button").click - within("#miniCart") do + + within_transaction_cart do + page.should have_content("10% off") + end + + login_to_paypal + click_button "Pay Now" + + within("[data-hook=order_details_price_adjustments]") do page.should have_content("10% off") end end @@ -184,10 +216,25 @@ def switch_to_paypal_login # Delivery step doesn't require any action click_button "Save and Continue" find("#paypal_button").click - within("#miniCart") do + + within_transaction_cart do page.should have_content('iPad') page.should_not have_content('iPod') end + + login_to_paypal + + within_transaction_cart do + page.should have_content('iPad') + page.should_not have_content('iPod') + end + + click_button "Pay Now" + + within("#line-items") do + page.should have_content('iPad') + page.should have_content('iPod') + end end end @@ -216,8 +263,13 @@ def switch_to_paypal_login # Delivery step doesn't require any action click_button "Save and Continue" find("#paypal_button").click - within("#miniCart") do - page.should have_content('Current purchase') + + login_to_paypal + + click_button "Pay Now" + + within("[data-hook=order_details_adjustments]") do + page.should have_content('FREE iPad ZOMG!') end end end @@ -265,10 +317,8 @@ def switch_to_paypal_login click_button "Save and Continue" find("#paypal_button").click switch_to_paypal_login - fill_in "login_email", :with => "pp@spreecommerce.com" - fill_in "login_password", :with => "thequickbrownfox" - click_button "Log In" - find("#continue_abovefold").click # Because there's TWO continue buttons. + login_to_paypal + click_button("Pay Now") page.should have_content("Your order has been processed successfully") visit '/admin' From 2f540c33ea0e85c24e10d03fabbee00b7145a55c Mon Sep 17 00:00:00 2001 From: Frederic Jean Date: Thu, 2 Oct 2014 10:00:04 -0600 Subject: [PATCH 4/4] Automatically re-run failed specs. This change automatically re-run failed specs. The Paypal gateway has the bad habit to return server errors at times. The result is a potential false negative. Re-running the failed spec(s) gives the suite a chance to succeed. --- .gitignore | 1 + Rakefile | 9 ++++----- spree_paypal_express.gemspec | 1 + 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/.gitignore b/.gitignore index 418c7fb3..aff2ad43 100644 --- a/.gitignore +++ b/.gitignore @@ -8,5 +8,6 @@ Gemfile.lock tmp pkg spec/dummy +rspec.failures .rvmrc .idea diff --git a/Rakefile b/Rakefile index a13ec13a..a24bcb36 100644 --- a/Rakefile +++ b/Rakefile @@ -3,8 +3,6 @@ require 'rake' require 'rake/testtask' require 'rake/packagetask' require 'rubygems/package_task' -require 'rspec/core/rake_task' -require 'spree/testing_support/extension_rake' desc 'Generates a dummy app for testing' task :test_app do @@ -14,10 +12,11 @@ end require 'rspec/core' require 'rspec/core/rake_task' -Rake::Task["spec"].clear +require 'rspec-rerun' +require 'spree/testing_support/extension_rake' + RSpec::Core::RakeTask.new(:spec) do |t| t.fail_on_error = false - t.rspec_opts = %w[-f JUnit -o results.xml] end desc "Run RSpec with code coverage" @@ -25,7 +24,7 @@ task :coverage do ENV['COVERAGE'] = 'true' Rake::Task["spec"].execute end -task :default => :spec +task :default => 'rspec-rerun:spec' Bundler::GemHelper.install_tasks diff --git a/spree_paypal_express.gemspec b/spree_paypal_express.gemspec index 2577709e..e3e25233 100644 --- a/spree_paypal_express.gemspec +++ b/spree_paypal_express.gemspec @@ -31,6 +31,7 @@ Gem::Specification.new do |s| s.add_development_dependency 'factory_girl', '~> 4.2' s.add_development_dependency 'ffaker' s.add_development_dependency 'rspec-rails', '~> 2.14.0' + s.add_development_dependency 'rspec-rerun' s.add_development_dependency 'sass-rails', '~> 4.0.2' s.add_development_dependency 'selenium-webdriver' s.add_development_dependency 'simplecov'