diff --git a/.gitignore b/.gitignore index 57a1306..9ecbe40 100644 --- a/.gitignore +++ b/.gitignore @@ -8,3 +8,4 @@ tmp/ ext/Rakefile .bundle TAGS +*.gem diff --git a/Gemfile b/Gemfile index 471a774..8ecff81 100644 --- a/Gemfile +++ b/Gemfile @@ -1,7 +1,9 @@ source :gemcutter +gemspec gem 'cucumber', '~> 1.0.0' -gem 'rspec', '~> 2.6' +gem 'rspec', '~> 2.8' gem 'rake' +gem "spork", :path => File.expand_path("../", __FILE__) if RUBY_VERSION =~ /^1\.9/ gem 'ruby-debug19' diff --git a/Gemfile.lock b/Gemfile.lock index 82d3131..e02e24d 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,30 +1,40 @@ +PATH + remote: . + specs: + spork (0.9.0) + +PATH + remote: . + specs: + spork (0.9.0) + GEM remote: http://rubygems.org/ specs: archive-tar-minitar (0.5.2) builder (3.0.0) columnize (0.3.6) - cucumber (1.0.0) + cucumber (1.0.6) builder (>= 2.1.2) diff-lcs (>= 1.1.2) - gherkin (~> 2.4.1) + gherkin (~> 2.4.18) json (>= 1.4.6) - term-ansicolor (>= 1.0.5) - diff-lcs (1.1.2) - gherkin (2.4.1) + term-ansicolor (>= 1.0.6) + diff-lcs (1.1.3) + gherkin (2.4.21) json (>= 1.4.6) - json (1.5.3) + json (1.6.5) linecache19 (0.5.12) ruby_core_source (>= 0.1.4) - rake (0.8.7) - rspec (2.6.0) - rspec-core (~> 2.6.0) - rspec-expectations (~> 2.6.0) - rspec-mocks (~> 2.6.0) - rspec-core (2.6.3) - rspec-expectations (2.6.0) + rake (0.9.2.2) + rspec (2.8.0) + rspec-core (~> 2.8.0) + rspec-expectations (~> 2.8.0) + rspec-mocks (~> 2.8.0) + rspec-core (2.8.0) + rspec-expectations (2.8.0) diff-lcs (~> 1.1.2) - rspec-mocks (2.6.0) + rspec-mocks (2.8.0) ruby-debug-base19 (0.11.25) columnize (>= 0.3.1) linecache19 (>= 0.5.11) @@ -35,7 +45,7 @@ GEM ruby-debug-base19 (>= 0.11.19) ruby_core_source (0.1.5) archive-tar-minitar (>= 0.5.2) - term-ansicolor (1.0.5) + term-ansicolor (1.0.7) PLATFORMS ruby @@ -43,5 +53,6 @@ PLATFORMS DEPENDENCIES cucumber (~> 1.0.0) rake - rspec (~> 2.6) + rspec (~> 2.8) ruby-debug19 + spork! diff --git a/README.rdoc b/README.rdoc index c292112..6eec127 100644 --- a/README.rdoc +++ b/README.rdoc @@ -20,40 +20,42 @@ Spork runs on POSIX systems using fork. It also runs on windows by pre-populatin == Supported Application Frameworks -Actually, Spork ~can~ work with any application framework. But, it ships with hooks and helpers to make an "out of the box" experience. +Spork can work with any application framework, but needs work to prevent application files from being eager loaded. -* Rails 3.0 (for Rails 2.{1,2,3}.x, please try spork 0.8.x) -* Padrino +See https://github.com/sporkrb/spork/wiki/Supported-Application-Frameworks for a list of supported frameworks and their gems. == INSTALL: === rubygems: - [sudo] gem install spork --prerelease - -(Rails 2.x) - - [sudo] gem install spork --version 0.8.4 + [sudo] gem install spork === bundler: Add to your Gemfile: - gem 'spork', '~> 0.9.0.rc' - -(Rails 2.x, use this) - - gem 'spork', '~> 0.8' + gem 'spork', '~> 0.9.0' == Usage From a terminal, change to your project directory. -Then, bootstrap your spec/spec_helper.rb file. +Then, bootstrap your test helper file. If running rspec, + + spork rspec --bootstrap + +Cucumber: + + spork cucumber --bootstrap + +TestUnit: + + (Install the spork-testunit gem) + spork test_unit --bootstrap - spork --bootstrap +If you don't specifiy a test framework, spork will find one and pick it. -Next, edit spec/spec_helper.rb and follow the instructions that were put at the top. +Follow the instructions. Finally, run spork. A spec DRb server will be running! @@ -131,4 +133,4 @@ See http://wiki.github.com/sporkrb/spork/troubleshooting * Roger Pack - JRuby support / Windows * Donald Parish - Windows support (Magazine strategy) -Spork (c) 2011 Tim Harper, released under the MIT license +Spork (c) 2012 Tim Harper, released under the MIT license diff --git a/features/cucumber_rails_integration.feature b/features/cucumber_rails_integration.feature deleted file mode 100644 index f63cd87..0000000 --- a/features/cucumber_rails_integration.feature +++ /dev/null @@ -1,107 +0,0 @@ -Feature: Cucumber integration with rails - As a developer using cucumber and rails - I want to use Spork with Cucumber - In order to eliminate the startup cost of my application each time I run them - - Background: Sporked env.rb - Given I am in a fresh rails project named "test_rails_project" - And the application has a model, observer, route, and application helper - And a file named "features/support/env.rb" with: - """ - require 'rubygems' - require 'spork' - ENV["RAILS_ENV"] ||= "test" - - - Spork.prefork do - # Loading more in this block will cause your tests to run faster. However, - # if you change any configuration or code from libraries loaded here, you'll - # need to restart spork for it take effect. - - # Sets up the Rails environment for Cucumber - require File.expand_path(File.dirname(__FILE__) + '/../../config/environment') - - require 'cucumber' - require 'cucumber/formatter/unicode' # Comment out this line if you don't want Cucumber Unicode support - require 'rspec/rails' - require 'cucumber/rails/rspec' - - #### this is for this test only ####### - $loaded_stuff << 'prefork block' ###### - ####################################### - end - - Spork.each_run do - #### this is for this test only ####### - $loaded_stuff << 'each_run block' ##### - ####################################### - end - """ - And a file named "features/cucumber_rails.feature" with: - """ - Feature: cucumber rails - Scenario: did it work? - Then it should work - - Scenario: did it work again? - Then it should work - """ - And a file named "features/support/cucumber_rails_helper.rb" with: - """ - $loaded_stuff << 'features/support/cucumber_rails_helper.rb' - """ - And a file named "config/database.yml" with: - """ - test: - adapter: sqlite3 - database: db/test.sqlite3 - timeout: 5000 - """ - And a file named "features/step_definitions/cucumber_rails_steps.rb" with: - """ - Then "it should work" do - (Rails.respond_to?(:logger) ? Rails.logger : ActionController::Base.logger).info "hey there" - $loaded_stuff.should include('ActiveRecord::Base.establish_connection') - $loaded_stuff.should include('User') - $loaded_stuff.should include('UserObserver') - $loaded_stuff.should include('ApplicationHelper') - $loaded_stuff.should include('config/routes.rb') - $loaded_stuff.should include('features/support/cucumber_rails_helper.rb') - $loaded_stuff.should include('each_run block') - $loaded_stuff.should include('prefork block') - puts "It worked!" - end - - Alors /ca marche/ do - end - """ - Scenario: Analyzing files were preloaded - When I run spork --diagnose - Then the output should not contain "user_observer.rb" - Then the output should not contain "user.rb" - Then the output should not contain "app/controllers/application.rb" - Then the output should not contain "app/controllers/application_controller.rb" - Then the output should not contain "app/controllers/application_helper.rb" - Then the output should not contain "features/step_definitions/cucumber_rails_steps.rb" - Then the output should not contain "features/support/cucumber_rails_helper.rb" - - Scenario: Running spork with a rails app and no server - When I run cucumber --drb features - Then the error output should contain - """ - WARNING: No DRb server is running. Running features locally - """ - - Scenario: Running spork with a rails app and observers - When I fire up a spork instance with "spork cucumber" - And I run cucumber --drb features - Then the error output should be empty - And the output should contain "It worked!" - And the file "log/test.log" should include "hey there" - - Scenario: Running spork with a rails app and a non-standard port - When I fire up a spork instance with "spork cucumber -p 9000" - And I run cucumber --drb --port 9000 features - Then the error output should be empty - And the output should contain "It worked!" - And the file "log/test.log" should include "hey there" diff --git a/features/diagnostic_mode.feature b/features/diagnostic_mode.feature index 357760c..c879faa 100644 --- a/features/diagnostic_mode.feature +++ b/features/diagnostic_mode.feature @@ -11,7 +11,7 @@ Feature: Diagnostic Mode require 'spork' Spork.prefork do - require 'lib/awesome.rb' + require './lib/awesome.rb' require '../external_dependency/super_duper.rb' end @@ -38,4 +38,3 @@ Feature: Diagnostic Mode And the output should contain "spec/spec_helper.rb:5" And the output should not contain "super_duper.rb" And the output should not contain "diagnose.rb" - \ No newline at end of file diff --git a/features/gemfiles/rails3.0/Gemfile b/features/gemfiles/rails3.0/Gemfile deleted file mode 100644 index 08d45d0..0000000 --- a/features/gemfiles/rails3.0/Gemfile +++ /dev/null @@ -1,14 +0,0 @@ -source :gemcutter -gem 'sqlite3-ruby', '1.2.5' -gem 'cucumber', '~> 1.0.0' -gem 'cucumber-rails', '~> 1.0.0' -gem "rspec", "2.5.0" -gem 'rspec-rails', "2.5.0" -gem 'rails', '3.0.7' - -if RUBY_VERSION =~ /^1\.9/ - gem 'ruby-debug19' -else - gem 'ruby-debug', '>= 0.10.3' -end -gem 'spork', :path => File.expand_path("../../..", File.dirname(__FILE__)) diff --git a/features/gemfiles/rails3.0/Gemfile.lock b/features/gemfiles/rails3.0/Gemfile.lock deleted file mode 100644 index 15be489..0000000 --- a/features/gemfiles/rails3.0/Gemfile.lock +++ /dev/null @@ -1,139 +0,0 @@ -PATH - remote: /Users/timcharper/projects/spork - specs: - spork (0.9.0.rc8) - -GEM - remote: http://rubygems.org/ - specs: - abstract (1.0.0) - actionmailer (3.0.7) - actionpack (= 3.0.7) - mail (~> 2.2.15) - actionpack (3.0.7) - activemodel (= 3.0.7) - activesupport (= 3.0.7) - builder (~> 2.1.2) - erubis (~> 2.6.6) - i18n (~> 0.5.0) - rack (~> 1.2.1) - rack-mount (~> 0.6.14) - rack-test (~> 0.5.7) - tzinfo (~> 0.3.23) - activemodel (3.0.7) - activesupport (= 3.0.7) - builder (~> 2.1.2) - i18n (~> 0.5.0) - activerecord (3.0.7) - activemodel (= 3.0.7) - activesupport (= 3.0.7) - arel (~> 2.0.2) - tzinfo (~> 0.3.23) - activeresource (3.0.7) - activemodel (= 3.0.7) - activesupport (= 3.0.7) - activesupport (3.0.7) - arel (2.0.9) - builder (2.1.2) - capybara (1.0.0) - mime-types (>= 1.16) - nokogiri (>= 1.3.3) - rack (>= 1.0.0) - rack-test (>= 0.5.4) - selenium-webdriver (~> 0.2.0) - xpath (~> 0.1.4) - childprocess (0.1.9) - ffi (~> 1.0.6) - columnize (0.3.2) - cucumber (1.0.0) - builder (>= 2.1.2) - diff-lcs (>= 1.1.2) - gherkin (~> 2.4.1) - json (>= 1.4.6) - term-ansicolor (>= 1.0.5) - cucumber-rails (1.0.2) - capybara (>= 1.0.0) - cucumber (~> 1.0.0) - nokogiri (>= 1.4.6) - diff-lcs (1.1.2) - erubis (2.6.6) - abstract (>= 1.0.0) - ffi (1.0.9) - gherkin (2.4.1) - json (>= 1.4.6) - i18n (0.5.0) - json (1.5.3) - json_pure (1.5.3) - linecache (0.43) - mail (2.2.19) - activesupport (>= 2.3.6) - i18n (>= 0.4.0) - mime-types (~> 1.16) - treetop (~> 1.4.8) - mime-types (1.16) - nokogiri (1.4.6) - polyglot (0.3.1) - rack (1.2.2) - rack-mount (0.6.14) - rack (>= 1.0.0) - rack-test (0.5.7) - rack (>= 1.0) - rails (3.0.7) - actionmailer (= 3.0.7) - actionpack (= 3.0.7) - activerecord (= 3.0.7) - activeresource (= 3.0.7) - activesupport (= 3.0.7) - bundler (~> 1.0) - railties (= 3.0.7) - railties (3.0.7) - actionpack (= 3.0.7) - activesupport (= 3.0.7) - rake (>= 0.8.7) - thor (~> 0.14.4) - rake (0.8.7) - rspec (2.5.0) - rspec-core (~> 2.5.0) - rspec-expectations (~> 2.5.0) - rspec-mocks (~> 2.5.0) - rspec-core (2.5.2) - rspec-expectations (2.5.0) - diff-lcs (~> 1.1.2) - rspec-mocks (2.5.0) - rspec-rails (2.5.0) - actionpack (~> 3.0) - activesupport (~> 3.0) - railties (~> 3.0) - rspec (~> 2.5.0) - ruby-debug (0.10.4) - columnize (>= 0.1) - ruby-debug-base (~> 0.10.4.0) - ruby-debug-base (0.10.4) - linecache (>= 0.3) - rubyzip (0.9.4) - selenium-webdriver (0.2.2) - childprocess (>= 0.1.9) - ffi (>= 1.0.7) - json_pure - rubyzip - sqlite3-ruby (1.2.5) - term-ansicolor (1.0.5) - thor (0.14.6) - treetop (1.4.9) - polyglot (>= 0.3.1) - tzinfo (0.3.27) - xpath (0.1.4) - nokogiri (~> 1.3) - -PLATFORMS - ruby - -DEPENDENCIES - cucumber (~> 1.0.0) - cucumber-rails (~> 1.0.0) - rails (= 3.0.7) - rspec (= 2.5.0) - rspec-rails (= 2.5.0) - ruby-debug (>= 0.10.3) - spork! - sqlite3-ruby (= 1.2.5) diff --git a/features/rails_delayed_loading_workarounds.feature b/features/rails_delayed_loading_workarounds.feature deleted file mode 100644 index e4f38cd..0000000 --- a/features/rails_delayed_loading_workarounds.feature +++ /dev/null @@ -1,177 +0,0 @@ -Feature: Rails Delayed Work arounds - To allow a rails developer to update as many parts of his application as possible without needing to restart Spork - Spork automatically tells rails to delay loading certain parts of the application until after the fork occurs - - Background: Rails App with RSpec and Spork - - Given I am in a fresh rails project named "test_rails_project" - And a file named "spec/spec_helper.rb" with: - """ - require 'rubygems' - require 'spork' - require 'spork/ext/ruby-debug' - - Spork.prefork do - require File.dirname(__FILE__) + '/../config/environment.rb' - require 'rspec' - require 'rspec/rails' - end - - Spork.each_run do - end - """ - And the application has a model, observer, route, and application helper - - Given the following code appears in "config/routes.rb" after /routes\.draw/: - """ - resources :users - """ - Given a file named "app/helpers/application_helper.rb" with: - """ - require 'reverseatron' - module ApplicationHelper - include Reverseatron - end - """ - Given a file named "lib/reverseatron.rb" with: - """ - module Reverseatron - def reverse_text(txt) - txt.reverse - end - end - """ - Given a file named "app/controllers/users_controller.rb" with: - """ - class UsersController < ApplicationController - $loaded_stuff << 'UsersController' - def index - @users = [] - end - end - """ - Given a file named "app/helpers/misc_helper.rb" with: - """ - module MiscHelper - def misc_helper_method - 'hello miscellaneous' - end - end - """ - Given a file named "app/helpers/users_helper.rb" with: - """ - module UsersHelper - end - """ - Given a file named "app/views/users/index.html.erb" with: - """ - Original View - """ - Scenario: respecting custom autoload paths - Given the following code appears in "config/application.rb" after /class Application < Rails::Application/: - """ - config.autoload_paths << 'app/models/non_standard' - """ - - And a file named "app/models/non_standard/boogie.rb" with: - """ - class Boogie - def boogie - 'Boogie Robots!' - end - end - """ - And a file named "spec/models/non_standard/boogie_spec.rb" with: - """ - describe Boogie do - it 'knows how to boogie' do - Boogie.new.boogie.should include('Boogie') - puts 'BOOGIE!!!' - end - end - """ - When I fire up a spork instance with "spork rspec" - And I run rspec --drb spec/models/non_standard/boogie_spec.rb - Then the output should contain "BOOGIE!!!" - - Scenario: within a view rendered by a controller, calling helper methods from an included module in ApplicationHelper - Given a file named "spec/controllers/users_controller_spec.rb" with: - """ - require "spec_helper" - describe UsersController do - render_views - it "renders a page, using a method inherited from ApplicationController" do - get :index - response.body.should_not include('Original View') - puts "Views are not being cached when rendering from a controller" - - response.body.should include('listing users') - puts "Controller stack is functioning when rendering from a controller" - - response.body.should include('hello miscellaneous') - puts "All helper modules were included when rendering from a controller" - end - end - """ - Given a file named "spec/views/index.html.erb_spec.rb" with: - """ - require "spec_helper" - describe "/users/index.html.erb" do - - it "renders the view" do - render - rendered.should_not include('Original View') - puts "Views are not being cached when rendering directly" - - rendered.should include('listing users') - puts "Controller stack is functioning when rendering directly" - - rendered.should include('hello miscellaneous') - puts "All helper modules were included when rendering directly" - end - end - """ - When I fire up a spork instance with "spork rspec" - And the contents of "app/views/users/index.html.erb" are changed to: - """ - <%= reverse_text('listing users'.reverse) %> - <%= misc_helper_method rescue nil %> -

Here is a list of users

- """ - - And I run rspec --drb spec/controllers/users_controller_spec.rb - Then the output should contain "Controller stack is functioning when rendering from a controller" - And the output should contain "Views are not being cached when rendering from a controller" - And the output should contain "All helper modules were included when rendering from a controller" - - When I run rspec --drb spec/views/index.html.erb_spec.rb - Then the output should contain "Controller stack is functioning when rendering directly" - And the output should contain "Views are not being cached when rendering directly" - And the output should contain "All helper modules were included when rendering directly" - - Given the contents of "app/helpers/application_helper.rb" are changed to: - """ - module ApplicationHelper - def make_it_loud(message) - message.upcase - end - end - """ - And the contents of "app/views/users/index.html.erb" are changed to: - """ - <%= make_it_loud('listing users') %> - """ - And the contents of "spec/controllers/users_controller_spec.rb" are changed to: - """ - require "spec_helper" - describe UsersController do - render_views - it "renders a page, using a method inherited from ApplicationController" do - get :index - response.body.should include('LISTING USERS') - puts "Helpers aren't being cached" - end - end - """ - When I run rspec --drb spec/controllers/users_controller_spec.rb - Then the output should contain "Helpers aren't being cached" diff --git a/features/rspec_rails_integration.feature b/features/rspec_rails_integration.feature deleted file mode 100644 index 961301e..0000000 --- a/features/rspec_rails_integration.feature +++ /dev/null @@ -1,92 +0,0 @@ -Feature: Rails Integration - To get a developer up and running quickly - Spork automatically integrates with rails - Providing default hooks and behaviors - - Background: Rails App with RSpec and Spork - Given I am in a fresh rails project named "test_rails_project" - And a file named "spec/spec_helper.rb" with: - """ - require 'rubygems' - require 'spork' - - Spork.prefork do - # Loading more in this block will cause your specs to run faster. However, - # if you change any configuration or code from libraries loaded here, you'll - # need to restart spork for it take effect. - require File.dirname(__FILE__) + '/../config/environment.rb' - require 'rspec' - require 'rspec/rails' - - #### this is for this test only ####### - $loaded_stuff << 'prefork block' ###### - ####################################### - end - - Spork.each_run do - # This code will be run each time you run your specs. - - #### this is for this test only ####### - $loaded_stuff << 'each_run block' ##### - ####################################### - end - """ - And the application has a model, observer, route, and application helper - Scenario: Analyzing files were preloaded - When I run spork --diagnose - Then the output should not contain "user_observer.rb" - Then the output should not contain "user.rb" - Then the output should not contain "app/controllers/application.rb" - Then the output should not contain "app/controllers/application_controller.rb" - Then the output should not contain "app/controllers/application_helper.rb" - # Then the output should not contain "config/routes.rb" - - Scenario: Running spork with a rails app and observers - Given a file named "spec/did_it_work_spec.rb" with: - """ - require 'spec_helper' - describe "Did it work?" do - it "checks to see if all worked" do - Spork.using_spork?.should == true - (Rails.respond_to?(:logger) ? Rails.logger : ActionController::Base.logger).info "hey there" - $loaded_stuff.should include('ActiveRecord::Base.establish_connection') - $loaded_stuff.should include('User') - $loaded_stuff.should include('UserObserver') - $loaded_stuff.should include('ApplicationHelper') - $loaded_stuff.should include('config/routes.rb') - $loaded_stuff.should include('each_run block') - $loaded_stuff.should include('prefork block') - puts "Specs successfully run within spork, and all initialization files were loaded" - end - end - """ - When I fire up a spork instance with "spork rspec" - And I run rspec --drb spec/did_it_work_spec.rb - Then the error output should be empty - And the output should contain "Specs successfully run within spork, and all initialization files were loaded" - And the file "log/test.log" should include "hey there" - - - Scenario: Running spork with a rails app and a non-standard port - Given a file named "spec/did_it_work_spec.rb" with: - """ - describe "Did it work?" do - it "checks to see if all worked" do - Spork.using_spork?.should == true - (Rails.respond_to?(:logger) ? Rails.logger : ActionController::Base.logger).info "hey there" - $loaded_stuff.should include('ActiveRecord::Base.establish_connection') - $loaded_stuff.should include('User') - $loaded_stuff.should include('UserObserver') - $loaded_stuff.should include('ApplicationHelper') - $loaded_stuff.should include('config/routes.rb') - $loaded_stuff.should include('each_run block') - $loaded_stuff.should include('prefork block') - puts "Specs successfully run within spork, and all initialization files were loaded" - end - end - """ - When I fire up a spork instance with "spork rspec --port 7000" - And I run rspec --drb --drb-port 7000 spec/did_it_work_spec.rb - Then the error output should be empty - And the output should contain "Specs successfully run within spork, and all initialization files were loaded" - And the file "log/test.log" should include "hey there" diff --git a/features/steps/rails_steps.rb b/features/steps/rails_steps.rb deleted file mode 100644 index aaf3fb6..0000000 --- a/features/steps/rails_steps.rb +++ /dev/null @@ -1,67 +0,0 @@ -Given /^I am in a fresh rails project named "(.+)"$/ do |folder_name| - @current_dir = SporkWorld::SANDBOX_DIR - # version_argument = ENV['RAILS_VERSION'] ? "_#{ENV['RAILS_VERSION']}_" : nil - # run("#{SporkWorld::RUBY_BINARY} #{%x{which rails}.chomp} #{folder_name}") - run(["rails", "new", folder_name].compact * " ") - - if last_exit_status != 0 - puts "Couldn't generate project. Output:\nSTDERR:\n-------\n#{last_stderr}\n------\n\nSTDOUT:\n-------\n#{last_stdout}\n\n" - last_exit_status.should == 0 - end - @current_dir = File.join(File.join(SporkWorld::SANDBOX_DIR, folder_name)) - in_current_dir do - FileUtils.ln_sf(ENV["BUNDLE_GEMFILE"], "Gemfile") - FileUtils.ln_sf(ENV["BUNDLE_GEMFILE"] + ".lock", "Gemfile.lock") - FileUtils.ln_sf(File.dirname(ENV["BUNDLE_GEMFILE"]) + "/.bundle", ".bundle") - end -end - - -Given "the application has a model, observer, route, and application helper" do - Given 'the following code appears in "config/application.rb" after /^end/:', - """ - ActiveRecord::Base.observers = [:user_observer] - """ - Given 'a file named "app/models/user.rb" with:', - """ - class User < ActiveRecord::Base - $loaded_stuff << 'User' - end - """ - Given 'a file named "app/models/user_observer.rb" with:', - """ - class UserObserver < ActiveRecord::Observer - $loaded_stuff << 'UserObserver' - end - """ - Given 'a file named "app/helpers/application_helper.rb" with:', - """ - module ApplicationHelper - $loaded_stuff << 'ApplicationHelper' - end - """ - Given 'the following code appears in "config/environment.rb" after /Rails::Initializer.run/:', - """ - config.active_record.observers = :user_observer - """ - Given 'the following code appears in "config/routes.rb" after /^end/:', - """ - $loaded_stuff << 'config/routes.rb' - """ - Given 'a file named "config/initializers/initialize_loaded_stuff.rb" with:', - """ - $loaded_stuff ||= [] - """ - Given 'a file named "config/initializers/log_establish_connection_calls.rb" with:', - """ - class ActiveRecord::Base - class << self - def establish_connection_with_load_logging(*args) - $loaded_stuff << 'ActiveRecord::Base.establish_connection' - establish_connection_without_load_logging(*args) - end - alias_method_chain :establish_connection, :load_logging - end - end - """ -end diff --git a/features/support/bundler_helpers.rb b/features/support/bundler_helpers.rb index e94fd9a..b270d9c 100644 --- a/features/support/bundler_helpers.rb +++ b/features/support/bundler_helpers.rb @@ -1,4 +1,3 @@ -require 'bundler' module BundlerHelpers extend self def install_bundle(dir) @@ -19,7 +18,7 @@ def ensure_installed(dir) FileUtils.rm(gemfile_lock) FileUtils.rm_rf(dir + "/.bundle") when ! File.exist?(bundle_environment) - puts "Bundle #{gemfile} not installed. Installing..." + puts "Installing bundle #{gemfile}..." when File.mtime(bundle_environment) < File.mtime(gemfile_lock) puts "#{gemfile_lock} is newer than #{bundle_environment}. Reinstalling" else @@ -28,13 +27,8 @@ def ensure_installed(dir) install_bundle(dir) end - def expand_gemfile(gemfile) - possibilities = [File.expand_path(gemfile, Dir.pwd), SporkWorld::GEMFILES_ROOT + gemfile + "Gemfile"] - possibilities.detect {|f| File.exist?(f)} || raise(RuntimeError, %(Gemfile not found:\n #{possibilities * "\n"})) - end - def set_gemfile(gemfile) - gemfile = expand_gemfile(gemfile || "rails3.0") + gemfile = File.expand_path(gemfile) ensure_installed(File.dirname(gemfile)) ENV["BUNDLE_GEMFILE"] = gemfile.to_s end diff --git a/features/support/env.rb b/features/support/env.rb index 6f829d2..419740a 100644 --- a/features/support/env.rb +++ b/features/support/env.rb @@ -1,105 +1,18 @@ require 'rubygems' require 'pathname' -require 'fileutils' -require 'forwardable' -require 'tempfile' require 'rspec/expectations' require 'timeout' -require(File.dirname(__FILE__) + '/background_job.rb') - -SPORK_ROOT = Pathname.new(File.expand_path('../../', File.dirname(__FILE__))) -class SporkWorld - RUBY_BINARY = File.join(Config::CONFIG['bindir'], Config::CONFIG['ruby_install_name']) - BINARY = SPORK_ROOT + 'bin/spork' - SANDBOX_DIR = SPORK_ROOT + "tmp/sandbox" - GEMFILES_ROOT = SPORK_ROOT + "features/gemfiles" - SPORK_LIBDIR = SPORK_ROOT + "lib" - - extend Forwardable - def_delegators SporkWorld, :sandbox_dir, :spork_lib_dir - - def spork_lib_dir - @spork_lib_dir ||= File.expand_path(File.join(File.dirname(__FILE__), '../../lib')) - end - - def initialize - @current_dir = SANDBOX_DIR - @background_jobs = [] - end - - private - attr_reader :last_exit_status, :last_stderr, :last_stdout, :background_jobs - def last_stderr - return @last_stderr if @last_stderr - if @background_job - @last_stderr = @background_job.stderr.read - end - end - - - def last_stdout - return @last_stdout if @last_stdout - if @background_job - @last_stdout = @background_job.stdout.read - end - end - - def create_file(file_name, file_content) - file_content.gsub!("SPORK_LIB", "'#{spork_lib_dir}'") # Some files, such as Rakefiles need to use the lib dir - in_current_dir do - FileUtils.mkdir_p(File.dirname(file_name)) - File.open(file_name, 'w') { |f| f << file_content } - end - end - - def in_current_dir(&block) - Dir.chdir(@current_dir, &block) - end - - def run(command) - stderr_file = Tempfile.new('spork') - stderr_file.close - in_current_dir do - @last_stdout = `env RUBYOPT= bundle exec #{command} 2> #{stderr_file.path}` - @last_exit_status = $?.exitstatus - end - @last_stderr = IO.read(stderr_file.path) - end - - def run_in_background(command) - in_current_dir do - @background_job = BackgroundJob.run("env RUBYOPT= bundle exec " + command) - end - @background_jobs << @background_job - @background_job - end - - def terminate_background_jobs - if @background_jobs - @background_jobs.each do |background_job| - background_job.kill - end - end - @background_jobs.clear - @background_job = nil - end -end - -require((SPORK_ROOT + "features/support/bundler_helpers.rb").to_s) -BundlerHelpers.set_gemfile(ENV["GEMFILE"]) +APP_ROOT = Pathname.new(File.expand_path('../../', File.dirname(__FILE__))) +SANDBOX_DIR = APP_ROOT + "tmp/sandbox" +require(APP_ROOT + "features/support/background_job.rb") +require(APP_ROOT + "features/support/spork_world.rb") World do SporkWorld.new end -Before do - FileUtils.rm_rf SporkWorld::SANDBOX_DIR - FileUtils.mkdir_p SporkWorld::SANDBOX_DIR -end - -After do - # FileUtils.rm_rf SporkWorld::SANDBOX_DIR - terminate_background_jobs -end +# FileUtils.rm_rf SporkWorld::SANDBOX_DIR +Before { reset_sandbox_dir } +After { terminate_background_jobs } diff --git a/features/support/spork_world.rb b/features/support/spork_world.rb new file mode 100644 index 0000000..daee309 --- /dev/null +++ b/features/support/spork_world.rb @@ -0,0 +1,84 @@ +require 'forwardable' +require 'fileutils' +require 'tempfile' +require 'pathname' + +class SporkWorld + SPORK_ROOT = Pathname.new(File.expand_path('../../', File.dirname(__FILE__))) + RUBY_BINARY = File.join(Config::CONFIG['bindir'], Config::CONFIG['ruby_install_name']) + BINARY = SPORK_ROOT + 'bin/spork' + + extend Forwardable + def_delegators SporkWorld, :sandbox_dir, :spork_lib_dir + + def spork_lib_dir + @spork_lib_dir ||= File.expand_path(File.join(File.dirname(__FILE__), '../../lib')) + end + + def initialize + @current_dir = SANDBOX_DIR + @background_jobs = [] + end + + private + attr_reader :last_exit_status, :last_stderr, :last_stdout, :background_jobs + def last_stderr + return @last_stderr if @last_stderr + if @background_job + @last_stderr = @background_job.stderr.read + end + end + + + def last_stdout + return @last_stdout if @last_stdout + if @background_job + @last_stdout = @background_job.stdout.read + end + end + + def create_file(file_name, file_content) + file_content.gsub!("SPORK_LIB", "'#{spork_lib_dir}'") # Some files, such as Rakefiles need to use the lib dir + in_current_dir do + FileUtils.mkdir_p(File.dirname(file_name)) + File.open(file_name, 'w') { |f| f << file_content } + end + end + + def in_current_dir(&block) + Dir.chdir(@current_dir, &block) + end + + def run(command) + stderr_file = Tempfile.new('spork') + stderr_file.close + in_current_dir do + @last_stdout = `env RUBYOPT= bundle exec #{command} 2> #{stderr_file.path}` + @last_exit_status = $?.exitstatus + end + @last_stderr = IO.read(stderr_file.path) + end + + def run_in_background(command) + in_current_dir do + @background_job = BackgroundJob.run("env RUBYOPT= bundle exec " + command) + end + @background_jobs << @background_job + @background_job + end + + def terminate_background_jobs + if @background_jobs + @background_jobs.each do |background_job| + background_job.kill + end + end + @background_jobs.clear + @background_job = nil + end + + def reset_sandbox_dir + FileUtils.rm_rf SANDBOX_DIR + FileUtils.mkdir_p SANDBOX_DIR + end +end diff --git a/features/unknown_app_framework.feature b/features/unknown_app_framework.feature index dc15ade..e7263f6 100644 --- a/features/unknown_app_framework.feature +++ b/features/unknown_app_framework.feature @@ -7,7 +7,7 @@ Feature: Unknown app frameworks Given a file named "spec/spec_helper.rb" with: """ require 'rubygems' - require 'spec' + require 'rspec' """ When I run spork Then the error output should contain "Using RSpec" @@ -16,11 +16,10 @@ Feature: Unknown app frameworks Scenario: Sporked spec_helper Given a file named "spec/spec_helper.rb" with: """ - require 'rubygems' require 'spork' Spork.prefork do - require 'spec' + require 'rspec' end Spork.each_run do @@ -31,12 +30,11 @@ Feature: Unknown app frameworks """ describe "Did it work?" do it "checks to see if all worked" do - Spork.state.should == :using_spork - puts "Specs successfully run within spork" + Spork.using_spork?.should == true + puts 'Specs successfully run within spork' end end """ When I fire up a spork instance with "spork rspec" - And I run spec --drb spec/did_it_work_spec.rb + And I run rspec --drb spec/did_it_work_spec.rb Then the output should contain "Specs successfully run within spork" - \ No newline at end of file diff --git a/lib/spork.rb b/lib/spork.rb index 867d72e..2773422 100644 --- a/lib/spork.rb +++ b/lib/spork.rb @@ -11,7 +11,6 @@ module Spork autoload :Runner, (LIBDIR + 'spork/runner').to_s autoload :Forker, (LIBDIR + 'spork/forker').to_s autoload :Diagnoser, (LIBDIR + 'spork/diagnoser').to_s - autoload :GemHelpers, (LIBDIR + 'spork/gem_helpers').to_s class << self # Run a block, during prefork mode. By default, if prefork is called twice in the same file and line number, the supplied block will only be ran once. @@ -98,15 +97,9 @@ def trap_class_method(klass, method_name) end def detect_and_require(subfolder) - ([LIBDIR.to_s] + other_spork_gem_load_paths).uniq.each do |gem_path| - Dir.glob(File.join(gem_path, subfolder)).each { |file| require file } - end - end - - # This method is used to auto-discover peer plugins such as spork-testunit. - def other_spork_gem_load_paths - @other_spork_gem_load_paths ||= Spork::GemHelpers.latest_load_paths.grep(/spork/).select do |g| - not g.match(%r{/spork-[0-9\-.]+/lib}) # don't include other versions of spork + Gem.find_files(subfolder).uniq.each do |path| + next if path.match(/_spec\.rb/) + require path end end diff --git a/lib/spork/app_framework.rb b/lib/spork/app_framework.rb index d449bb5..bce795f 100644 --- a/lib/spork/app_framework.rb +++ b/lib/spork/app_framework.rb @@ -1,41 +1,23 @@ class Spork::AppFramework - # A hash of procs where the key is the class name, and the proc takes no arguments and returns true if it detects that said application framework is being used in the project. - # - # The key :Rails maps to Spork::AppFramework::Rails - # - # This is used to reduce the amount of code needed to be loaded - only the detected application framework's support code is loaded. - SUPPORTED_FRAMEWORKS = { - :Padrino => lambda { - File.exist?("config/boot.rb") && File.read("config/boot.rb").include?('PADRINO') - }, - :Rails => lambda { - File.exist?("config/environment.rb") && ( - File.read("config/environment.rb").include?('RAILS_GEM_VERSION') || - (File.exist?("config/application.rb") && File.read("config/application.rb").include?("Rails::Application")) - ) - } - } unless defined? SUPPORTED_FRAMEWORKS - - def self.setup_autoload - ([:Unknown] + SUPPORTED_FRAMEWORKS.keys).each do |name| - autoload name, File.join(File.dirname(__FILE__), "app_framework", name.to_s.downcase) - end + APP_FRAMEWORKS = [] + def self.inherited(child) + APP_FRAMEWORKS << child end - # Iterates through all SUPPORTED_FRAMEWORKS and returns the symbolic name of the project application framework detected. Otherwise, returns :Unknown def self.detect_framework_name - SUPPORTED_FRAMEWORKS.each do |key, value| - return key if value.call - end - :Unknown + detect_framework.short_name end # Same as detect_framework_name, but returns an instance of the specific AppFramework class. - def self.detect_framework - name = detect_framework_name - self[name] + def self.detect_framework_class + APP_FRAMEWORKS.select(&:present?).first || Spork::AppFramework::Unknown end + # Same as detect_framework_name, but returns an instance of the specific AppFramework class. + def self.detect_framework + detect_framework_class.new + end + # Initializes, stores, and returns a singleton instance of the named AppFramework. # # == Parameters @@ -70,6 +52,10 @@ def preload(&block) def short_name self.class.short_name end + + def self.present? + raise "#{self} should have defined #{self}.present?, but didn't" + end protected def self.instances @@ -77,4 +63,4 @@ def self.instances end end -Spork::AppFramework.setup_autoload \ No newline at end of file +Spork.detect_and_require('spork/app_framework/*.rb') diff --git a/lib/spork/app_framework/padrino.rb b/lib/spork/app_framework/padrino.rb deleted file mode 100644 index 1d5f66a..0000000 --- a/lib/spork/app_framework/padrino.rb +++ /dev/null @@ -1,22 +0,0 @@ -class Spork::AppFramework::Padrino < Spork::AppFramework - - def preload(&block) - STDERR.puts "Preloading Padrino environment" - STDERR.flush - ENV["PADRINO_ENV"] ||= "test" - require boot_file - # Make it so that we don't have to restart Spork if we change, say, a model or routes - Spork.each_run { ::Padrino.reload! } - yield - end - - def entry_point - @entry_point ||= File.expand_path("config/boot.rb", Dir.pwd) - end - alias :boot_file :entry_point - - def boot_contents - @boot_contents ||= File.read(boot_file) - end - -end \ No newline at end of file diff --git a/lib/spork/app_framework/rails.rb b/lib/spork/app_framework/rails.rb deleted file mode 100644 index 351d6e7..0000000 --- a/lib/spork/app_framework/rails.rb +++ /dev/null @@ -1,82 +0,0 @@ -class Spork::AppFramework::Rails < Spork::AppFramework - - def preload(&block) - STDERR.puts "Preloading Rails environment" - STDERR.flush - ENV["RAILS_ENV"] ||= 'test' - preload_rails - yield - end - - def entry_point - @entry_point ||= File.expand_path("config/environment.rb", Dir.pwd) - end - - alias :environment_file :entry_point - - def boot_file - @boot_file ||= File.join(File.dirname(environment_file), 'boot') - end - - def application_file - @application_file ||= File.join(File.dirname(environment_file), 'application') - end - - def environment_contents - @environment_contents ||= File.read(environment_file) - end - - def vendor - @vendor ||= File.expand_path("vendor/rails", Dir.pwd) - end - - def deprecated_version - @version ||= ( - if /^[^#]*RAILS_GEM_VERSION\s*=\s*["']([!~<>=]*\s*[\d.]+)["']/.match(environment_contents) - $1 - else - nil - end - ) - end - - def preload_rails - if deprecated_version && (not /^3/.match(deprecated_version)) - puts "This version of spork only supports Rails 3.0. To use spork with rails 2.3.x, downgrade to spork 0.8.x." - exit 1 - end - require application_file - ::Rails.application - ::Rails::Engine.class_eval do - def eager_load! - # turn off eager_loading, all together - end - end - # Spork.trap_method(::AbstractController::Helpers::ClassMethods, :helper) - Spork.trap_method(::ActiveModel::Observing::ClassMethods, :instantiate_observers) - Spork.each_run { ActiveRecord::Base.establish_connection rescue nil } if Object.const_defined?(:ActiveRecord) - - - AbstractController::Helpers::ClassMethods.module_eval do - def helper(*args, &block) - ([args].flatten - [:all]).each do |arg| - next unless arg.is_a?(String) - filename = arg + "_helper" - unless ::ActiveSupport::Dependencies.search_for_file(filename) - # this error message must raise in the format such that LoadError#path returns the filename - raise LoadError.new("Missing helper file helpers/%s.rb" % filename) - end - end - - Spork.each_run(false) do - modules_for_helpers(args).each do |mod| - add_template_helper(mod) - end - - _helpers.module_eval(&block) if block_given? - end - end - end - end - -end diff --git a/lib/spork/app_framework/unknown.rb b/lib/spork/app_framework/unknown.rb index 6fc8003..7595e09 100644 --- a/lib/spork/app_framework/unknown.rb +++ b/lib/spork/app_framework/unknown.rb @@ -3,4 +3,8 @@ class Spork::AppFramework::Unknown < Spork::AppFramework def entry_point nil end -end \ No newline at end of file + + def self.present? + false + end +end diff --git a/lib/spork/ext/rails-reloader.rb b/lib/spork/ext/rails-reloader.rb deleted file mode 100644 index 8969c2c..0000000 --- a/lib/spork/ext/rails-reloader.rb +++ /dev/null @@ -1,14 +0,0 @@ -Spork.each_run do - ::ActiveSupport.const_defined?(:Dependencies) ? - ::ActiveSupport::Dependencies.mechanism = :load : - ::Dependencies.mechanism = :load - - require 'action_controller/dispatcher' - dispatcher = ::ActionController::Dispatcher.new($stdout) - - if ::ActionController::Dispatcher.respond_to?(:reload_application) - ::ActionController::Dispatcher.reload_application - else - dispatcher.reload_application - end -end if Spork.using_spork? \ No newline at end of file diff --git a/lib/spork/gem_helpers.rb b/lib/spork/gem_helpers.rb deleted file mode 100644 index 11767aa..0000000 --- a/lib/spork/gem_helpers.rb +++ /dev/null @@ -1,38 +0,0 @@ -module Spork::GemHelpers - extend self - - class GemPath - attr_reader :name, :version, :path, :version_numbers - include Comparable - def initialize(p) - @path = p - @name, @version = File.basename(p).scan(/^(.+?)-([^-]+)$/).flatten - @version_numbers = @version.split(/[^0-9]+/).map(&:to_i) - end - - def <=>(other) - raise "Not comparable gem paths ('#{name}' is not '#{other.name}')" unless name == other.name - @version_numbers <=> other.version_numbers - end - end - - def latest_load_paths - case - when defined?(Bundler) - $LOAD_PATH.map { |p| File.expand_path(p) }.uniq - when Gem.respond_to?(:path) - Dir["{#{Gem.path.join(',')}}" + "/gems/*"].inject({}) do |h,f| - gem_path = GemPath.new(f) - if h[gem_path.name] - h[gem_path.name] = gem_path if gem_path > h[gem_path.name] - else - h[gem_path.name] = gem_path - end - h - end.values.map { |gem_path| File.expand_path("lib", gem_path.path) }.sort.uniq - else - STDERR.puts "No mechanism available to scan for other gems implementing spork hooks. " - [] - end - end -end diff --git a/lib/spork/runner.rb b/lib/spork/runner.rb index 9d86c4c..8308009 100644 --- a/lib/spork/runner.rb +++ b/lib/spork/runner.rb @@ -56,7 +56,7 @@ def find_test_framework def run return false unless test_framework = find_test_framework ENV["DRB"] = 'true' - @error.puts "Using #{test_framework.short_name}" + @error.puts "Using #{test_framework.short_name}, #{test_framework.app_framework.short_name}" @error.flush case diff --git a/lib/spork/test/cucumber_helpers.rb b/lib/spork/test/cucumber_helpers.rb new file mode 100644 index 0000000..acfaffa --- /dev/null +++ b/lib/spork/test/cucumber_helpers.rb @@ -0,0 +1,5 @@ +SPORK_CUCUMBER_DIR = File.expand_path( "../../../features/", File.dirname(__FILE__)) +require("#{SPORK_CUCUMBER_DIR}/support/background_job.rb") +require("#{SPORK_CUCUMBER_DIR}/support/spork_world.rb") +require("#{SPORK_CUCUMBER_DIR}/support/bundler_helpers.rb") +Dir.glob("#{SPORK_CUCUMBER_DIR}/steps/**/*.rb").each { |f| load f } diff --git a/lib/spork/test/test_helpers.rb b/lib/spork/test/test_helpers.rb new file mode 100644 index 0000000..3eed188 --- /dev/null +++ b/lib/spork/test/test_helpers.rb @@ -0,0 +1,2 @@ +SPORK_SPEC_DIR = File.expand_path( "../../../spec/", File.dirname(__FILE__)) +Dir.glob("#{SPORK_SPEC_DIR}/support/*.rb").each { |f| require(f) } diff --git a/lib/spork/test_framework.rb b/lib/spork/test_framework.rb index 14f37be..b104d60 100644 --- a/lib/spork/test_framework.rb +++ b/lib/spork/test_framework.rb @@ -122,16 +122,16 @@ def preload stderr.puts "#{helper_file} has not been bootstrapped. Run spork --bootstrap to do so." stderr.flush - if framework.bootstrap_required? - stderr.puts "I can't do anything for you by default for the framework you're using: #{framework.short_name}.\nYou must bootstrap #{helper_file} to continue." + if app_framework.bootstrap_required? + stderr.puts "I can't do anything for you by default for the app framework you're using: #{app_framework.short_name}.\nYou must bootstrap #{helper_file} to continue." stderr.flush return false else - load(framework.entry_point) + load(app_framework.entry_point) end end - framework.preload do + app_framework.preload do if bootstrapped? stderr.puts "Loading Spork.prefork block..." stderr.flush @@ -147,21 +147,21 @@ def run_tests(argv, stderr, stdout) end def entry_point - bootstrapped? ? helper_file : framework.entry_point + bootstrapped? ? helper_file : app_framework.entry_point end def default_port self.class.default_port end + def app_framework + @app_framework ||= Spork::AppFramework.detect_framework + end + protected def self.inherited(subclass) @@supported_test_frameworks << subclass end - - def framework - @framework ||= Spork::AppFramework.detect_framework - end end Spork.detect_and_require('spork/test_framework/*.rb') diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 4361c74..de89af7 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -6,102 +6,21 @@ require 'fileutils' require 'rspec' +Dir.glob("#{File.dirname(__FILE__)}/support/*.rb").each { |f| require(f) } + RSpec.configure do |config| + include(TmpProjectHelpers) + config.before(:each) do - $test_stdout = StringIO.new - $test_stderr = StringIO.new + TestIOStreams.set_streams(StringIO.new, StringIO.new) + @current_dir = nil - end - - config.after(:each) do - FileUtils.rm_rf(SPEC_TMP_DIR) if File.directory?(SPEC_TMP_DIR) - end -end - -def create_file(filename, contents) - FileUtils.mkdir_p(SPEC_TMP_DIR) unless File.directory?(SPEC_TMP_DIR) - - in_current_dir do - FileUtils.mkdir_p(File.dirname(filename)) - File.open(filename, 'wb') { |f| f << contents } + clear_tmp_dir end end -def create_helper_file(test_framework = FakeFramework) - create_file(test_framework.helper_file, "# stub spec helper file") -end - -def in_current_dir(&block) - Dir.chdir(current_dir, &block) -end - -def current_dir - @current_dir ||= SPEC_TMP_DIR -end - -def change_current_dir(sub_path) - @current_dir = File.expand_path(sub_path, SPEC_TMP_DIR) -end def windows? ENV['OS'] == 'Windows_NT' end - -module RSpec - module Matchers - class IncludeAStringLike - def initialize(substring_or_regex) - case substring_or_regex - when String - @regex = Regexp.new(Regexp.escape(substring_or_regex)) - when Regexp - @regex = substring_or_regex - else - raise ArgumentError, "don't know what to do with the #{substring_or_regex.class} you provided" - end - end - - def matches?(list_of_strings) - @list_of_strings = list_of_strings - @list_of_strings.any? { |s| s =~ @regex } - end - def failure_message - "#{@list_of_strings.inspect} expected to include a string like #{@regex.inspect}" - end - def negative_failure_message - "#{@list_of_strings.inspect} expected to not include a string like #{@regex.inspect}, but did" - end - end - - def include_a_string_like(substring_or_regex) - IncludeAStringLike.new(substring_or_regex) - end - end -end - -module Spork::TestIOStreams - def self.included(klass) - klass.send(:extend, ::Spork::TestIOStreams::ClassMethods) - end - - def stderr - self.class.stderr - end - - def stdout - self.class.stdout - end - - module ClassMethods - def stderr - $test_stderr - end - - def stdout - $test_stdout - end - end -end - -Dir.glob(File.dirname(__FILE__) + "/support/*.rb").each { |f| require(f) } diff --git a/spec/spork/app_framework/rails_spec.rb b/spec/spork/app_framework/rails_spec.rb deleted file mode 100644 index 6258417..0000000 --- a/spec/spork/app_framework/rails_spec.rb +++ /dev/null @@ -1,22 +0,0 @@ -require 'spec_helper' - -describe Spork::AppFramework::Rails do - describe ".deprecated_version" do - it "detects the current version of rails" do - create_file("config/environment.rb", "RAILS_GEM_VERSION = '2.1.0'") - in_current_dir do - Spork::AppFramework::Rails.new.deprecated_version.should == "2.1.0" - end - - create_file("config/environment.rb", 'RAILS_GEM_VERSION = "2.1.0"') - in_current_dir do - Spork::AppFramework::Rails.new.deprecated_version.should == "2.1.0" - end - - create_file("config/environment.rb", 'RAILS_GEM_VERSION = "> 2.1.0"') - in_current_dir do - Spork::AppFramework::Rails.new.deprecated_version.should == "> 2.1.0" - end - end - end -end diff --git a/spec/spork/app_framework_spec.rb b/spec/spork/app_framework_spec.rb index 855eb23..e41bd83 100644 --- a/spec/spork/app_framework_spec.rb +++ b/spec/spork/app_framework_spec.rb @@ -2,13 +2,6 @@ describe Spork::AppFramework do describe ".detect_framework" do - it "detects when rails is installed and available" do - create_file("config/environment.rb", "RAILS_GEM_VERSION = '2.1.0'") - in_current_dir do - Spork::AppFramework.detect_framework.short_name.should == "Rails" - end - end - it "returns Unknown when no framework known detected" do Spork::AppFramework.detect_framework.short_name.should == "Unknown" end diff --git a/spec/spork/diagnoser_spec.rb b/spec/spork/diagnoser_spec.rb index f37a10a..7cdb3a3 100644 --- a/spec/spork/diagnoser_spec.rb +++ b/spec/spork/diagnoser_spec.rb @@ -1,6 +1,5 @@ require 'spec_helper' - describe Spork::Diagnoser do after(:each) do Spork::Diagnoser.remove_hook! diff --git a/spec/spork/test_framework_spec.rb b/spec/spork/test_framework_spec.rb index 896a780..2be53d1 100644 --- a/spec/spork/test_framework_spec.rb +++ b/spec/spork/test_framework_spec.rb @@ -66,9 +66,9 @@ create_helper_file @fake.bootstrap - $test_stderr.string.should include("Bootstrapping") - $test_stderr.string.should include("Edit") - $test_stderr.string.should include("favorite text editor") + TestIOStreams.stderr.string.should include("Bootstrapping") + TestIOStreams.stderr.string.should include("Edit") + TestIOStreams.stderr.string.should include("favorite text editor") File.read(@fake.helper_file).should include(File.read(FakeFramework::BOOTSTRAP_FILE)) end diff --git a/spec/support/fake_framework.rb b/spec/support/fake_framework.rb index 9203db2..1c7ac75 100644 --- a/spec/support/fake_framework.rb +++ b/spec/support/fake_framework.rb @@ -1,5 +1,7 @@ +require "#{File.dirname(__FILE__)}/test_io_streams.rb" + class FakeFramework < Spork::TestFramework - include Spork::TestIOStreams + include TestIOStreams attr_accessor :wait_time DEFAULT_PORT = 1000 diff --git a/spec/support/should_include_a_string_like.rb b/spec/support/should_include_a_string_like.rb new file mode 100644 index 0000000..8be45e2 --- /dev/null +++ b/spec/support/should_include_a_string_like.rb @@ -0,0 +1,31 @@ +module RSpec + module Matchers + class IncludeAStringLike + def initialize(substring_or_regex) + case substring_or_regex + when String + @regex = Regexp.new(Regexp.escape(substring_or_regex)) + when Regexp + @regex = substring_or_regex + else + raise ArgumentError, "don't know what to do with the #{substring_or_regex.class} you provided" + end + end + + def matches?(list_of_strings) + @list_of_strings = list_of_strings + @list_of_strings.any? { |s| s =~ @regex } + end + def failure_message + "#{@list_of_strings.inspect} expected to include a string like #{@regex.inspect}" + end + def negative_failure_message + "#{@list_of_strings.inspect} expected to not include a string like #{@regex.inspect}, but did" + end + end + + def include_a_string_like(substring_or_regex) + IncludeAStringLike.new(substring_or_regex) + end + end +end diff --git a/spec/support/test_io_streams.rb b/spec/support/test_io_streams.rb new file mode 100644 index 0000000..9e61478 --- /dev/null +++ b/spec/support/test_io_streams.rb @@ -0,0 +1,17 @@ +module TestIOStreams + def stderr + ::TestIOStreams.stderr + end + + def stdout + ::TestIOStreams.stdout + end + + class << self + attr_accessor :stderr, :stdout + + def set_streams(stderr, stdout) + self.stderr, self.stdout = stderr, stdout + end + end +end diff --git a/spec/support/tmp_project_helpers.rb b/spec/support/tmp_project_helpers.rb new file mode 100644 index 0000000..3b406dc --- /dev/null +++ b/spec/support/tmp_project_helpers.rb @@ -0,0 +1,30 @@ +module TmpProjectHelpers + def clear_tmp_dir + FileUtils.rm_rf(SPEC_TMP_DIR) if File.directory?(SPEC_TMP_DIR) + end + + def create_file(filename, contents) + FileUtils.mkdir_p(SPEC_TMP_DIR) unless File.directory?(SPEC_TMP_DIR) + + in_current_dir do + FileUtils.mkdir_p(File.dirname(filename)) + File.open(filename, 'wb') { |f| f << contents } + end + end + + def create_helper_file(test_framework = FakeFramework) + create_file(test_framework.helper_file, "# stub spec helper file") + end + + def in_current_dir(&block) + Dir.chdir(current_dir, &block) + end + + def current_dir + @current_dir ||= SPEC_TMP_DIR + end + + def change_current_dir(sub_path) + @current_dir = File.expand_path(sub_path, SPEC_TMP_DIR) + end +end diff --git a/spork.gemspec b/spork.gemspec index 32575a8..4c0602d 100644 --- a/spork.gemspec +++ b/spork.gemspec @@ -13,8 +13,8 @@ Gem::Specification.new do |s| "MIT-LICENSE", "README.rdoc" ] - s.files = ["Gemfile", "README.rdoc", "MIT-LICENSE"] + Dir["lib/**/*"] + Dir["assets/**/*"] - s.homepage = %q{http://github.com/timcharper/spork} + s.files = ["Gemfile", "README.rdoc", "MIT-LICENSE"] + Dir["lib/**/*"] + Dir["spec/**/*"] + Dir["features/**/*"] + s.homepage = %q{http://github.com/sporkrb/spork} s.rdoc_options = ["--main", "README.rdoc"] s.require_paths = ["lib"] s.rubyforge_project = %q{spork}