From 635887918e9c4b5c8278e4a45958420175a4024a Mon Sep 17 00:00:00 2001 From: Lunar Date: Fri, 31 May 2013 19:57:16 +0200 Subject: [PATCH] Implement first scenario --- Gemfile | 1 + Gemfile.lock | 31 ++++++++++ features/fixtures/create-git-bundle | 1 + features/git-hooks.feature | 2 +- features/step_definitions/commandes.rb | 3 + features/step_definitions/git.rb | 25 ++++++++ features/step_definitions/subscriptions.rb | 6 ++ features/support/env.rb | 18 ++++++ features/support/fixtures.rb | 69 ++++++++++++++++++++++ 9 files changed, 155 insertions(+), 1 deletion(-) create mode 100644 Gemfile.lock create mode 100755 features/fixtures/create-git-bundle create mode 100644 features/step_definitions/commandes.rb create mode 100644 features/step_definitions/git.rb create mode 100644 features/step_definitions/subscriptions.rb create mode 100644 features/support/env.rb create mode 100644 features/support/fixtures.rb diff --git a/Gemfile b/Gemfile index 8e7e0b5..5df2cc3 100644 --- a/Gemfile +++ b/Gemfile @@ -2,3 +2,4 @@ source 'https://rubygems.org' gem 'cucumber' gem 'aruba' +gem 'safe_yaml' diff --git a/Gemfile.lock b/Gemfile.lock new file mode 100644 index 0000000..7291159 --- /dev/null +++ b/Gemfile.lock @@ -0,0 +1,31 @@ +GEM + remote: https://rubygems.org/ + specs: + aruba (0.5.3) + childprocess (>= 0.3.6) + cucumber (>= 1.1.1) + rspec-expectations (>= 2.7.0) + builder (3.2.1) + childprocess (0.3.9) + ffi (~> 1.0, >= 1.0.11) + cucumber (1.3.2) + builder (>= 2.1.2) + diff-lcs (>= 1.1.3) + gherkin (~> 2.12.0) + multi_json (~> 1.3) + diff-lcs (1.2.4) + ffi (1.8.1) + gherkin (2.12.0) + multi_json (~> 1.3) + multi_json (1.7.4) + rspec-expectations (2.13.0) + diff-lcs (>= 1.1.3, < 2.0) + safe_yaml (0.9.2) + +PLATFORMS + ruby + +DEPENDENCIES + aruba + cucumber + safe_yaml diff --git a/features/fixtures/create-git-bundle b/features/fixtures/create-git-bundle new file mode 100755 index 0000000..1a24852 --- /dev/null +++ b/features/fixtures/create-git-bundle @@ -0,0 +1 @@ +#!/bin/sh diff --git a/features/git-hooks.feature b/features/git-hooks.feature index 2f16551..4cf55fa 100644 --- a/features/git-hooks.feature +++ b/features/git-hooks.feature @@ -9,4 +9,4 @@ Fonctionnalité: Git hooks Soit un clone du Git contenant les adhésions Lorsque j'ajoute une fiche correcte pour une nouvelle adhésion Et que je fait un `commit` du nouveau fichier - Alors je ne dois pas voir d'erreur + Alors je ne dois pas avoir eu d'erreur diff --git a/features/step_definitions/commandes.rb b/features/step_definitions/commandes.rb new file mode 100644 index 0000000..471f8dd --- /dev/null +++ b/features/step_definitions/commandes.rb @@ -0,0 +1,3 @@ +Then /^je ne dois pas avoir eu d'erreur$/ do + assert_exit_status(0) +end diff --git a/features/step_definitions/git.rb b/features/step_definitions/git.rb new file mode 100644 index 0000000..30d6e7c --- /dev/null +++ b/features/step_definitions/git.rb @@ -0,0 +1,25 @@ +require 'fileutils' + +Given /^un clone du Git contenant les adhésions$/ do + # Create main repository + create_dir 'main' + cd 'main' + run_simple 'git init' + create_dir 'Membres' + BASE_SUBSCRIPTIONS.each_pair do |number, data| + file = subscription_filename_for_id(number) + write_file file, render_subscription_file(data) + run_simple "git add #{file}" + end + run_simple 'git commit -m "Initial data set from fixtures"' + cd '..' + + # Clone it now + run_simple 'git clone main clone' + cd 'clone' +end + +When /je fait un `commit` du nouveau fichier$/ do + run_simple "git add #{@file}" + run_simple "git commit #{@file} -m 'new file'" +end diff --git a/features/step_definitions/subscriptions.rb b/features/step_definitions/subscriptions.rb new file mode 100644 index 0000000..4fab6a3 --- /dev/null +++ b/features/step_definitions/subscriptions.rb @@ -0,0 +1,6 @@ +When /^j'ajoute une fiche correcte pour une nouvelle adhésion$/ do + new_id = Dir.glob("#{current_dir}/Membres/*.mdwn"). + collect { |f| File.basename(f).gsub(/\.mdwn$/, '').to_i }.max + 1 + @file = subscription_filename_for_id(new_id) + write_file @file, render_subscription_file(EXTRA_SUBSCRIPTION) +end diff --git a/features/support/env.rb b/features/support/env.rb new file mode 100644 index 0000000..936dc53 --- /dev/null +++ b/features/support/env.rb @@ -0,0 +1,18 @@ +require 'rubygems' +require 'bundler' +Bundler.setup + +require 'tmpdir' +require 'aruba/cucumber' +require 'safe_yaml' + +SafeYAML::OPTIONS[:default_mode] = :safe + +Before do + @tmpdir = Dir.mktmpdir('gestion-adh') + @dirs = [@tmpdir] +end + +After do + FileUtils.remove_entry_secure @tmpdir +end diff --git a/features/support/fixtures.rb b/features/support/fixtures.rb new file mode 100644 index 0000000..d3e3353 --- /dev/null +++ b/features/support/fixtures.rb @@ -0,0 +1,69 @@ +#-*- coding: utf-8 -*- + +require 'erb' +require 'ostruct' +require 'yaml' + +BASE_SUBSCRIPTIONS = YAML.load(< +address: + <%= address %> +email: <%= email %> +mumbership_fee_paid_on: <%= membership_fee_paid_on %> +--- + +<%= notes %> +END_OF_TEMPLATE + +def subscription_filename_for_id(id) + "Membres/%06d.mdwn" % id +end + +def render_subscription_file(locals) + ERB.new(SUBSCRIPTION_FILE_TEMPLATE).result(OpenStruct.new(locals).instance_eval { binding }) +end -- 2.39.5