Skip to content

Instantly share code, notes, and snippets.

@brutuscat
Last active December 31, 2015 10:39
Show Gist options
  • Save brutuscat/7974807 to your computer and use it in GitHub Desktop.
Save brutuscat/7974807 to your computer and use it in GitHub Desktop.
Codeception auto tests setup using ruby's Guard

Codeception auto tests setup using ruby's Guard

Instructions

  • Drop the Gemfile and the Guardfile in your project
  • Run bundle install
  • Run bundle exec guard

When changing any of the files you've setup to be monitored ("guarded"), the test will run auto-magically. A notification should be shown to you if using growl on OSX when the test finishes.

For more notification options take a look at Guard's System-notifications

Dependencies: Ruby >= v1.9.3

# A sample Gemfile
source "https://rubygems.org"
group :development, :test do
gem 'rb-inotify', :require => false
gem 'rb-fsevent', :require => false
gem 'rb-fchange', :require => false
gem 'growl'
gem "guard"
gem 'guard-shell'
end
guard 'shell' do
watch(%r{^(folder/to/monitor1|folder/to/monitor2|tests/(functional|unit|acceptance|others))/(.+)\.php$}) do |m|
output = `/path/to/your/binary/php vendor/codeception/codeception/codecept run unit --debug --steps`
last_lines = ''; lines2read = 4;
output.clone.lines.reverse_each do |line|
lines2read -= 1;
last_lines << line
break if lines2read == 0
end
# output
result = if /OK/ =~ last_lines then :success else :failed end
message = if result == :success
last_lines.scan(/(?:[^\[2K]\w+\: \d+)|\d+ \w+/).join(' ')
else
last_lines.scan(/(?:[^\[2K]\w+\: \d+)/).join(' ')
end
n(message , 'Codeception', result)
output
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment