Skip to content

Commit

Permalink
Rename to Guard::RSpecRails
Browse files Browse the repository at this point in the history
  • Loading branch information
netzpirat committed Sep 30, 2011
1 parent 850e69f commit e367f07
Show file tree
Hide file tree
Showing 21 changed files with 149 additions and 104 deletions.
2 changes: 1 addition & 1 deletion .yardopts
@@ -1,7 +1,7 @@
--readme README.md
--markup markdown
--markup-provider kramdown
--title 'Guard::RSpectacular Documentation'
--title 'Guard::RSpecRails Documentation'
--hide-void-return
--protected
--private
Expand Down
2 changes: 1 addition & 1 deletion Gemfile
@@ -1,6 +1,6 @@
source 'http://rubygems.org'

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

gem 'rake'
Expand Down
12 changes: 6 additions & 6 deletions README.md
@@ -1,6 +1,6 @@
# Guard::RSpectacular [![Build Status](https://secure.travis-ci.org/netzpirat/guard-rspectacular.png)](http://travis-ci.org/netzpirat/guard-rspectacular)
# Guard::RSpecRails [![Build Status](https://secure.travis-ci.org/netzpirat/guard-rspec-rails.png)](http://travis-ci.org/netzpirat/guard-rspec-rails)

Guard::RSpectacular automatically tests your Rails application when files are modified.
Guard::RSpecRails 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.

Expand All @@ -9,21 +9,21 @@ If you have any questions please join us on our [Google group](http://groups.goo

## Install

### Guard and Guard::RSpectacular
### Guard and Guard::RSpecRails

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

Install the gem:

$ gem install guard-rspectacular
$ gem install guard-rspec-rails

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

gem 'guard-rspectacular'
gem 'guard-rspec-rails'

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

$ guard init rspectacular
$ guard init rspec-rails

## Usage

Expand Down
12 changes: 6 additions & 6 deletions guard-rspectacular.gemspec → guard-rspec-rails.gemspec
@@ -1,21 +1,21 @@
# -*- encoding: utf-8 -*-
$:.push File.expand_path('../lib', __FILE__)
require 'guard/rspectacular/version'
require 'guard/rspec_rails/version'

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

s.add_development_dependency 'bundler', '~> 1.0'
s.add_development_dependency 'guard-rspec', '~> 0.4'
Expand Down
45 changes: 39 additions & 6 deletions lib/guard/rspectacular.rb → lib/guard/rspec_rails.rb
Expand Up @@ -4,26 +4,29 @@

module Guard

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

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

DEFAULT_OPTIONS = {
:cli => ''
}

# Initialize Guard::RSpectacular.
# Initialize Guard::RSpecRails.
#
# @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)

watchers << ::Guard::Watcher.new(%r{^.*$})

super(watchers, options)
end

Expand All @@ -32,6 +35,17 @@ def initialize(watchers = [], options = { })
# @return [Boolean] when the start was successful
#
def start
ENV['RAILS_ENV'] = 'test'

if File.exists?('config/application.rb')
Formatter.info 'Load Rails...'
require 'config/application'
end

Formatter.info 'Load RSpec...'
require 'spec/spec_helper'

Formatter.info 'RSpectacular ready!'
true
end

Expand All @@ -40,6 +54,8 @@ def start
# @return [Boolean] when the reload was successful
#
def reload
Dir.glob('**/*').each { |file| reload_file(file) }

true
end

Expand All @@ -57,8 +73,25 @@ def run_all
# @return [Boolean] when running the changed specs was successful
#
def run_on_change(paths)
paths.each { |path| reload_file(path) }
Runner.run(Inspector.clean(paths), options)
end

private

# Reloads the given file.
#
# @param [String] file the changed file
#
def reload_file(file)
return unless file =~ /\.rb$/

Formatter.info "Reload #{ file }"
load file

rescue Exception => e
Formatter.error "Error reloading file #{ file }: #{ e.message }"
end

end
end
@@ -1,5 +1,5 @@
module Guard
class RSpectacular
class RSpecRails

# The Guard::RSpectacular formatter collects console and
# system notification methods and enhances them with
Expand Down
@@ -1,5 +1,5 @@
module Guard
class RSpectacular
class RSpecRails

# The inspector verifies if the changed paths are valid
# for Guard::RSpectacular.
Expand Down
34 changes: 34 additions & 0 deletions lib/guard/rspec_rails/runner.rb
@@ -0,0 +1,34 @@
# coding: utf-8

require 'rspec/core/runner'

module Guard
class RSpecRails

autoload :Formatter, 'guard/rspec_rails/formatter'

# 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 = {})
return false if paths.empty?

Formatter.info "Run #{ paths.join('') }"

RSpec::Core::Runner.run(paths)

rescue Exception => e
Formatter.error "Error while spec run: #{ e.message }"
end

end
end
end
end
@@ -1,4 +1,4 @@
guard 'rspectacular' do
guard 'rspec_rails' do
watch('spec/spec_helper.rb') { "spec" }
watch('config/routes.rb') { "spec/routing" }
watch('app/controllers/application_controller.rb') { "spec/controllers" }
Expand Down
6 changes: 6 additions & 0 deletions lib/guard/rspec_rails/version.rb
@@ -0,0 +1,6 @@
module Guard
module RSpecRailsVersion
# Guard::Spec version that is used for the Gem specification
VERSION = '0.1.0'
end
end
22 changes: 0 additions & 22 deletions lib/guard/rspectacular/runner.rb

This file was deleted.

6 changes: 0 additions & 6 deletions lib/guard/rspectacular/version.rb

This file was deleted.

@@ -1,8 +1,8 @@
require 'spec_helper'

describe Guard::RSpectacular::Formatter do
describe Guard::RSpecRails::Formatter do

let(:formatter) { Guard::RSpectacular::Formatter }
let(:formatter) { Guard::RSpecRails::Formatter }
let(:ui) { Guard::UI }
let(:notifier) { Guard::Notifier }

Expand Down
@@ -1,11 +1,11 @@
require 'spec_helper'

describe Guard::RSpectacular::Inspector do
describe Guard::RSpecRails::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 }
subject { Guard::RSpecRails::Inspector }

describe 'clean' do
it 'allows the RSpec spec dir' do
Expand Down
12 changes: 12 additions & 0 deletions spec/guard/rspec_rails/runner_spec.rb
@@ -0,0 +1,12 @@
# coding: utf-8

require 'spec_helper'

describe Guard::RSpecRails::Runner do

let(:runner) { Guard::RSpecRails::Runner }

describe '#run' do
end

end
9 changes: 9 additions & 0 deletions spec/guard/rspec_rails/version_spec.rb
@@ -0,0 +1,9 @@
require 'spec_helper'

describe Guard::RSpecRails do
describe 'VERSION' do
it 'defines the version' do
Guard::RSpecRailsVersion::VERSION.should match /\d+.\d+.\d+/
end
end
end
25 changes: 25 additions & 0 deletions spec/guard/rspec_rails_spec.rb
@@ -0,0 +1,25 @@
require 'spec_helper'

describe Guard::RSpecRails do

let(:guard) { Guard::RSpecRails.new }

let(:runner) { Guard::RSpecRails::Runner }
let(:inspector) { Guard::RSpecRails::Inspector }
let(:formatter) { Guard::RSpecRails::Formatter }

let(:defaults) { Guard::RSpecRails::DEFAULT_OPTIONS }

describe '.start' do
end

describe '.reload' do
end

describe '.run_all' do
end

describe '.run_on_change' do
end

end
12 changes: 0 additions & 12 deletions spec/guard/rspectacular/runner_spec.rb

This file was deleted.

9 changes: 0 additions & 9 deletions spec/guard/rspectacular/version_spec.rb

This file was deleted.

25 changes: 0 additions & 25 deletions spec/guard/rspectacular_spec.rb

This file was deleted.

0 comments on commit e367f07

Please sign in to comment.