clean tests and make them pass in the order observed on nix systems

This commit is contained in:
did 2011-08-13 16:24:02 -07:00
parent 161878f57e
commit b23f2697e9
14 changed files with 164 additions and 87 deletions

View File

@ -1,9 +1,9 @@
GIT
remote: git://github.com/floehopper/mocha.git
revision: 0ce0adc9f104a0ae2ddca400696c8694e85f1b93
revision: f417066f7f1b7d66cf5c72f28380675bde0cc424
specs:
mocha (0.9.12)
metaid (~> 1.0)
metaclass (~> 0.0.1)
GEM
remote: http://rubygems.org/
@ -170,7 +170,7 @@ GEM
i18n (>= 0.4.0)
mime-types (~> 1.16)
treetop (~> 1.4.8)
metaid (1.0)
metaclass (0.0.1)
mime-types (1.16)
mimemagic (0.1.8)
mimetype-fu (0.1.2)

View File

@ -20,3 +20,52 @@ task :release => :gem do
end
task :default => [:spec, :cucumber]
# only for running the tests suite in the order observed in *nix systems
task :spec_nix do
files = %w(
lib/core_ext_spec.rb
lib/locomotive/routing/site_dispatcher_spec.rb
lib/locomotive/bushido_spec.rb
lib/locomotive/render_spec.rb
lib/locomotive/httparty/patches_spec.rb
lib/locomotive/httparty/webservice_spec.rb
lib/locomotive/configuration_spec.rb
lib/locomotive/liquid/tags/consume_spec.rb
lib/locomotive/liquid/tags/with_scope_spec.rb
lib/locomotive/liquid/tags/nav_spec.rb
lib/locomotive/liquid/tags/editable/content_spec.rb
lib/locomotive/liquid/tags/editable/short_text_spec.rb
lib/locomotive/liquid/tags/seo_spec.rb
lib/locomotive/liquid/tags/paginate_spec.rb
lib/locomotive/liquid/drops/content_spec.rb
lib/locomotive/liquid/drops/contents_spec.rb
lib/locomotive/liquid/drops/page_spec.rb
lib/locomotive/liquid/drops/site_spec.rb
lib/locomotive/liquid/filters/resize_spec.rb
lib/locomotive/liquid/filters/html_spec.rb
lib/locomotive/liquid/filters/date_spec.rb
lib/locomotive/liquid/filters/text_spec.rb
lib/locomotive/liquid/filters/misc_spec.rb
lib/locomotive/heroku_spec.rb
lib/locomotive/import_spec.rb
lib/locomotive/export_spec.rb
models/content_instance_spec.rb
models/editable_element_spec.rb
models/account_spec.rb
models/content_type_spec.rb
models/snippet_spec.rb
models/ability_spec.rb
models/membership_spec.rb
models/page_spec.rb
models/asset_spec.rb
models/theme_asset_spec.rb
models/site_spec.rb
cells/admin/main_menu_cell_spec.rb
cells/admin/global_actions_spec.rb
cells/admin/settings_menu_cell_spec.rb
requests/seo_trailing_slash_spec.rb
).collect { |f| File.join('spec', f) }.join(' ')
sh "bundle exec rspec #{files}"
end

View File

@ -45,6 +45,7 @@ class Admin::MenuCell < Cell::Base
block.call(MenuProxy.new(self))
end
# Note: this might cause "stack level too deep" if called twice for the same name
alias_method_chain :build_list, name.to_sym
end

View File

@ -1,21 +1,5 @@
require 'spec_helper'
module Resetter
@@original_global_actions_cell_klass = Admin::GlobalActionsCell
def self.original_global_actions_cell_klass
@@original_global_actions_cell_klass
end
def self.reset_global_actions_cell_klass
::Admin.send(:remove_const, 'GlobalActionsCell')
::Admin.const_set('GlobalActionsCell', self.original_global_actions_cell_klass.clone)
::Admin::GlobalActionsCell.any_instance.stubs(:sections).returns({ :main => 'settings', :sub => 'site' })
end
end
describe Admin::GlobalActionsCell do
render_views
@ -25,7 +9,7 @@ describe Admin::GlobalActionsCell do
describe 'show menu' do
before(:each) do
Resetter.reset_global_actions_cell_klass
CellsResetter.new_global_actions_cell_klass({ :main => 'settings', :sub => 'site' })
end
it 'has 3 links' do
@ -49,7 +33,7 @@ describe Admin::GlobalActionsCell do
describe 'add a new menu item' do
before(:each) do
Resetter.reset_global_actions_cell_klass
CellsResetter.new_global_actions_cell_klass({ :main => 'settings', :sub => 'site' })
Admin::GlobalActionsCell.update_for(:testing_add) { |m| m.add(:my_link, :label => 'My link', :url => 'http://www.locomotivecms.com') }
end
@ -66,7 +50,7 @@ describe Admin::GlobalActionsCell do
describe 'remove a new menu item' do
before(:each) do
Resetter.reset_global_actions_cell_klass
CellsResetter.new_global_actions_cell_klass({ :main => 'settings', :sub => 'site' })
Admin::GlobalActionsCell.update_for(:testing_remove) { |m| m.remove(:see) }
end
@ -83,7 +67,7 @@ describe Admin::GlobalActionsCell do
describe 'modify an existing menu item' do
before(:each) do
Resetter.reset_global_actions_cell_klass
CellsResetter.new_global_actions_cell_klass({ :main => 'settings', :sub => 'site' })
Admin::GlobalActionsCell.update_for(:testing_update) { |m| m.modify(:see, { :label => 'Modified !' }) }
end
@ -98,4 +82,8 @@ describe Admin::GlobalActionsCell do
end
after(:all) do
CellsResetter.clean!
end
end

View File

@ -1,21 +1,5 @@
require 'spec_helper'
module Resetter
@@original_main_menu_cell_klass = Admin::MainMenuCell
def self.original_main_menu_cell_klass
@@original_main_menu_cell_klass
end
def self.reset_main_menu_cell_klass
::Admin.send(:remove_const, 'MainMenuCell')
::Admin.const_set('MainMenuCell', self.original_main_menu_cell_klass.clone)
::Admin::MainMenuCell.any_instance.stubs(:sections).returns({ :main => 'settings', :sub => 'site' })
end
end
describe Admin::MainMenuCell do
render_views
@ -25,7 +9,7 @@ describe Admin::MainMenuCell do
describe 'show menu' do
before(:each) do
Resetter.reset_main_menu_cell_klass
CellsResetter.new_main_menu_cell_klass({ :main => 'settings', :sub => 'site' })
end
it 'has 2 items' do
@ -45,7 +29,7 @@ describe Admin::MainMenuCell do
describe 'add a new menu item' do
before(:each) do
Resetter.reset_main_menu_cell_klass
CellsResetter.new_main_menu_cell_klass({ :main => 'settings', :sub => 'site' })
Admin::MainMenuCell.update_for(:testing_add) { |m| m.add(:my_link, :label => 'Shop', :url => 'http://www.locomotivecms.com') }
end
@ -62,7 +46,7 @@ describe Admin::MainMenuCell do
describe 'remove a new menu item' do
before(:each) do
Resetter.reset_main_menu_cell_klass
CellsResetter.new_main_menu_cell_klass({ :main => 'settings', :sub => 'site' })
Admin::MainMenuCell.update_for(:testing_remove) { |m| m.remove(:settings) }
end
@ -79,7 +63,7 @@ describe Admin::MainMenuCell do
describe 'modify an existing menu item' do
before(:each) do
Resetter.reset_main_menu_cell_klass
CellsResetter.new_main_menu_cell_klass({ :main => 'settings', :sub => 'site' })
Admin::MainMenuCell.update_for(:testing_update) { |m| m.modify(:settings, { :label => 'Modified !' }) }
end
@ -94,4 +78,8 @@ describe Admin::MainMenuCell do
end
after(:all) do
CellsResetter.clean!
end
end

View File

@ -1,21 +1,5 @@
require 'spec_helper'
module Resetter
@@original_settings_menu_cell_klass = Admin::SettingsMenuCell
def self.original_settings_menu_cell_klass
@@original_settings_menu_cell_klass
end
def self.reset_settings_menu_cell_klass
::Admin.send(:remove_const, 'SettingsMenuCell')
::Admin.const_set('SettingsMenuCell', self.original_settings_menu_cell_klass.clone)
::Admin::SettingsMenuCell.any_instance.stubs(:sections).returns({ :main => 'settings', :sub => 'site' })
end
end
describe Admin::SettingsMenuCell do
render_views
@ -25,7 +9,7 @@ describe Admin::SettingsMenuCell do
describe 'show menu' do
before(:each) do
Resetter.reset_settings_menu_cell_klass
CellsResetter.new_settings_menu_cell_klass({ :main => 'settings', :sub => 'site' })
end
it 'has 3 items' do
@ -49,7 +33,7 @@ describe Admin::SettingsMenuCell do
describe 'add a new menu item' do
before(:each) do
Resetter.reset_settings_menu_cell_klass
CellsResetter.new_settings_menu_cell_klass({ :main => 'settings', :sub => 'site' })
Admin::SettingsMenuCell.update_for(:testing_add) { |m| m.add(:my_link, :label => 'My link', :url => 'http://www.locomotivecms.com') }
end
@ -66,7 +50,7 @@ describe Admin::SettingsMenuCell do
describe 'remove a new menu item' do
before(:each) do
Resetter.reset_settings_menu_cell_klass
CellsResetter.new_settings_menu_cell_klass({ :main => 'settings', :sub => 'site' })
Admin::SettingsMenuCell.update_for(:testing_remove) { |m| m.remove(:theme_assets) }
end
@ -83,7 +67,7 @@ describe Admin::SettingsMenuCell do
describe 'modify an existing menu item' do
before(:each) do
Resetter.reset_settings_menu_cell_klass
CellsResetter.new_settings_menu_cell_klass({ :main => 'settings', :sub => 'site' })
Admin::SettingsMenuCell.update_for(:testing_update) { |m| m.modify(:theme_assets, { :label => 'Modified !' }) }
end
@ -98,4 +82,8 @@ describe Admin::SettingsMenuCell do
end
after(:all) do
CellsResetter.clean!
end
end

View File

@ -23,13 +23,17 @@ Factory.define "existing site", :parent => "site" do |s|
s.subdomain "models"
s.after_build do |site_with_models|
site_with_models.content_types.build(
:slug => 'projects',
:name => 'Existing name',
:slug => 'projects',
:name => 'Existing name',
:description => 'Existing description',
:order_by => 'created_at')
end
end
Factory.define "valid site", :parent => "site" do |s|
# s.after_build { |valid_site| valid_site.stubs(:valid?).returns(true) }
end
# Accounts ##
Factory.define :account do |a|

View File

@ -83,7 +83,7 @@ describe 'Bushido support' do
before(:each) do
configure_locomotive_with_bushido
(@site = Factory.build(:site)).stubs(:valid?).returns(true)
@site = Factory.build('valid site')
end
it 'calls add_bushido_domains after saving a site' do
@ -183,7 +183,6 @@ describe 'Bushido support' do
end
after(:all) do
ENV['APP_TLD'] = nil
Locomotive.configure_for_test(true)
end

View File

@ -2,10 +2,6 @@ require 'spec_helper'
describe 'Heroku support' do
before(:all) do
Site.destroy_all
end
before(:each) do
::Heroku::Client.any_instance.stubs(:post).returns(true)
::Heroku::Client.any_instance.stubs(:delete).returns(true)
@ -99,7 +95,9 @@ describe 'Heroku support' do
before(:each) do
configure_locomotive_with_heroku
(@site = Factory.build(:site)).stubs(:valid?).returns(true)
# (@site = Factory.stub(:site)).stubs(:valid?).returns(true)
@site = Factory.build('valid site')
# (@site = Site.new(:name => 'foobar', :subdomain => 'acme')).stubs(:valid?).returns(true)
end
it 'calls add_heroku_domains after saving a site' do
@ -178,7 +176,6 @@ describe 'Heroku support' do
end
after(:all) do
ENV['HEROKU_SLUG'] = ENV['APP_NAME'] = ENV['HEROKU_LOGIN'] = ENV['HEROKU_PASSWORD'] = nil
Locomotive.configure_for_test(true)
end

View File

@ -2,6 +2,11 @@ require 'spec_helper'
describe Locomotive::Import::Job do
# before(:all) do
# # Site.destroy_all
# # Locomotive.configure_for_test(true)
# end
context 'when successful' do
before(:all) do
@ -24,7 +29,7 @@ describe Locomotive::Import::Job do
content_type = @site.content_types.where(:slug => 'projects').first
content_type.content_custom_fields.size.should == 9
end
it 'correctly imports content type names' do
content_type = @site.content_types.where(:slug => 'projects').first
content_type.name.should == 'My projects'
@ -73,7 +78,7 @@ describe Locomotive::Import::Job do
page = @site.pages.where(:title => 'Contact').first
page.find_editable_element('content', 'office').source_filename.should == 'office.jpg'
end
it 'sets the empty editable file for a page from the site config file' do
page = @site.pages.where(:title => 'Contact').first
page.find_editable_element('content', 'office2').source_filename.should be_nil
@ -100,7 +105,7 @@ describe Locomotive::Import::Job do
end
end
context 'with an existing site' do
before(:all) do
@site = Factory("existing site")
@ -110,25 +115,24 @@ describe Locomotive::Import::Job do
job.success nil
end
context 'updates to content_type attributes' do
before(:all) do
@projects = content_type = @site.content_types.where(:slug => 'projects').first
end
it 'includes new name' do
@projects.name.should == 'My projects'
end
it 'includes new description' do
@projects.description.should == 'My portfolio'
end
it 'includes new order by' do
@projects.order_by.should == '_position_in_list'
end
end
end
end

View File

@ -70,7 +70,7 @@ describe Locomotive::Routing::SiteDispatcher do
before :each do
@controller.expects(:current_site).returns(true)
end
it 'returns true' do
@controller.send(:require_site).should be_true
end
@ -87,7 +87,7 @@ describe Locomotive::Routing::SiteDispatcher do
@controller.stubs(:admin_installation_url).returns('/admin/install/url/')
@controller.stubs(:redirect_to).with('/admin/install/url/')
end
it 'returns false' do
@controller.send(:require_site).should be_false
end
@ -98,7 +98,7 @@ describe Locomotive::Routing::SiteDispatcher do
end
end
context 'when there are no sites' do
before :each do
@ -110,7 +110,7 @@ describe Locomotive::Routing::SiteDispatcher do
@controller.stubs(:admin_installation_url).returns('/admin/install/url/')
@controller.stubs(:redirect_to).with('/admin/install/url/')
end
it 'returns false' do
@controller.send(:require_site).should be_false
end
@ -131,7 +131,7 @@ describe Locomotive::Routing::SiteDispatcher do
@controller.instance_variable_set('@_response', ActionDispatch::Response.new)
@controller.expects(:current_site).returns(false)
end
it 'returns false' do
@controller.send(:require_site).should be_false
end
@ -244,4 +244,8 @@ describe Locomotive::Routing::SiteDispatcher do
end
# after(:all) do
# Locomotive.configure_for_test(true)
# end
end

View File

@ -1,3 +1,26 @@
# figure out where we are being loaded from
if $LOADED_FEATURES.grep(/spec\/spec_helper\.rb/).any?
begin
raise "foo"
rescue => e
puts <<-MSG
===================================================
It looks like spec_helper.rb has been loaded
multiple times. Normalize the require to:
require "spec/spec_helper"
Things like File.join and File.expand_path will
cause it to be loaded multiple times.
Loaded this time from:
#{e.backtrace.join("\n ")}
===================================================
MSG
end
end
# This file is copied to spec/ when you run 'rails generate rspec:install'
ENV["RAILS_ENV"] ||= 'test'
require File.expand_path('../../config/environment', __FILE__)
@ -49,4 +72,10 @@ RSpec.configure do |config|
DatabaseCleaner.clean
end
end
config.before(:all) do
if self.described_class == Locomotive::Import::Job
DatabaseCleaner.clean
end
end
end

View File

@ -1,3 +1,27 @@
require 'rspec-cells'
require 'cell/test_case'
require 'rspec/rails/example/cell_example_group'
require 'rspec/rails/example/cell_example_group'
module CellsResetter
def self.method_missing(meth, *args)
if meth =~ /^new_(.*)_klass/
name = $1
klass_name = name.camelize
::Admin.send(:remove_const, klass_name)
load "#{name}.rb"
"::Admin::#{klass_name}".constantize.any_instance.stubs(:sections).returns(args.first)
end
end
def self.clean!
[:menu_cell, :main_menu_cell, :global_actions_cell, :settings_menu_cell].each do |name|
::Admin.send(:remove_const, "#{name.to_s.camelize}")
load "#{name}.rb"
end
end
end

View File

@ -25,6 +25,8 @@ def Locomotive.configure_for_test(force = false)
config.enable_logs = true
if force
ENV['APP_TLD'] = ENV['HEROKU_SLUG'] = ENV['APP_NAME'] = ENV['HEROKU_LOGIN'] = ENV['HEROKU_PASSWORD'] = nil
Locomotive.define_subdomain_and_domains_options
Object.send(:remove_const, 'Site') if Object.const_defined?('Site')