Skip to content

Commit

Permalink
Initial project structure.
Browse files Browse the repository at this point in the history
  • Loading branch information
netzpirat committed Sep 19, 2011
0 parents commit 850e69f
Show file tree
Hide file tree
Showing 21 changed files with 551 additions and 0 deletions.
15 changes: 15 additions & 0 deletions .gitignore
@@ -0,0 +1,15 @@
pkg/*
*.gem
*.rbc
.bundle
.yardoc
doc
Gemfile.lock

## MAC OS
.DS_Store
.Trashes
.com.apple.timemachine.supported
.fseventsd
Desktop DB
Desktop DF
6 changes: 6 additions & 0 deletions .travis.yml
@@ -0,0 +1,6 @@
rvm:
- 1.8.7
- 1.9.2
- ree
- rbx
- jruby
8 changes: 8 additions & 0 deletions .yardopts
@@ -0,0 +1,8 @@
--readme README.md
--markup markdown
--markup-provider kramdown
--title 'Guard::RSpectacular Documentation'
--hide-void-return
--protected
--private
lib/**/*.rb
17 changes: 17 additions & 0 deletions Gemfile
@@ -0,0 +1,17 @@
source 'http://rubygems.org'

# Specify your gem's dependencies in guard-rspectacular.gemspec
gemspec

gem 'rake'

require 'rbconfig'

if Config::CONFIG['target_os'] =~ /darwin/i
gem 'rb-fsevent', '>= 0.4.0'
gem 'growl', '~> 1.0.3'
end
if Config::CONFIG['target_os'] =~ /linux/i
gem 'rb-inotify', '>= 0.8.4'
gem 'libnotify', '~> 0.3.0'
end
5 changes: 5 additions & 0 deletions Guardfile
@@ -0,0 +1,5 @@
guard 'rspec', :rvm => ['1.8.7', '1.9.2'] do
watch('spec/spec_helper.rb') { 'spec' }
watch(%r{spec/.+_spec.rb})
watch(%r{lib/(.+).rb}) { |m| "spec/#{ m[1] }_spec.rb" }
end
20 changes: 20 additions & 0 deletions LICENSE
@@ -0,0 +1,20 @@
Copyright (c) 2011 Michael Kessler

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
56 changes: 56 additions & 0 deletions README.md
@@ -0,0 +1,56 @@
# Guard::RSpectacular [![Build Status](https://secure.travis-ci.org/netzpirat/guard-rspectacular.png)](http://travis-ci.org/netzpirat/guard-rspectacular)

Guard::RSpectacular automatically tests your Rails application when files are modified.

Tested on MRI Ruby 1.8.7, 1.9.2, REE and the latest versions of JRuby & Rubinius.

If you have any questions please join us on our [Google group](http://groups.google.com/group/guard-dev) or on `#guard`
(irc.freenode.net).

## Install

### Guard and Guard::RSpectacular

Please be sure to have [Guard][] installed.

Install the gem:

$ gem install guard-rspectacular

Add it to your `Gemfile`, preferably inside the development group:

gem 'guard-rspectacular'

Add guard definition to your `Guardfile` by running this command:

$ guard init rspectacular

## Usage

Please read the [Guard usage documentation](https://github.com/guard/guard#readme).

## License

(The MIT License)

Copyright (c) 2011 Michael Kessler

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
'Software'), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

21 changes: 21 additions & 0 deletions Rakefile
@@ -0,0 +1,21 @@
require 'bundler'
Bundler::GemHelper.install_tasks

require 'rspec/core/rake_task'
RSpec::Core::RakeTask.new(:spec)
task :default => :spec

namespace(:spec) do
desc "Run all specs on multiple ruby versions (requires rvm)"
task(:portability) do
%w[1.8.7 1.9.2 ree rbx jruby].each do |version|
system <<-BASH
bash -c 'source ~/.rvm/scripts/rvm;
rvm #{version};
echo "--------- version #{version} ----------\n";
bundle install;
rake spec'
BASH
end
end
end
28 changes: 28 additions & 0 deletions guard-rspectacular.gemspec
@@ -0,0 +1,28 @@
# -*- encoding: utf-8 -*-
$:.push File.expand_path('../lib', __FILE__)
require 'guard/rspectacular/version'

Gem::Specification.new do |s|
s.name = 'guard-rspectacular'
s.version = Guard::RSpectacularVersion::VERSION
s.platform = Gem::Platform::RUBY
s.authors = ['Michael Kessler']
s.email = ['michi@netzpiraten.ch']
s.homepage = 'http://github.com/netzpirat/guard-rspectacular'
s.summary = 'Guard gem for fast Rails RSpec testing'
s.description = 'Guard::Rspectacular automatically tests your Rails app with RSpec'

s.required_rubygems_version = '>= 1.3.6'
s.rubyforge_project = 'guard-rspec'

s.add_dependency 'guard', '>= 0.4'

s.add_development_dependency 'bundler', '~> 1.0'
s.add_development_dependency 'guard-rspec', '~> 0.4'
s.add_development_dependency 'rspec', '~> 2.6'
s.add_development_dependency 'yard', '~> 0.7.2'
s.add_development_dependency 'kramdown', '~> 0.13.3'

s.files = Dir.glob('{bin,lib}/**/*') + %w[LICENSE README.md]
s.require_path = 'lib'
end
64 changes: 64 additions & 0 deletions lib/guard/rspectacular.rb
@@ -0,0 +1,64 @@
require 'guard'
require 'guard/guard'
require 'guard/watcher'

module Guard

# The RSpectacular guard that gets notifications about the following
# Guard events: `start`, `stop`, `reload`, `run_all` and `run_on_change`.
#
class RSpectacular < Guard

autoload :Formatter, 'guard/rspectacular/formatter'
autoload :Inspector, 'guard/rspectacular/inspector'
autoload :Runner, 'guard/rspectacular/runner'

DEFAULT_OPTIONS = {
}

# Initialize Guard::RSpectacular.
#
# @param [Array<Guard::Watcher>] watchers the watchers in the Guard block
# @param [Hash] options the options for the Guard
#
def initialize(watchers = [], options = { })
options = DEFAULT_OPTIONS.merge(options)

super(watchers, options)
end

# Gets called once when Guard starts.
#
# @return [Boolean] when the start was successful
#
def start
true
end

# Gets called when the Guard should reload itself.
#
# @return [Boolean] when the reload was successful
#
def reload
true
end

# Gets called when all specs should be run.
#
# @return [Boolean] when running all specs was successful
#
def run_all
Runner.run(['spec'], options)
end

# Gets called when watched paths and files have changes.
#
# @param [Array<String>] paths the changed paths and files
# @return [Boolean] when running the changed specs was successful
#
def run_on_change(paths)
Runner.run(Inspector.clean(paths), options)
end

end
end
76 changes: 76 additions & 0 deletions lib/guard/rspectacular/formatter.rb
@@ -0,0 +1,76 @@
module Guard
class RSpectacular

# The Guard::RSpectacular formatter collects console and
# system notification methods and enhances them with
# some color information.
#
module Formatter
class << self

# Print an info message to the console.
#
# @param [String] message the message to print
# @param [Hash] options the output options
# @option options [Boolean] :reset reset the UI
#
def info(message, options = { })
::Guard::UI.info(message, options)
end

# Print a debug message to the console.
#
# @param [String] message the message to print
# @param [Hash] options the output options
# @option options [Boolean] :reset reset the UI
#
def debug(message, options = { })
::Guard::UI.debug(message, options)
end

# Print a red error message to the console.
#
# @param [String] message the message to print
# @param [Hash] options the output options
# @option options [Boolean] :reset reset the UI
#
def error(message, options = { })
::Guard::UI.error(color(message, ';31'), options)
end

# Print a green success message to the console.
#
# @param [String] message the message to print
# @param [Hash] options the output options
# @option options [Boolean] :reset reset the UI
#
def success(message, options = { })
::Guard::UI.info(color(message, ';32'), options)
end

# Outputs a system notification.
#
# @param [String] message the message to print
# @param [Hash] options the output options
# @option options [Symbol, String] :image the image to use, either :failed, :pending or :success, or an image path
# @option options [String] :title the title of the system notification
#
def notify(message, options = { })
::Guard::Notifier.notify(message, options)
end

private

# Print a info message to the console.
#
# @param [String] test the text to colorize
# @param [String] color_code the color code
#
def color(text, color_code)
::Guard::UI.send(:color_enabled?) ? "\e[0#{ color_code }m#{ text }\e[0m" : text
end

end
end
end
end
61 changes: 61 additions & 0 deletions lib/guard/rspectacular/inspector.rb
@@ -0,0 +1,61 @@
module Guard
class RSpectacular

# The inspector verifies if the changed paths are valid
# for Guard::RSpectacular.
#
module Inspector
class << self

# Clean the changed paths and return only valid
# RSpec specs.
#
# @param [Array<String>] paths the changed paths
# @return [Array<String>] the valid spec files
#
def clean(paths)
paths.uniq!
paths.compact!

if paths.include?('spec')
paths = ['spec']
else
paths = paths.select { |p| rspec_spec?(p) }
end

clear

paths
end

private

# Clears the list of RSpec specs in this project.
#
def clear
@rspec_specs = nil
end

# Tests if the file is valid.
#
# @param [String] file the file
# @return [Boolean] when the file valid
#
def rspec_spec?(path)
rspec_specs.include?(path)
end

# Scans the project and keeps a list of all
# files ending with `_spec.rb` within the `spec`
# directory.
#
# @return [Array<String>] the valid files
#
def rspec_specs
@rspec_specs ||= Dir.glob('spec/**/*_spec.rb')
end

end
end
end
end

0 comments on commit 850e69f

Please sign in to comment.