From a9210121343f6bcb52154a2ca3cf2cff234e8857 Mon Sep 17 00:00:00 2001 From: Lunar Date: Wed, 13 Jan 2016 17:10:14 +0100 Subject: [PATCH] Update to Ruby 2+, RSpec 3 and recent Aruba --- Gemfile.lock | 75 +++++++++++++-------------- features/step_definitions/commands.rb | 18 ++++--- features/step_definitions/emails.rb | 16 +++--- features/step_definitions/git.rb | 12 ++--- features/step_definitions/mailman.rb | 2 +- features/step_definitions/members.rb | 36 ++++++------- features/step_definitions/receipts.rb | 2 +- features/support/env.rb | 14 ++--- features/support/fixtures.rb | 4 +- 9 files changed, 90 insertions(+), 89 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index 869fed9..104eb02 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -9,52 +9,49 @@ PATH GEM remote: https://rubygems.org/ specs: - Ascii85 (1.0.2) - afm (0.2.0) - aruba (0.5.3) - childprocess (>= 0.3.6) - cucumber (>= 1.1.1) - rspec-expectations (>= 2.7.0) + aruba (0.12.0) + childprocess (~> 0.5.6) + contracts (~> 0.9) + cucumber (>= 1.3.19) + event-bus (~> 0.2) + ffi (~> 1.9.10) + rspec-expectations (>= 2.99) + thor (~> 0.19) builder (3.2.2) - childprocess (0.3.9) + childprocess (0.5.9) ffi (~> 1.0, >= 1.0.11) - cucumber (1.3.10) + contracts (0.12.0) + cucumber (2.1.0) builder (>= 2.1.2) + cucumber-core (~> 1.3.0) diff-lcs (>= 1.1.3) - gherkin (~> 2.12) + gherkin3 (~> 3.1.0) multi_json (>= 1.7.5, < 2.0) - multi_test (>= 0.0.2) + multi_test (>= 0.1.2) + cucumber-core (1.3.1) + gherkin3 (~> 3.1.0) diff-lcs (1.2.5) - ffi (1.9.3) - gherkin (2.12.2) - multi_json (~> 1.3) - hashery (2.1.1) + event-bus (0.2.3) + ffi (1.9.10) + gherkin3 (3.1.2) json (1.7.7) - mail (2.5.4) - mime-types (~> 1.16) - treetop (~> 1.4.8) - mime-types (1.25.1) - multi_json (1.8.2) - multi_test (0.0.2) - pdf-reader (1.3.3) - Ascii85 (~> 1.0.0) - afm (~> 0.2.0) - hashery (~> 2.0) - ruby-rc4 - ttfunk - polyglot (0.3.3) - prawn (0.12.0) - pdf-reader (>= 0.9.0) - ttfunk (~> 1.0.2) - rspec-expectations (2.14.4) - diff-lcs (>= 1.1.3, < 2.0) - ruby-rc4 (0.1.5) - safe_yaml (0.9.7) - timecop (0.7.0) - treetop (1.4.15) - polyglot - polyglot (>= 0.3.1) - ttfunk (1.0.3) + mail (2.6.3) + mime-types (>= 1.16, < 3) + mime-types (2.99) + multi_json (1.11.2) + multi_test (0.1.2) + pdf-core (0.6.0) + prawn (2.0.2) + pdf-core (~> 0.6.0) + ttfunk (~> 1.4.0) + rspec-expectations (3.4.0) + diff-lcs (>= 1.2.0, < 2.0) + rspec-support (~> 3.4.0) + rspec-support (3.4.1) + safe_yaml (1.0.4) + thor (0.19.1) + timecop (0.8.0) + ttfunk (1.4.0) PLATFORMS ruby diff --git a/features/step_definitions/commands.rb b/features/step_definitions/commands.rb index 154c4e9..e0b5ea4 100644 --- a/features/step_definitions/commands.rb +++ b/features/step_definitions/commands.rb @@ -34,7 +34,7 @@ When /^j'exécute list-emails le (\d+)\-(\d+)\-(\d+)$/ do |year, month, day|$/ end When /^j'exécute update-ag-subscribers$/ do - run_simple 'update-ag-subscribers' + NosOignons.update_ag_subscribers! end When /^(?:que )?j'exécute send-membership-reminders$/ do @@ -52,26 +52,30 @@ When /^j'exécute send\-member\-emails\-to\-advisors$/ do end When /^j'exécute `(create\-membership\-fee\-receipt.*)`$/ do |cmd| - run_simple cmd, false + run_simple cmd, :fail_on_error => false end Then /^je ne dois pas avoir eu d'erreur$/ do - assert_exit_status(0) + expect(last_command_started).to have_exit_status(0) end Then /^je dois voir comme erreur "(.*?)"$/ do |expected| - assert_failing_with(expected) + expect(last_command_started).to have_output_on_stderr /#{Regexp.escape(expected)}/ end Then /^la sortie doit être vide$/ do - assert_exact_output('', @stdout || all_stdout) + expect(last_command_started).to have_output_on_stdout('') end Then /^la sortie doit être:$/ do |expected| # add an extra line feed for nice scenario - assert_exact_output(expected + "\n", @stdout || all_stdout) + expect(last_command_started).to have_output_on_stdout(expected) end Then /^la sortie doit être "([^"]*)"$/ do |expected| - assert_exact_output(expected, (@stdout || all_stdout).rstrip) + begin + expect(last_command_started).to have_output_on_stdout(expected) + rescue Aruba::NoCommandHasBeenStartedError + expect(@stdout.rstrip).to eq(expected) + end end diff --git a/features/step_definitions/emails.rb b/features/step_definitions/emails.rb index c6935e6..e5e4fab 100644 --- a/features/step_definitions/emails.rb +++ b/features/step_definitions/emails.rb @@ -17,11 +17,11 @@ # along with this program. If not, see . Then /^aucun email ne doit avoir été envoyé$/ do - Mail::TestMailer.deliveries.should be_empty + expect(Mail::TestMailer.deliveries.size).to eq(0) end Then /^un appel pour la cotisation doit avoir été envoyé$/ do - Mail::TestMailer.deliveries.should have(1).email + expect(Mail::TestMailer.deliveries.size).to eq(1) mail = Mail::TestMailer.deliveries.first expect(mail.from).to eql([NosOignons::BOARD_EMAIL]) expect(mail.to).to eql([@last_member['email']]) @@ -41,19 +41,19 @@ Then /^un (premier|dernier) rappel pour la cotisation doit avoir été envoyé$/ end Then /^(\d+) emails? (?:doit|doivent) avoir été envoyés?$/ do |count| - Mail::TestMailer.deliveries.should have(count).email + expect(Mail::TestMailer.deliveries.size).to eq(count.to_i) end Then /^des emails doivent avoir été envoyés à Jane, Fatima, Fred et Moly$/ do recipients = Mail::TestMailer.deliveries.collect(&:to) - recipients.should include(['jane@example.org']) - recipients.should include(['fatima@example.org']) - recipients.should include(['fred@example.org']) - recipients.should include(['moly@example.org']) + expect(recipients).to include(['jane@example.org']) + expect(recipients).to include(['fatima@example.org']) + expect(recipients).to include(['fred@example.org']) + expect(recipients).to include(['moly@example.org']) end Then /^un email doit avoir été envoyé au comité de déontologie$/ do - expect(Mail::TestMailer.deliveries).to have(1).email + expect(Mail::TestMailer.deliveries.size).to eq(1) expect(Mail::TestMailer.deliveries.first.to).to include('deontologie@nos-oignons.net') end diff --git a/features/step_definitions/git.rb b/features/step_definitions/git.rb index abd3e76..3ea8a8b 100644 --- a/features/step_definitions/git.rb +++ b/features/step_definitions/git.rb @@ -20,19 +20,19 @@ require 'fileutils' Given /^un clone du Git contenant les adhésions$/ do # Create main repository - create_dir 'main' + @main_repository_path = expand_path('main') + create_directory 'main' cd 'main' - @main_repository_path = current_dir run_simple 'git init --quiet --bare' cd '..' # Clone it now - run_simple "git clone --quiet --local file://#{current_dir}/main clone" + run_simple "git clone --quiet --local file://#{expand_path('.')}/main clone" cd 'clone' - create_dir 'Membres' + create_directory 'Membres' BASE_MEMBERS.each_pair do |number, data| file = member_filename_for_id(number) - write_file file, render_member_file(data) + File.write file, render_member_file(data) run_simple "git add #{file}" end run_simple 'git commit -m "Initial data set from fixtures"' @@ -41,7 +41,7 @@ end Given /^le « pre-commit hook » correctement configuré$/ do FileUtils.ln_s File.expand_path('../../../bin/pre-commit-hook', __FILE__), - "#{current_dir}/.git/hooks/pre-commit" + "#{expand_path('.')}/.git/hooks/pre-commit" end Given /^le « pre-receive hook » configuré sur le dépôt principal$/ do diff --git a/features/step_definitions/mailman.rb b/features/step_definitions/mailman.rb index 4d375c4..e201bab 100644 --- a/features/step_definitions/mailman.rb +++ b/features/step_definitions/mailman.rb @@ -19,7 +19,7 @@ require 'json' Before('@mailman') do - @mock_mailman_db = "#{current_dir}/mock_mailman.json" + @mock_mailman_db = expand_path('mock_mailman.json') init_mailman_mock_db({}) ENV['MOCK_MAILMAN_DB'] = @mock_mailman_db @orig_path = ENV['PATH'] diff --git a/features/step_definitions/members.rb b/features/step_definitions/members.rb index 880f67e..0ec5ae1 100644 --- a/features/step_definitions/members.rb +++ b/features/step_definitions/members.rb @@ -17,9 +17,9 @@ # along with this program. If not, see . def init_db - @member_db_path = File.join(current_dir, NosOignons::MEMBERS_DB_DIR) - ENV['NOS_OIGNONS_BOARD_WIKI_PATH'] = current_dir - create_dir @member_db_path + create_directory NosOignons::MEMBERS_DB_DIR + @member_db_path = expand_path(NosOignons::MEMBERS_DB_DIR) + ENV['NOS_OIGNONS_BOARD_WIKI_PATH'] = expand_path('.') end def create_new_member(name, joined_on, paid_on) @@ -31,7 +31,7 @@ def create_new_member(name, joined_on, paid_on) } init_db unless @member_db_path file = member_filename_for_id(new_id) - write_file file, render_member_file(@last_member) + File.write file, render_member_file(@last_member) end Given /une base de membres vide$/ do @@ -57,21 +57,21 @@ end Given /^une base avec (\w+), membre (\w+), ayant cotisé le ([0-9-]+)$/ do |name, member_id, paid_on| create_new_member(name, paid_on, paid_on) - expect(File.read(File.join(current_dir, member_filename_for_id(member_id)))).to include(name) + expect(File.read(member_filename_for_id(member_id))).to include(name) end Given /^une base avec (\w+), membre (\w+), n'ayant jamais cotisé$/ do |name, member_id| joined_on = (Time.now - 3600*24*30).strftime('%Y-%m-%d') create_new_member(name, joined_on, nil) - expect(File.read(File.join(current_dir, member_filename_for_id(member_id)))).to include(name) + expect(File.read(member_filename_for_id(member_id))).to include(name) end Given /^une base avec uniquement (\w+), membre (\w+)$/ do |name, member_id| paid_on = (Time.now - 3600*24*30).strftime('%Y-%m-%d') create_new_member(name, paid_on, paid_on) - member_path = File.join(current_dir, member_filename_for_id(member_id)) + member_path = File.join(member_filename_for_id(member_id)) expect(File.read(member_path)).to include(name) - expect(Dir.glob("#{@member_db_path}/[0-9]*")).to have(1).member + expect(Dir.glob("#{@member_db_path}/[0-9]*").size).to eq(1) end @@ -107,24 +107,24 @@ end When /^j'ajoute une fiche correcte pour une nouvelle adhésion$/ do @file = member_filename_for_id(new_id) - write_file @file, render_member_file(EXTRA_MEMBER) + File.write @file, render_member_file(EXTRA_MEMBER) end When /^j'ajoute une fiche vide$/ do @file = member_filename_for_id(new_id) - write_file @file, '' + File.write @file, '' end When /^j'ajoute une fiche sans YAML$/ do @file = member_filename_for_id(new_id) - write_file @file, <<-EOF.gsub(/^ /, '') + File.write @file, <<-EOF.gsub(/^ /, '') Ceci est une fiche sans YAML. EOF end When /^j'ajoute une fiche avec du mauvais YAML$/ do @file = member_filename_for_id(new_id) - write_file @file, <<-EOF.gsub(/^ /, '') + File.write @file, <<-EOF.gsub(/^ /, '') --- [This is missing a closing bracket --- @@ -133,7 +133,7 @@ end When /^j'ajoute une fiche sans email$/ do @file = member_filename_for_id(new_id) - write_file @file, <<-EOF.gsub(/^ /, '') + File.write @file, <<-EOF.gsub(/^ /, '') --- name: J. Example address: | @@ -147,7 +147,7 @@ end When /^j'ajoute une fiche sans nom$/ do @file = member_filename_for_id(new_id) - write_file @file, <<-EOF.gsub(/^ /, '') + File.write @file, <<-EOF.gsub(/^ /, '') --- email: joe@example.org address: | @@ -161,7 +161,7 @@ end When /^j'ajoute une fiche avec comme date d'adhésion "([^"]*)"$/ do |date| @file = member_filename_for_id(new_id) - write_file @file, <<-EOF.gsub(/^ /, '') + File.write @file, <<-EOF.gsub(/^ /, '') --- name: J. Example email: joe@example.org @@ -176,7 +176,7 @@ end When /^j'ajoute une fiche avec comme date de cotisation "([^"]*)"$/ do |date| @file = member_filename_for_id(new_id) - write_file @file, <<-EOF.gsub(/^ /, '') + File.write @file, <<-EOF.gsub(/^ /, '') --- name: J. Example email: joe@example.org @@ -195,6 +195,6 @@ When /^je supprime le nom sur une fiche existante$/ do end When /^j'ajoute un fichier hors de la base des adhérents$/ do - @file = 'test' - write_file @file, 'Test content.' + @file = expand_path('test') + File.write @file, 'Test content.' end diff --git a/features/step_definitions/receipts.rb b/features/step_definitions/receipts.rb index 6e9c300..9656bad 100644 --- a/features/step_definitions/receipts.rb +++ b/features/step_definitions/receipts.rb @@ -18,7 +18,7 @@ Then /^le fichier "(.*)" doit avoir été créé avec les reçus$/ do |filename| @receipt_path = "#{ENV['NOS_OIGNONS_RECEIPTS_DIR']}/#{filename}" - expect(File.exists?(@receipt_path)).to be_true + expect(File.exists?(@receipt_path)).to be_truthy end Then /^il doit contenir le nom et l'adresse de (\w+), la date et le montant de la cotisation$/ do |name| diff --git a/features/support/env.rb b/features/support/env.rb index 7779bab..ae8c5c3 100644 --- a/features/support/env.rb +++ b/features/support/env.rb @@ -28,21 +28,22 @@ require 'mail' SafeYAML::OPTIONS[:default_mode] = :safe +Aruba.configure do |config| + config.io_wait_timeout = 0.1 + config.exit_timeout = 20 +end + require 'nos_oignons' Before do ENV['GIT_COMMITTER_NAME'] = ENV['GIT_AUTHOR_NAME'] = 'J. Test' ENV['GIT_COMMITTER_EMAIL'] = ENV['GIT_AUTHOR_EMAIL'] = 'test@example.org' - @tmpdir = Dir.mktmpdir('gestion-adh') - @dirs = [@tmpdir] - @aruba_io_wait_seconds = 0.1 - @aruba_timeout_seconds = 20 @orig_wiki_path = ENV['NOS_OIGNONS_BOARD_WIKI_PATH'] @orig_reminder_db_path = ENV['NOS_OIGNONS_REMINDER_DB'] @orig_receipts_dir = ENV['NOS_OIGNONS_RECEIPTS_DIR'] - ENV['NOS_OIGNONS_REMINDER_DB'] = File.join(current_dir, 'reminders.yaml') + ENV['NOS_OIGNONS_REMINDER_DB'] = expand_path('reminders.yaml') NosOignons::ReminderDb.instance.reload! - ENV['NOS_OIGNONS_RECEIPTS_DIR'] = File.join(current_dir, 'receipts') + ENV['NOS_OIGNONS_RECEIPTS_DIR'] = expand_path('receipts') FileUtils.mkdir(ENV['NOS_OIGNONS_RECEIPTS_DIR']) Mail.defaults do delivery_method :test @@ -54,5 +55,4 @@ After do ENV['NOS_OIGNONS_REMINDER_DB'] = @orig_reminder_db_path ENV['NOS_OIGNONS_BOARD_WIKI_PATH'] = @orig_wiki_path ENV['NOS_OIGNONS_RECEIPTS_DIR'] = @orig_receipts_dir - FileUtils.remove_entry_secure @tmpdir end diff --git a/features/support/fixtures.rb b/features/support/fixtures.rb index 32142b2..42d46ee 100644 --- a/features/support/fixtures.rb +++ b/features/support/fixtures.rb @@ -84,7 +84,7 @@ membership_fee_paid_on: <%= membership_fee_paid_on %> END_OF_TEMPLATE def member_filename_for_id(id) - "Membres/%06d.mdwn" % id + expand_path("Membres/%06d.mdwn" % id) end def render_member_file(locals) @@ -92,7 +92,7 @@ def render_member_file(locals) end def new_id - max_id = Dir.glob("#{current_dir}/Membres/*.mdwn"). + max_id = Dir.glob("#{expand_path('Membres')}/*.mdwn"). collect { |f| File.basename(f).gsub(/\.mdwn$/, '').to_i }.max || 0 max_id + 1 end -- 2.39.5