Skip to content
Browse files

Initial project structure.

  • Loading branch information...
0 parents commit 850e69f8c61d7c7eb48281b738b9d036d83ce299 @netzpirat committed Sep 19, 2011
15 .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 .travis.yml
@@ -0,0 +1,6 @@
+rvm:
+ - 1.8.7
+ - 1.9.2
+ - ree
+ - rbx
+ - jruby
8 .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 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 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 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 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 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 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 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 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 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
22 lib/guard/rspectacular/runner.rb
@@ -0,0 +1,22 @@
+# coding: utf-8
+
+module Guard
+ class RSpectacular
+
+ # The RSpectacular runner handles the execution of the rspec test.
+ #
+ module Runner
+ class << self
+
+ # Run the supplied specs.
+ #
+ # @param [Array<String>] paths the spec files or directories
+ # @param [Hash] options the options for the Guard
+ #
+ def run(paths, options = { })
+ end
+
+ end
+ end
+ end
+end
9 lib/guard/rspectacular/templates/Guardfile
@@ -0,0 +1,9 @@
+guard 'rspectacular' do
+ watch('spec/spec_helper.rb') { "spec" }
+ watch('config/routes.rb') { "spec/routing" }
+ watch('app/controllers/application_controller.rb') { "spec/controllers" }
+ watch(%r{^spec/.+_spec\.rb$})
+ watch(%r{^app/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
+ watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
+ watch(%r{^app/controllers/(.+)_(controller)\.rb$}) { |m| ["spec/routing/#{m[1]}_routing_spec.rb", "spec/#{m[2]}s/#{m[1]}_#{m[2]}_spec.rb", "spec/acceptance/#{m[1]}_spec.rb"] }
+end
6 lib/guard/rspectacular/version.rb
@@ -0,0 +1,6 @@
+module Guard
+ module RSpectacularVersion
+ # Guard::RSpectacular version that is used for the Gem specification
+ VERSION = '0.1.0'
+ end
+end
43 spec/guard/rspectacular/formatter_spec.rb
@@ -0,0 +1,43 @@
+require 'spec_helper'
+
+describe Guard::RSpectacular::Formatter do
+
+ let(:formatter) { Guard::RSpectacular::Formatter }
+ let(:ui) { Guard::UI }
+ let(:notifier) { Guard::Notifier }
+
+ describe '.info' do
+ it 'shows an info message' do
+ ui.should_receive(:info).with('Info message', { :reset => true })
+ formatter.info('Info message', { :reset => true })
+ end
+ end
+
+ describe '.debug' do
+ it 'shows a debug message' do
+ ui.should_receive(:debug).with('Debug message', { :reset => true })
+ formatter.debug('Debug message', { :reset => true })
+ end
+ end
+
+ describe '.error' do
+ it 'shows a colorized error message' do
+ ui.should_receive(:error).with("\e[0;31mError message\e[0m", { :reset => true })
+ formatter.error('Error message', { :reset => true })
+ end
+ end
+
+ describe '.success' do
+ it 'shows a colorized success message' do
+ ui.should_receive(:info).with("\e[0;32mSuccess message\e[0m", { :reset => true })
+ formatter.success('Success message', { :reset => true })
+ end
+ end
+
+ describe '.notify' do
+ it 'shows an info message' do
+ notifier.should_receive(:notify).with('Notify message', { :image => :failed })
+ formatter.notify('Notify message', { :image => :failed })
+ end
+ end
+end
30 spec/guard/rspectacular/inspector_spec.rb
@@ -0,0 +1,30 @@
+require 'spec_helper'
+
+describe Guard::RSpectacular::Inspector do
+ before do
+ Dir.stub(:glob).and_return ['spec/models/model_spec.rb', 'spec/constrollers/test_controller_spec.rb']
+ end
+
+ subject { Guard::RSpectacular::Inspector }
+
+ describe 'clean' do
+ it 'allows the RSpec spec dir' do
+ subject.clean(['spec', 'spec/models/model_spec.rb']).should == ['spec']
+ end
+
+ it 'removes duplicate files' do
+ subject.clean(['spec/models/model_spec.rb', 'spec/models/model_spec.rb']).should == ['spec/models/model_spec.rb']
+ end
+
+ it 'remove nil files' do
+ subject.clean(['spec/models/model_spec.rb', nil]).should == ['spec/models/model_spec.rb']
+ end
+
+ it 'removes files that are no rspec specs' do
+ subject.clean(['spec/models/model_spec.rb',
+ 'app/models/model.rb',
+ 'b.txt']).should == ['spec/models/model_spec.rb']
+ end
+
+ end
+end
12 spec/guard/rspectacular/runner_spec.rb
@@ -0,0 +1,12 @@
+# coding: utf-8
+
+require 'spec_helper'
+
+describe Guard::RSpectacular::Runner do
+
+ let(:runner) { Guard::RSpectacular::Runner }
+
+ describe '#run' do
+ end
+
+end
9 spec/guard/rspectacular/version_spec.rb
@@ -0,0 +1,9 @@
+require 'spec_helper'
+
+describe Guard::RSpectacularVersion do
+ describe 'VERSION' do
+ it 'defines the version' do
+ Guard::RSpectacularVersion::VERSION.should match /\d+.\d+.\d+/
+ end
+ end
+end
25 spec/guard/rspectacular_spec.rb
@@ -0,0 +1,25 @@
+require 'spec_helper'
+
+describe Guard::RSpectacular do
+
+ let(:guard) { Guard::RSpectacular.new }
+
+ let(:runner) { Guard::RSpectacular::Runner }
+ let(:inspector) { Guard::RSpectacular::Inspector }
+ let(:formatter) { Guard::RSpectacular::Formatter }
+
+ let(:defaults) { Guard::RSpectacular::DEFAULT_OPTIONS }
+
+ describe '.start' do
+ end
+
+ describe '.reload' do
+ end
+
+ describe '.run_all' do
+ end
+
+ describe '.run_on_change' do
+ end
+
+end
18 spec/spec_helper.rb
@@ -0,0 +1,18 @@
+require 'rspec'
+require 'guard/rspectacular'
+
+RSpec.configure do |config|
+
+ config.color_enabled = true
+ config.filter_run :focus => true
+ config.run_all_when_everything_filtered = true
+
+ config.before(:each) do
+ ENV["GUARD_ENV"] = 'test'
+ @project_path = Pathname.new(File.expand_path('../../', __FILE__))
+ end
+
+ config.after(:each) do
+ ENV["GUARD_ENV"] = nil
+ end
+end

0 comments on commit 850e69f

Please sign in to comment.
Something went wrong with that request. Please try again.