From 7bd81c1b2befa3ab403af402c9a1c204e2feea91 Mon Sep 17 00:00:00 2001 From: Dusty Mabe Date: Wed, 20 Jul 2016 16:58:51 -0400 Subject: [PATCH] tests: add some notes for myself for the future --- features/README.md | 21 +++++++++++++++++++ features/sshfs_cwd_mount.feature | 14 +++++++++++++ .../step_definitions/sshfs_cwd_mount_steps.rb | 8 +++++++ features/support/env.rb | 15 ++++++++++++- 4 files changed, 57 insertions(+), 1 deletion(-) create mode 100644 features/README.md diff --git a/features/README.md b/features/README.md new file mode 100644 index 0000000..ac8a46d --- /dev/null +++ b/features/README.md @@ -0,0 +1,21 @@ + +We are using Cucumber for automated testing. Read more at the +following two links: + +- [link1](https://en.wikipedia.org/wiki/Cucumber_(software)) +- [link2](http://www.methodsandtools.com/tools/cucumber.php) + +features/ + This is the features directory. The features directory Contains + feature files, which all have a .feature extension. May contain + subdirectories to organize feature files. + +features/step_definitions + This directory contains step definition files, which are Ruby code + and have a .rb extension. + +features/support + This directory contains supporting Ruby code. Files in support + load before those in step_definitions, which makes it useful for + such things as environment configuration (commonly done in a file + called env.rb). diff --git a/features/sshfs_cwd_mount.feature b/features/sshfs_cwd_mount.feature index 23e8421..d614a53 100644 --- a/features/sshfs_cwd_mount.feature +++ b/features/sshfs_cwd_mount.feature @@ -1,3 +1,16 @@ +# The language in this file is Gherkin. It is the language Cucumber +# uses to define test cases and is designed to be non-technical and +# human readable. All Gherkin files have a .feature extension +# +# See more here: https://en.wikipedia.org/wiki/Cucumber_(software) +# +# Additoinally in the setup/env.rb file we set up Aruba. Aruba is used +# to define most of the basic step definitions that we use as part of +# the Gherkin syntax in this file. +# +# For more information on the step definitions provided see: +# https://github.com/cucumber/aruba/tree/bb5d7ff71809b5461e29153ded793d2b9a3a0624/features/testing_frameworks/cucumber/steps +# Feature: SSHFS mount of vagrant current working directory Scenario Outline: SSHFS mounting of vagrant cwd @@ -23,6 +36,7 @@ Feature: SSHFS mount of vagrant current working directory Then stdout from "bundle exec vagrant up" should contain "Installing SSHFS client..." And stdout from "bundle exec vagrant up" should contain "Mounting SSHFS shared folder..." And stdout from "bundle exec vagrant up" should contain "Folder Successfully Mounted!" + # The code for the following test is in ./step_definitions/sshfs_cwd_mount_steps.rb And vagrant current working directory should be mounted Examples: diff --git a/features/step_definitions/sshfs_cwd_mount_steps.rb b/features/step_definitions/sshfs_cwd_mount_steps.rb index a848352..1d161b5 100644 --- a/features/step_definitions/sshfs_cwd_mount_steps.rb +++ b/features/step_definitions/sshfs_cwd_mount_steps.rb @@ -1,3 +1,11 @@ +# This is a cucumber step definition. Cucumber scenarios become automated +# tests with the addition of what are called step definitions. A step +# definition is a block of code associated with one or more steps by a +# regular expression (or, in simple cases, a string). +# +# This is the step definition for the `And vagrant current working +# directory should be mounted` step from sshfs_cwd_mount.feature +# And(/^vagrant current working directory should be mounted$/) do run("vagrant ssh -c 'ls /testdir/Vagrantfile'") expect(last_command_started).to have_exit_status(0) diff --git a/features/support/env.rb b/features/support/env.rb index b626eeb..5f93cc1 100644 --- a/features/support/env.rb +++ b/features/support/env.rb @@ -1,12 +1,25 @@ +# This is a support file for the cucumber tests. This file sets up the +# environment for the tests to run. At this point mainly that means +# configuring Aruba. Aruba is used to define most of the basic step +# definitions that we use as part of the Gherkin syntax in our .feature files. +# +# For more information on the step definitions provided see: +# https://github.com/cucumber/aruba/tree/bb5d7ff71809b5461e29153ded793d2b9a3a0624/features/testing_frameworks/cucumber/steps require 'aruba/cucumber' -require 'komenda' +require 'komenda' # use komenda for easily executing a command +# Configure aruba. The options can be inferred from here: +# https://github.com/cucumber/aruba/tree/bb5d7ff71809b5461e29153ded793d2b9a3a0624/features/configuration Aruba.configure do |config| + # Wait up to 300 seconds for the test to run config.exit_timeout = 300 + # Output stdout and stderr on test failure config.activate_announcer_on_command_failure = [:stdout, :stderr] + # The directory where the tests are to be run config.working_directory = 'build/aruba' end +# After running tests, clean up After do |_scenario| if File.exist?(File.join(aruba.config.working_directory, 'Vagrantfile')) Komenda.run('bundle exec vagrant destroy -f', cwd: aruba.config.working_directory, fail_on_fail: true)