]> nos-oignons.net Git - gestion-adh.git/blob - features/step_definitions/mailman.rb
Implement send-member-emails-to-advisors
[gestion-adh.git] / features / step_definitions / mailman.rb
1 #-*- coding: utf-8 -*-
2
3 require 'json'
4
5 Before('@mailman') do
6   @mock_mailman_db = "#{current_dir}/mock_mailman.json"
7   init_mailman_mock_db({})
8   ENV['MOCK_MAILMAN_DB'] = @mock_mailman_db
9   @orig_path = ENV['PATH']
10   ENV['PATH'] = "#{File.expand_path('../../support/mock_mailman', __FILE__)}:#{@orig_path}"
11 end
12
13 After('@mailman') do
14   ENV['PATH'] = @orig_path
15   FileUtils.remove_entry_secure @mock_mailman_db
16 end
17
18 def init_mailman_mock_db(dict)
19   File.open(@mock_mailman_db, 'w') { |f| f.write(JSON.dump(dict)) }
20 end
21
22 def mailman_mock_db
23   JSON.load(File.open(@mock_mailman_db))
24 end
25
26 Given /^une liste ag@ avec comme emails inscrits:$/ do |subscriber_list|
27   emails = subscriber_list.strip.split
28   init_mailman_mock_db('ag' => emails)
29 end
30
31 Then /^la liste ag@ doit avoir comme emails inscrits:$/ do |expected|
32   emails = expected.strip.split.sort
33   expect(mailman_mock_db['ag'].sort).to eql(emails)
34 end
35