Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Add Rake Tasks for Unmerged and Unpushed #1

Merged
merged 10 commits into from

1 participant

Marshall Yount
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on May 12, 2012
  1. docs!

    authored
  2. documentation tweaks

    authored
Commits on May 14, 2012
  1. Update README.md

    Marshall Yount authored
Commits on May 15, 2012
  1. tidy up directories

    authored
  2. path bug

    authored
  3. Troubleshooting tricky bundler path problems.

    Marshall Yount authored
  4. add support for uncommitted and unmerged command line args

    authored
    docs!
    
    documentation tweaks
    
    Update README.md
    
    tidy up directories
    
    path bug
    
    fix versioning bugs
  5. Merge branch 'unmerged' of github.com:marshally/rspec-rails-uncommitt…

    authored
    …ed into unmerged
    
    Conflicts:
    	lib/rspec/rails/uncommitted/tasks/rspec.rake
  6. fix up merge

    authored
This page is out of date. Refresh to see the latest.
47 README.md
View
@@ -1,4 +1,45 @@
-rspec-rails-uncommitted
-=======================
+# rspec-rails-uncommitted
-rspec-rails-uncommitted adds rake tasks which selectively run rspec tests based on git status
+rake tasks for rails-3 which selectively run specs based on your SCM status.
+
+## Install
+```
+gem install rspec-rails-uncommitted
+```
+
+## Configure
+
+Add `rspec-rails-uncommitted` to the `:test` and `:development` groups in the Gemfile:
+
+```ruby
+group :test, :development do
+ gem "rspec-rails-uncommitted", "~> 2.0"
+end
+```
+
+It needs to be in the `:development` group to expose generators and rake
+tasks without having to type `RAILS_ENV=test`.
+
+## Behavior
+
+### `rake rspec:uncommitted`
+
+This task will execute specs associated with files you have changed and not yet committed.
+
+### `rake rspec:unpushed`
+
+This task will execute specs for files you have committed locally, but haven't pushed up to origin.
+
+### `rake rspec:unmerged`
+
+This task will execute specs for files you have not yet merged back into the master branch.
+
+# Contribute
+
+See [http://github.com/rspec/rspec-dev](http://github.com/rspec/rspec-dev)
+
+# Also see
+
+* [http://github.com/rspec/rspec](http://github.com/rspec/rspec)
+* [http://github.com/rspec/rspec-core](http://github.com/rspec/rspec-core)
+* [http://github.com/rspec/rspec-rails](http://github.com/rspec/rspec-rails)
2  lib/rspec-rails-uncommitted.rb
View
@@ -3,7 +3,7 @@ module Rails
module Uncommitted
class Railtie < ::Rails::Railtie
rake_tasks do
- load "rspec/rails-uncommitted/tasks/rspec.rake"
+ load "rspec/rails/uncommitted/tasks/rspec.rake"
end
end
end
42 lib/rspec/rails-uncommitted/tasks/rspec.rake
View
@@ -1,42 +0,0 @@
-require 'rspec/core'
-require 'rspec/core/rake_task'
-
-# FIXME: these two settings are duplicated from rspec-rails
-orm_setting = Rails.configuration.generators.options[:rails][:orm]
-spec_prereq = if(orm_setting == :active_record)
- Rails.configuration.active_record[:schema_format] == :sql ? "db:test:clone_structure" : "db:test:prepare"
-else
- :noop
-end
-
-def uncommitted
- # cribbed from rails/railties/lib/rails/test_unit/testing.rake
- if File.directory?(".svn")
- changed_since_checkin = silence_stderr { `svn status` }.split.map { |path| path.chomp[7 .. -1] }
- elsif File.directory?(".git")
- changed_since_checkin = silence_stderr { `git ls-files --modified --others` }.split.map { |path| path.chomp }
- else
- abort "Not a Subversion or Git checkout."
- end
-end
-
-namespace :spec do
- desc "Run uncommitted specs"
- RSpec::Core::RakeTask.new(:uncommitted => spec_prereq) do |t|
- changed = uncommitted
-
- # cribbed from rails/railties/lib/rails/test_unit/testing.rake
- models = changed.select { |path| path =~ /app[\\\/]models[\\\/].*\.rb$/ }
- controllers = changed.select { |path| path =~ /app[\\\/]controllers[\\\/].*\.rb$/ }
-
- unit_tests = models.map { |model| "spec/models/#{File.basename(model, '.rb')}_spec.rb" }
- functional_tests = controllers.map { |controller| "spec/controllers/#{File.basename(controller, '.rb')}_spec.rb" }
- routing_tests = controllers.map { |controller| "spec/routing/#{File.basename(controller, '.rb').gsub("controller", "routing")}_spec.rb" }
- # Someone who thinks that view testing is awesome should probably write code for handling view specs.
-
- specs_to_run = (unit_tests + functional_tests).uniq.select { |file| File.exist?(file) }
-
- t.pattern = specs_to_run
- end
-end
-
79 lib/rspec/rails/uncommitted/tasks/rspec.rake
View
@@ -0,0 +1,79 @@
+require 'rspec/core'
+require 'rspec/core/rake_task'
+
+# FIXME: these two settings are duplicated from rspec-rails
+orm_setting = Rails.configuration.generators.options[:rails][:orm]
+spec_prereq = if(orm_setting == :active_record)
+ Rails.configuration.active_record[:schema_format] == :sql ? "db:test:clone_structure" : "db:test:prepare"
+else
+ :noop
+end
+
+def uncommitted
+ # cribbed from rails/railties/lib/rails/test_unit/testing.rake
+ if File.directory?(".svn")
+ changed_since_checkin = silence_stderr { `svn status` }.split.map { |path| path.chomp[7 .. -1] }
+ elsif File.directory?(".git")
+ changed_since_checkin = silence_stderr { `git ls-files --modified --others` }.split.map { |path| path.chomp }
+ else
+ abort "Not a Subversion or Git checkout."
+ end
+end
+
+def unpushed
+ if File.directory?(".git")
+ `git diff origin/#{current_branch} --stat`.split("\n")[0..-2].map{|path| path.chomp.split("\s").first}
+ else
+ abort "Not a Git checkout. (unpushed does not work with Subversion)"
+ end
+end
+
+def unmerged(branch="master")
+ if File.directory?(".git")
+ `git diff #{branch} --stat`.split("\n")[0..-2].map{|path| path.chomp.split("\s").first}
+ else
+ abort "Not a Git checkout. (unmerged does not work with Subversion)"
+ end
+end
+
+def current_branch
+ git_status[/On branch ([^\s]+)/, 1]
+end
+
+def git_status
+ @git_status ||= `git status`
+end
+
+def specs_to_run(changed)
+ # cribbed from rails/railties/lib/rails/test_unit/testing.rake
+ models = changed.select { |path| path =~ /app[\\\/]models[\\\/].*\.rb$/ }
+ controllers = changed.select { |path| path =~ /app[\\\/]controllers[\\\/].*\.rb$/ }
+
+ unit_tests = models.map { |model| "spec/models/#{File.basename(model, '.rb')}_spec.rb" }
+ functional_tests = controllers.map { |controller| "spec/controllers/#{File.basename(controller, '.rb')}_spec.rb" }
+ routing_tests = controllers.map { |controller| "spec/routing/#{File.basename(controller, '.rb').gsub("controller", "routing")}_spec.rb" }
+ # Someone who thinks that view testing is awesome should probably write code for handling view specs.
+
+ (unit_tests + functional_tests).uniq.select { |file| File.exist?(file) }
+end
+
+namespace :spec do
+ desc "Run uncommitted specs"
+ RSpec::Core::RakeTask.new(:uncommitted => spec_prereq) do |t|
+ t.pattern = specs_to_run uncommitted
+ end
+
+ desc "Run unmerged specs"
+ RSpec::Core::RakeTask.new(:unmerged => spec_prereq) do |t|
+ t.pattern = specs_to_run unmerged
+ end
+<<<<<<< HEAD
+
+ desc "Run unpushed specs"
+ RSpec::Core::RakeTask.new(:unpushed => spec_prereq) do |t|
+ t.pattern = specs_to_run unpushed
+ end
+=======
+>>>>>>> c47c1eedbfd3c35132c981d390573077dacde7d5
+end
+
8 rspec-rails-uncommitted.gemspec
View
@@ -4,7 +4,7 @@ require "rspec-rails-uncommitted/version"
Gem::Specification.new do |s|
s.name = "rspec-rails-uncommitted"
- s.version = Rspec::Rails::Uncommitted::VERSION
+ s.version = Rspec::Rails::Uncommitted::Version::STRING
s.platform = Gem::Platform::RUBY
s.authors = ["Marshall Yount"]
s.email = ["marshall@yountlabs.com"]
@@ -17,9 +17,9 @@ Gem::Specification.new do |s|
s.files = `git ls-files`.split("\n")
s.require_paths = ["lib"]
- if RSpec::Rails::Uncommitted::Version::STRING =~ /[a-zA-Z]+/ # prerelease builds
- s.add_runtime_dependency "rspec-rails", "= #{RSpec::Rails::Uncommitted::Version::STRING}"
+ if Rspec::Rails::Uncommitted::Version::STRING =~ /[a-zA-Z]+/ # prerelease builds
+ s.add_runtime_dependency "rspec-rails", "= #{Rspec::Rails::Uncommitted::Version::STRING}"
else
- s.add_runtime_dependency "rspec-rails", "~> #{RSpec::Rails::Uncommitted::Version::STRING.split('.')[0..1].concat(['0']).join('.')}"
+ s.add_runtime_dependency "rspec-rails", "~> #{Rspec::Rails::Uncommitted::Version::STRING.split('.')[0..1].concat(['0']).join('.')}"
end
end
Something went wrong with that request. Please try again.