diff --git a/.rspec b/.rspec index 174e25596c80eb09a5bf10cf31499ad4f619169e..7c9f24ab9cc09f9ec1dbf4463b71e682f86ffed5 100644 --- a/.rspec +++ b/.rspec @@ -3,3 +3,4 @@ --color --tag ~performance --order random +--drb \ No newline at end of file diff --git a/Gemfile b/Gemfile index a892b2daa5cfa7b148c976d69c34c43e7625020f..2f47e9fd0df5b9195ec2269816169fbd9525b1e7 100644 --- a/Gemfile +++ b/Gemfile @@ -149,6 +149,11 @@ group :test do gem 'webmock', :require => false gem 'sqlite3' gem 'mock_redis' + + gem 'spork', '~> 1.0rc' + gem 'guard-rspec' + gem 'guard-spork' + gem 'guard-cucumber' end group :development do diff --git a/Gemfile.lock b/Gemfile.lock index 266e538d709fa8d4fa538de82ec0e779e7de8b5d..1dc88a104bf5e97b8857b3751e112438c6692c53 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -193,6 +193,17 @@ GEM gem_plugin (0.2.3) gherkin (2.9.3) json (>= 1.4.6) + guard (1.0.1) + ffi (>= 0.5.0) + thor (~> 0.14.6) + guard-cucumber (0.7.5) + cucumber (>= 0.10) + guard (>= 0.8.3) + guard-rspec (0.7.0) + guard (>= 0.10.0) + guard-spork (0.5.2) + guard (>= 0.10.0) + spork (>= 0.8.4) haml (3.1.4) handlebars_assets (0.4.1) execjs (>= 1.2.9) @@ -405,6 +416,7 @@ GEM rack (~> 1.3, >= 1.3.6) rack-protection (~> 1.2) tilt (~> 1.3, >= 1.3.3) + spork (1.0.0rc2) sprockets (2.0.3) hike (~> 1.2) rack (~> 1.0) @@ -485,6 +497,9 @@ DEPENDENCIES foreigner (~> 1.1.0) foreman (= 0.34.1) fuubar (= 0.0.6) + guard-cucumber + guard-rspec + guard-spork haml handlebars_assets heroku @@ -538,6 +553,7 @@ DEPENDENCIES sass-rails (= 3.1.4) selenium-webdriver (~> 2.16.0) settingslogic! + spork (~> 1.0rc) sqlite3 thin (~> 1.3.1) timecop diff --git a/Guardfile b/Guardfile index b975861e5c18c7c177a15db35474f9037f0e33d4..51bb0d3f3a8b2af8395f0bfb92a0390468c97772 100644 --- a/Guardfile +++ b/Guardfile @@ -18,3 +18,21 @@ guard 'rspec', :version => 2, :all_on_start => false do # Capybara request specs watch(%r{^app/views/(.+)/.*\.(erb|haml)$}) { |m| "spec/requests/#{m[1]}_spec.rb" } end + +guard 'spork', :cucumber_env => { 'RAILS_ENV' => 'test' }, :rspec_env => { 'RAILS_ENV' => 'test' }, :all_on_start => false do + watch('config/application.rb') + watch('config/environment.rb') + watch(%r{^config/environments/.+\.rb$}) + watch(%r{^config/initializers/.+\.rb$}) + watch('Gemfile') + watch('Gemfile.lock') + watch('spec/spec_helper.rb') { :rspec } + watch('test/test_helper.rb') { :test_unit } + watch(%r{features/support/}) { :cucumber } +end + +guard 'cucumber' do + watch(%r{^features/.+\.feature$}) + watch(%r{^features/support/.+$}) { 'features' } + watch(%r{^features/step_definitions/(.+)_steps\.rb$}) { |m| Dir[File.join("**/#{m[1]}.feature")][0] || 'features' } +end diff --git a/features/support/env.rb b/features/support/env.rb index 57616187073d59362b1f57da6d383f5398d2d888..5d591929e3e455503caa033b0e187e34f4fdecda 100644 --- a/features/support/env.rb +++ b/features/support/env.rb @@ -1,93 +1,96 @@ -# IMPORTANT: This file is generated by cucumber-rails - edit at your own peril. -# It is recommended to regenerate this file in the future when you upgrade to a -# newer version of cucumber-rails. Consider adding your own code to a new file -# instead of editing this one. Cucumber will automatically load all features/**/*.rb -# files. - -ENV["RAILS_ENV"] ||= "test" -require 'cucumber/rails' - -require 'capybara/rails' -require 'capybara/cucumber' -require 'capybara/session' -#require 'cucumber/rails/capybara_javascript_emulation' # Lets you click links with onclick javascript handlers without using @culerity or @javascript -require 'cucumber/api_steps' - -# Ensure we know the appservers port -Capybara.server_port = 9887 - -# Capybara defaults to XPath selectors rather than Webrat's default of CSS3. In -# order to ease the transition to Capybara we set the default here. If you'd -# prefer to use XPath just remove this line and adjust any selectors in your -# steps to use the XPath syntax. -Capybara.default_selector = :css - -# We have a ridiculously high wait time to account for build machines of various beefiness. -# Capybara.default_wait_time = 30 - -# While there are a lot of failures, wait less, avoiding travis timeout -Capybara.default_wait_time = 3 - -# If you set this to false, any error raised from within your app will bubble -# up to your step definition and out to cucumber unless you catch it somewhere -# on the way. You can make Rails rescue errors and render error pages on a -# per-scenario basis by tagging a scenario or feature with the @allow-rescue tag. -# -# If you set this to true, Rails will rescue all errors and render error -# pages, more or less in the same way your application would behave in the -# default production environment. It's not recommended to do this for all -# of your scenarios, as this makes it hard to discover errors in your application. -ActionController::Base.allow_rescue = false - -require 'database_cleaner' -require 'database_cleaner/cucumber' -DatabaseCleaner.strategy = :truncation -DatabaseCleaner.orm = "active_record" -Cucumber::Rails::World.use_transactional_fixtures = false - -require File.join(File.dirname(__FILE__), "database_cleaner_patches") -require File.join(File.dirname(__FILE__), "integration_sessions_controller") -require File.join(File.dirname(__FILE__), "poor_mans_webmock") - -require File.join(File.dirname(__FILE__), "..", "..", "spec", "helper_methods") -require File.join(File.dirname(__FILE__), "..", "..", "spec", "support","user_methods") -include HelperMethods - -require 'webmock/cucumber' -WebMock.disable_net_connect!(:allow_localhost => true) - -Before do - @no_follow_diaspora_hq_setting = AppConfig[:no_follow_diasporahq] - AppConfig[:no_follow_diasporahq] = true - DatabaseCleaner.clean - Devise.mailer.deliveries = [] -end - -After do - AppConfig[:no_follow_diasporahq] = @no_follow_diaspora_hq_setting - if Capybara.current_session.driver.respond_to?(:browser) - Capybara.reset_sessions! - # Capybara.current_session.driver.browser.manage.delete_all_cookies +require 'rubygems' +require 'spork' +#uncomment the following line to use spork with the debugger +#require 'spork/ext/ruby-debug' + +Spork.prefork do + ENV["RAILS_ENV"] ||= "test" + require 'cucumber/rails' + + require 'capybara/rails' + require 'capybara/cucumber' + require 'capybara/session' + #require 'cucumber/rails/capybara_javascript_emulation' # Lets you click links with onclick javascript handlers without using @culerity or @javascript + require 'cucumber/api_steps' + + # Ensure we know the appservers port + Capybara.server_port = 9887 + + + # Capybara defaults to XPath selectors rather than Webrat's default of CSS3. In + # order to ease the transition to Capybara we set the default here. If you'd + # prefer to use XPath just remove this line and adjust any selectors in your + # steps to use the XPath syntax. + Capybara.default_selector = :css + + # We have a ridiculously high wait time to account for build machines of various beefiness. + # Capybara.default_wait_time = 30 + + # While there are a lot of failures, wait less, avoiding travis timeout + Capybara.default_wait_time = 3 + + # If you set this to false, any error raised from within your app will bubble + # up to your step definition and out to cucumber unless you catch it somewhere + # on the way. You can make Rails rescue errors and render error pages on a + # per-scenario basis by tagging a scenario or feature with the @allow-rescue tag. + # + # If you set this to true, Rails will rescue all errors and render error + # pages, more or less in the same way your application would behave in the + # default production environment. It's not recommended to do this for all + # of your scenarios, as this makes it hard to discover errors in your application. + ActionController::Base.allow_rescue = false + + require 'database_cleaner' + require 'database_cleaner/cucumber' + DatabaseCleaner.strategy = :truncation + DatabaseCleaner.orm = "active_record" + Cucumber::Rails::World.use_transactional_fixtures = false + + require File.join(File.dirname(__FILE__), "database_cleaner_patches") + require File.join(File.dirname(__FILE__), "integration_sessions_controller") + require File.join(File.dirname(__FILE__), "poor_mans_webmock") + + require File.join(File.dirname(__FILE__), "..", "..", "spec", "helper_methods") + require File.join(File.dirname(__FILE__), "..", "..", "spec", "support","user_methods") + include HelperMethods + + require 'webmock/cucumber' + WebMock.disable_net_connect!(:allow_localhost => true) + + silence_warnings do + SERVICES['facebook'] = {'app_id' => :fake, 'app_secret' => 'sdoigjosdfijg'} + AppConfig[:configured_services] << 'facebook' end -end -silence_warnings do - SERVICES['facebook'] = {'app_id' => :fake, 'app_secret' => 'sdoigjosdfijg'} - AppConfig[:configured_services] << 'facebook' -end + require File.join(File.dirname(__FILE__), "..", "..", "spec", "support", "fake_resque") -require File.join(File.dirname(__FILE__), "..", "..", "spec", "support", "fake_resque") -require File.join(File.dirname(__FILE__), 'run_resque_in_process') + require File.join(File.dirname(__FILE__), 'run_resque_in_process') +end +Spork.each_run do + Before do + @no_follow_diaspora_hq_setting = AppConfig[:no_follow_diasporahq] + AppConfig[:no_follow_diasporahq] = true + DatabaseCleaner.clean + Devise.mailer.deliveries = [] + end -Before('@localserver') do - TestServerFixture.start_if_needed - CapybaraSettings.instance.save - Capybara.current_driver = :selenium - Capybara.run_server = false -end + After do + AppConfig[:no_follow_diasporahq] = @no_follow_diaspora_hq_setting + if Capybara.current_session.driver.respond_to?(:browser) + Capybara.reset_sessions! + # Capybara.current_session.driver.browser.manage.delete_all_cookies + end + end -After('@localserver') do - CapybaraSettings.instance.restore -end + Before('@localserver') do + TestServerFixture.start_if_needed + CapybaraSettings.instance.save + Capybara.current_driver = :selenium + Capybara.run_server = false + end + After('@localserver') do + CapybaraSettings.instance.restore + end +end \ No newline at end of file diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index ee64844880eb5666acb5a321e5d3f88dd7d37a00..28529a8a92ceb9c00b1ef06598bb3a919b7fa9df 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -2,89 +2,102 @@ # licensed under the Affero General Public License version 3 or later. See # the COPYRIGHT file. -ENV["RAILS_ENV"] ||= 'test' -require File.join(File.dirname(__FILE__), '..', 'config', 'environment') unless defined?(Rails) -require 'helper_methods' -require 'spec-doc' -require 'rspec/rails' -require 'webmock/rspec' -require 'factory_girl' - -include HelperMethods - -# Force fixture rebuild -FileUtils.rm_f(File.join(Rails.root, 'tmp', 'fixture_builder.yml')) - -# Requires supporting files with custom matchers and macros, etc, -# in ./support/ and its subdirectories. -fixture_builder_file = "#{File.dirname(__FILE__)}/support/fixture_builder.rb" -support_files = Dir["#{File.dirname(__FILE__)}/support/**/*.rb"] - [fixture_builder_file] -support_files.each {|f| require f } -require fixture_builder_file - -RSpec.configure do |config| - config.include Devise::TestHelpers, :type => :controller - config.mock_with :rspec - - config.use_transactional_fixtures = true - - config.before(:each) do - I18n.locale = :en - stub_request(:post, "https://pubsubhubbub.appspot.com/") - disable_typhoeus - $process_queue = false - Postzord::Dispatcher::Public.any_instance.stub(:deliver_to_remote) - Postzord::Dispatcher::Private.any_instance.stub(:deliver_to_remote) +require 'rubygems' +require 'spork' +#uncomment the following line to use spork with the debugger +#require 'spork/ext/ruby-debug' + +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. + + ENV["RAILS_ENV"] ||= 'test' + require File.join(File.dirname(__FILE__), '..', 'config', 'environment') unless defined?(Rails) + require 'helper_methods' + require 'spec-doc' + require 'rspec/rails' + require 'webmock/rspec' + require 'factory_girl' + + include HelperMethods + + Dir["#{File.dirname(__FILE__)}/shared_behaviors/**/*.rb"].each do |f| + require f end - config.before(:each, :type => :controller) do - self.class.render_views - end + ProcessedImage.enable_processing = false + UnprocessedImage.enable_processing = false - config.after(:all) do - `rm -rf #{Rails.root}/tmp/uploads/*` + def set_up_friends + [local_luke, local_leia, remote_raphael] end -end - -Dir["#{File.dirname(__FILE__)}/shared_behaviors/**/*.rb"].each do |f| - require f -end - -ProcessedImage.enable_processing = false -UnprocessedImage.enable_processing = false - -AppConfig.load! -AppConfig.setup! + def alice + @alice ||= User.where(:username => 'alice').first + end -def set_up_friends - [local_luke, local_leia, remote_raphael] -end + def bob + @bob ||= User.where(:username => 'bob').first + end -def alice - @alice ||= User.where(:username => 'alice').first -end + def eve + @eve ||= User.where(:username => 'eve').first + end -def bob - @bob ||= User.where(:username => 'bob').first -end + def local_luke + @local_luke ||= User.where(:username => 'luke').first + end -def eve - @eve ||= User.where(:username => 'eve').first -end + def local_leia + @local_leia ||= User.where(:username => 'leia').first + end -def local_luke - @local_luke ||= User.where(:username => 'luke').first -end + def remote_raphael + @remote_raphael ||= Person.where(:diaspora_handle => 'raphael@remote.net').first + end -def local_leia - @local_leia ||= User.where(:username => 'leia').first -end + def photo_fixture_name + @photo_fixture_name = File.join(File.dirname(__FILE__), 'fixtures', 'button.png') + end -def remote_raphael - @remote_raphael ||= Person.where(:diaspora_handle => 'raphael@remote.net').first + # Force fixture rebuild + FileUtils.rm_f(File.join(Rails.root, 'tmp', 'fixture_builder.yml')) + + # Requires supporting files with custom matchers and macros, etc, + # in ./support/ and its subdirectories. + fixture_builder_file = "#{File.dirname(__FILE__)}/support/fixture_builder.rb" + support_files = Dir["#{File.dirname(__FILE__)}/support/**/*.rb"] - [fixture_builder_file] + support_files.each {|f| require f } + require fixture_builder_file + + RSpec.configure do |config| + config.include Devise::TestHelpers, :type => :controller + config.mock_with :rspec + + config.use_transactional_fixtures = true + + config.before(:each) do + I18n.locale = :en + stub_request(:post, "https://pubsubhubbub.appspot.com/") + disable_typhoeus + $process_queue = false + Postzord::Dispatcher::Public.any_instance.stub(:deliver_to_remote) + Postzord::Dispatcher::Private.any_instance.stub(:deliver_to_remote) + end + + config.before(:each, :type => :controller) do + self.class.render_views + end + + config.after(:all) do + `rm -rf #{Rails.root}/tmp/uploads/*` + end + end end -def photo_fixture_name - @photo_fixture_name = File.join(File.dirname(__FILE__), 'fixtures', 'button.png') +Spork.each_run do + # This code will be run each time you run your specs. + AppConfig.load! + AppConfig.setup! end