compass/test/rails_integration_test.rb

84 lines
2.7 KiB
Ruby
Raw Normal View History

require File.join(File.dirname(__FILE__),'test_helper')
require 'fileutils'
require 'compass'
require 'compass/exec'
require 'timeout'
class RailsIntegrationTest < Test::Unit::TestCase
include Compass::TestCaseHelper
include Compass::CommandLineHelper
Refactor of the internal datastructures used to access project configuration. Configuration is now a singly linked list of configuration objects that inherit values and defaults from the next configuration instance. All instances hold a reference to the top of the configuration chain. There is now a consistent API for reading configuration property values: <attr>: Reads the fully-resolved attribute after taking configuration inheritance and defaults into account. raw_<attr>: reads attribute from a configuration object without inheritance or defaults. default_for(<attr>): reads the default value for an attribute default_for_<attr>: specifies the default value for an attribute. <attr>_without_default: reads the inherited attribute without applying defaults. comment_for_<attr>: Specifies a comment that will be emitted above the property when serializing the configuration to a file. Additionally, method_missing and respond_to both work down the configuration chain, so any method that is added to a configuration instance, can be accessed from the top level. The distinction between default and explicitly set values allows compass to more correctly manage the serialization of attributes when creating configuration files for projects. The compass configuration can still be accessed via Compass.configuration, however, the configuration object is no longer a singleton. This means that you can build several configuration chains to track several projects at once. This should ease the use of compass in other frameworks and plugins that want to use compass internally.
2009-08-25 21:18:58 +00:00
include Compass::IoHelper
def setup
Refactor of the internal datastructures used to access project configuration. Configuration is now a singly linked list of configuration objects that inherit values and defaults from the next configuration instance. All instances hold a reference to the top of the configuration chain. There is now a consistent API for reading configuration property values: <attr>: Reads the fully-resolved attribute after taking configuration inheritance and defaults into account. raw_<attr>: reads attribute from a configuration object without inheritance or defaults. default_for(<attr>): reads the default value for an attribute default_for_<attr>: specifies the default value for an attribute. <attr>_without_default: reads the inherited attribute without applying defaults. comment_for_<attr>: Specifies a comment that will be emitted above the property when serializing the configuration to a file. Additionally, method_missing and respond_to both work down the configuration chain, so any method that is added to a configuration instance, can be accessed from the top level. The distinction between default and explicitly set values allows compass to more correctly manage the serialization of attributes when creating configuration files for projects. The compass configuration can still be accessed via Compass.configuration, however, the configuration object is no longer a singleton. This means that you can build several configuration chains to track several projects at once. This should ease the use of compass in other frameworks and plugins that want to use compass internally.
2009-08-25 21:18:58 +00:00
Compass.reset_configuration!
end
def test_rails_install
within_tmp_directory do
generate_rails_app_directories("compass_rails")
Dir.chdir "compass_rails" do
compass("--rails", '--trace', ".") do |responder|
responder.respond_to "Is this OK? (Y/n)", :with => "Y", :required => true
responder.respond_to "Emit compiled stylesheets to public/stylesheets/compiled/? (Y/n)", :with => "Y", :required => true
end
# puts ">>>#{@last_result}<<<"
assert_action_performed :create, "./app/stylesheets/screen.sass"
assert_action_performed :create, "./config/initializers/compass.rb"
end
end
rescue LoadError
puts "Skipping rails test. Couldn't Load rails"
end
def test_rails_install_with_no_dialog
within_tmp_directory do
generate_rails_app_directories("compass_rails")
Dir.chdir "compass_rails" do
compass(*%w(--rails --trace --sass-dir app/stylesheets --css-dir public/stylesheets/compiled .))
assert_action_performed :create, "./app/stylesheets/screen.sass"
assert_action_performed :create, "./config/initializers/compass.rb"
end
end
rescue LoadError
puts "Skipping rails test. Couldn't Load rails"
end
def generate_rails_app_directories(name)
Dir.mkdir name
Dir.mkdir File.join(name, "config")
Dir.mkdir File.join(name, "config", "initializers")
end
# Generate a rails application without polluting our current set of requires
# with the rails libraries. This will allow testing against multiple versions of rails
# by manipulating the load path.
def generate_rails_app(name)
if pid = fork
Process.wait(pid)
if $?.exitstatus == 2
raise LoadError, "Couldn't load rails"
elsif $?.exitstatus != 0
raise "Failed to generate rails application."
end
else
begin
require 'rails/version'
require 'rails_generator'
require 'rails_generator/scripts/generate'
Rails::Generator::Base.use_application_sources!
capture_output do
Rails::Generator::Base.logger = Rails::Generator::SimpleLogger.new $stdout
Rails::Generator::Scripts::Generate.new.run([name], :generator => 'app')
end
rescue LoadError
Kernel.exit(2)
rescue => e
$stderr.puts e
Kernel.exit!(1)
end
Kernel.exit!(0)
end
end
end