require 'rubygems'
require 'bundler'
Bundler.setup
+
+require 'nos_oignons/subscriptions'
+
+subscriptions = read_subscriptions
+subscriptions.each_pair do |subscription_id, data|
+ puts data['email']
+end
Then /^la sortie doit-être vide$/ do
expect(all_output).to be_empty
end
+
+Then /^la sortie doit être:$/ do |expected|
+ # add an extra line feed for nice scenario
+ assert_exact_output(expected + "\n", all_stdout)
+end
create_dir 'Membres'
end
+Given /^une base avec (\w+), à jour de cotisation$/ do |name|
+ data = { 'name' => name,
+ 'address' => "At #{name}",
+ 'email' => "#{name.downcase}@example.org",
+ 'membership_fee_paid_on' =>
+ # one month ago
+ (Time.now - 3600*24*30).strftime('%Y-%m-%d')
+ }
+ create_dir 'Membres'
+ file = subscription_filename_for_id(new_id)
+ write_file file, render_subscription_file(data)
+end
+
When /^j'ajoute une fiche correcte pour une nouvelle adhésion$/ do
@file = subscription_filename_for_id(new_id)
write_file @file, render_subscription_file(EXTRA_SUBSCRIPTION)
end
def new_id
- new_id = Dir.glob("#{current_dir}/Membres/*.mdwn").
- collect { |f| File.basename(f).gsub(/\.mdwn$/, '').to_i }.max + 1
+ max_id = Dir.glob("#{current_dir}/Membres/*.mdwn").
+ collect { |f| File.basename(f).gsub(/\.mdwn$/, '').to_i }.max || 0
+ max_id + 1
end
is_valid_subscription?(f.read)
end
end
+
+def read_subscriptions
+ subscriptions = {}
+ Dir.glob("#{SUBSCRIPTIONS_ROOT}/*.mdwn") do |file|
+ subscription_id = File.basename(file).gsub(/\.mdwn$/, '')
+ subscriptions[subscription_id] = YAML.load_file(file)
+ end
+ subscriptions
+end