2009-10-16 07:57:34 +00:00
|
|
|
$:.unshift(File.expand_path(File.join(File.dirname(__FILE__), '../../test')))
|
|
|
|
|
|
|
|
require 'test_helper'
|
|
|
|
|
|
|
|
require 'compass/exec'
|
|
|
|
|
|
|
|
include Compass::CommandLineHelper
|
|
|
|
include Compass::IoHelper
|
2009-10-26 03:15:31 +00:00
|
|
|
include Compass::RailsHelper
|
2009-10-16 07:57:34 +00:00
|
|
|
|
|
|
|
Before do
|
2009-10-26 03:15:31 +00:00
|
|
|
Compass.reset_configuration!
|
2009-10-16 07:57:34 +00:00
|
|
|
@cleanup_directories = []
|
2009-10-24 22:21:49 +00:00
|
|
|
@original_working_directory = Dir.pwd
|
2009-10-16 07:57:34 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
After do
|
2009-10-24 22:21:49 +00:00
|
|
|
Dir.chdir @original_working_directory
|
2009-10-16 07:57:34 +00:00
|
|
|
@cleanup_directories.each do |dir|
|
|
|
|
FileUtils.rm_rf dir
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2009-10-24 22:21:49 +00:00
|
|
|
# Given Preconditions
|
|
|
|
Given %r{^I am using the existing project in ([^\s]+)$} do |project|
|
|
|
|
tmp_project = "tmp_#{File.basename(project)}"
|
|
|
|
@cleanup_directories << tmp_project
|
|
|
|
FileUtils.cp_r project, tmp_project
|
|
|
|
Dir.chdir tmp_project
|
|
|
|
end
|
|
|
|
|
|
|
|
Given %r{^I am in the parent directory$} do
|
|
|
|
Dir.chdir ".."
|
|
|
|
end
|
|
|
|
|
2010-08-28 19:50:48 +00:00
|
|
|
Given %r{^I'm in a newly created rails project: (.+)$} do |project_name|
|
2009-10-26 03:15:31 +00:00
|
|
|
@cleanup_directories << project_name
|
2009-10-30 15:13:25 +00:00
|
|
|
begin
|
|
|
|
generate_rails_app project_name
|
|
|
|
Dir.chdir project_name
|
|
|
|
rescue LoadError
|
|
|
|
pending "Missing Ruby-on-rails gems: sudo gem install rails"
|
|
|
|
end
|
2009-10-26 03:15:31 +00:00
|
|
|
end
|
|
|
|
|
2009-11-17 21:47:29 +00:00
|
|
|
Given /^I should clean up the directory: (\w+)$/ do |directory|
|
|
|
|
@cleanup_directories << directory
|
|
|
|
end
|
|
|
|
|
2009-10-24 22:21:49 +00:00
|
|
|
# When Actions are performed
|
|
|
|
When /^I create a project using: compass create ([^\s]+) ?(.+)?$/ do |dir, args|
|
2009-10-16 07:57:34 +00:00
|
|
|
@cleanup_directories << dir
|
|
|
|
compass 'create', dir, *(args || '').split
|
|
|
|
end
|
|
|
|
|
2009-10-26 03:15:31 +00:00
|
|
|
When /^I initialize a project using: compass init ?(.+)?$/ do |args|
|
|
|
|
compass 'init', *(args || '').split
|
|
|
|
end
|
|
|
|
|
2009-10-24 22:21:49 +00:00
|
|
|
When /^I run: compass ([^\s]+) ?(.+)?$/ do |command, args|
|
|
|
|
compass command, *(args || '').split
|
|
|
|
end
|
2009-10-16 07:57:34 +00:00
|
|
|
|
2009-10-25 07:45:34 +00:00
|
|
|
When /^I run in a separate process: compass ([^\s]+) ?(.+)?$/ do |command, args|
|
|
|
|
unless @other_process = fork
|
|
|
|
@last_result = ''
|
|
|
|
@last_error = ''
|
|
|
|
Signal.trap("HUP") do
|
|
|
|
open('/tmp/last_result.compass_test.txt', 'w') do |file|
|
|
|
|
file.puts $stdout.string
|
|
|
|
end
|
|
|
|
open('/tmp/last_error.compass_test.txt', 'w') do |file|
|
|
|
|
file.puts @stderr.string
|
|
|
|
end
|
2009-10-26 03:13:28 +00:00
|
|
|
exit!
|
2009-10-25 07:45:34 +00:00
|
|
|
end
|
|
|
|
# this command will run forever
|
|
|
|
# we kill it with a HUP signal from the parent process.
|
|
|
|
args = (args || '').split
|
|
|
|
args << { :wait => 5 }
|
|
|
|
compass command, *args
|
2009-10-26 03:13:28 +00:00
|
|
|
exit!
|
2009-10-25 07:45:34 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
When /^I shutdown the other process$/ do
|
|
|
|
Process.kill("HUP", @other_process)
|
|
|
|
Process.wait
|
|
|
|
@last_result = File.read('/tmp/last_result.compass_test.txt')
|
|
|
|
@last_error = File.read('/tmp/last_error.compass_test.txt')
|
|
|
|
end
|
|
|
|
|
2009-10-24 22:21:49 +00:00
|
|
|
When /^I touch ([^\s]+)$/ do |filename|
|
|
|
|
FileUtils.touch filename
|
|
|
|
end
|
|
|
|
|
|
|
|
When /^I wait ([\d.]+) seconds?$/ do |count|
|
|
|
|
sleep count.to_f
|
|
|
|
end
|
|
|
|
|
2009-10-25 00:53:02 +00:00
|
|
|
When /^I add some sass to ([^\s]+)$/ do |filename|
|
|
|
|
open(filename, "w+") do |file|
|
|
|
|
file.puts ".added .some .arbitrary"
|
|
|
|
file.puts " sass: code"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2009-10-24 22:21:49 +00:00
|
|
|
# Then postconditions
|
|
|
|
Then /^a directory ([^ ]+) is (not )?created$/ do |directory, negated|
|
2009-10-17 00:36:29 +00:00
|
|
|
File.directory?(directory).should == !negated
|
2009-10-16 07:57:34 +00:00
|
|
|
end
|
|
|
|
|
2009-10-26 03:15:31 +00:00
|
|
|
Then /an? \w+ file ([^ ]+) is (not )?created/ do |filename, negated|
|
|
|
|
File.exists?(filename).should == !negated
|
2009-10-16 07:57:34 +00:00
|
|
|
end
|
|
|
|
|
2009-10-17 00:36:29 +00:00
|
|
|
Then /an? \w+ file ([^ ]+) is reported created/ do |filename|
|
|
|
|
@last_result.should =~ /create #{Regexp.escape(filename)}/
|
|
|
|
end
|
|
|
|
|
|
|
|
Then /a \w+ file ([^ ]+) is (?:reported )?compiled/ do |filename|
|
2009-10-16 07:57:34 +00:00
|
|
|
@last_result.should =~ /compile #{Regexp.escape(filename)}/
|
|
|
|
end
|
|
|
|
|
2009-10-24 22:21:49 +00:00
|
|
|
Then /a \w+ file ([^ ]+) is reported unchanged/ do |filename|
|
|
|
|
@last_result.should =~ /unchanged #{Regexp.escape(filename)}/
|
|
|
|
end
|
|
|
|
|
|
|
|
Then /a \w+ file ([^ ]+) is reported identical/ do |filename|
|
|
|
|
@last_result.should =~ /identical #{Regexp.escape(filename)}/
|
|
|
|
end
|
|
|
|
|
2009-10-25 00:53:02 +00:00
|
|
|
Then /a \w+ file ([^ ]+) is reported overwritten/ do |filename|
|
|
|
|
@last_result.should =~ /overwrite #{Regexp.escape(filename)}/
|
|
|
|
end
|
|
|
|
|
2009-12-16 16:42:51 +00:00
|
|
|
Then /a \w+ file ([^ ]+) is not mentioned/ do |filename|
|
|
|
|
@last_result.should_not =~ /#{Regexp.escape(filename)}/
|
|
|
|
end
|
|
|
|
|
2009-10-16 07:57:34 +00:00
|
|
|
Then /I am told how to link to ([^ ]+) for media "([^"]+)"/ do |stylesheet, media|
|
|
|
|
@last_result.should =~ %r{<link href="#{stylesheet}" media="#{media}" rel="stylesheet" type="text/css" />}
|
|
|
|
end
|
|
|
|
|
2009-10-17 00:36:29 +00:00
|
|
|
Then /I am told how to conditionally link "([^"]+)" to ([^ ]+) for media "([^"]+)"/ do |condition, stylesheet, media|
|
2009-10-16 07:57:34 +00:00
|
|
|
@last_result.should =~ %r{<!--\[if #{condition}\]>\s+<link href="#{stylesheet}" media="#{media}" rel="stylesheet" type="text/css" />\s+<!\[endif\]-->}mi
|
|
|
|
end
|
2009-10-22 16:46:46 +00:00
|
|
|
|
|
|
|
Then /^an error message is printed out: (.+)$/ do |error_message|
|
|
|
|
@last_error.should =~ Regexp.new(Regexp.escape(error_message))
|
|
|
|
end
|
|
|
|
|
|
|
|
Then /^the command exits with a non\-zero error code$/ do
|
|
|
|
@last_exit_code.should_not == 0
|
|
|
|
end
|
|
|
|
|
2010-10-26 00:52:13 +00:00
|
|
|
Then /^the command exits normally$/ do
|
|
|
|
@last_exit_code.should == 0
|
|
|
|
end
|
2009-10-22 16:46:46 +00:00
|
|
|
|
|
|
|
Then /^I am congratulated$/ do
|
2009-10-24 22:21:08 +00:00
|
|
|
@last_result.should =~ /Congratulations!/
|
2009-10-22 16:46:46 +00:00
|
|
|
end
|
|
|
|
|
2009-10-24 22:21:08 +00:00
|
|
|
Then /^I am told that I can place stylesheets in the ([^\s]+) subdirectory$/ do |subdir|
|
|
|
|
@last_result.should =~ /You may now add sass stylesheets to the #{subdir} subdirectory of your project./
|
2009-10-22 16:46:46 +00:00
|
|
|
end
|
|
|
|
|
2009-10-24 22:21:08 +00:00
|
|
|
Then /^I am told how to compile my sass stylesheets$/ do
|
|
|
|
@last_result.should =~ /You must compile your sass stylesheets into CSS when they change.\nThis can be done in one of the following ways:/
|
2009-10-22 16:46:46 +00:00
|
|
|
end
|
|
|
|
|
2009-11-15 20:28:03 +00:00
|
|
|
Then /^I should be shown a list of "([^"]+)" commands$/ do |kind|
|
|
|
|
@last_result.should =~ /^#{kind.capitalize} Commands:$/
|
|
|
|
@last_command_list = []
|
|
|
|
found = false
|
|
|
|
indent = nil
|
|
|
|
@last_result.split("\n").each do |line|
|
|
|
|
if line =~ /^#{kind.capitalize} Commands:$/
|
|
|
|
found = true
|
|
|
|
elsif found && line =~ /^\s+/
|
|
|
|
@last_command_list << line
|
|
|
|
elsif found && line =~ /^$|^\w/
|
|
|
|
break
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2009-10-25 00:46:59 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
Then /^the list of commands should describe the ([^ ]+) command$/ do |command|
|
|
|
|
@last_result.should =~ /^\s+\* #{command}\s+- [A-Z].+$/
|
2009-10-24 22:21:49 +00:00
|
|
|
end
|
|
|
|
|
2009-10-27 01:52:27 +00:00
|
|
|
Then /^the following configuration properties are set in ([^ ]+):$/ do |config_file, table|
|
|
|
|
|
|
|
|
config = Compass::Configuration::Data.new_from_file(config_file)
|
|
|
|
table.hashes.each do |hash|
|
|
|
|
config.send(hash['property']).should == hash['value']
|
|
|
|
end
|
2009-10-26 16:24:38 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
Then /^my css is validated$/ do
|
2009-10-30 15:13:25 +00:00
|
|
|
if @last_error =~ /The Compass CSS Validator could not be loaded/
|
|
|
|
pending "Missing Dependency: sudo gem install chriseppstein-compass-validator"
|
|
|
|
else
|
|
|
|
@last_result.should =~ /Compass CSS Validator/
|
|
|
|
end
|
2009-10-26 16:24:38 +00:00
|
|
|
end
|
|
|
|
|
2009-10-26 16:25:52 +00:00
|
|
|
Then /^I am informed that my css is valid.$/ do
|
|
|
|
@last_result.should =~ /Your CSS files are valid\./
|
2009-10-26 16:24:38 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
Then /^I am told statistics for each file:$/ do |table|
|
|
|
|
# table is a Cucumber::Ast::Table
|
2009-10-29 16:57:05 +00:00
|
|
|
table.raw.each do |row|
|
|
|
|
re = Regexp.new row.join(' *\| *')
|
|
|
|
@last_result.should =~ re
|
|
|
|
end
|
2009-10-26 16:24:38 +00:00
|
|
|
end
|
2009-10-29 16:57:05 +00:00
|
|
|
|
2009-11-15 20:28:03 +00:00
|
|
|
Then /^I should see the following "([^"]+)" commands:$/ do |kind, table|
|
2009-10-29 16:57:05 +00:00
|
|
|
|
2009-11-15 20:28:03 +00:00
|
|
|
|
|
|
|
Then %Q{I should be shown a list of "#{kind}" commands}
|
|
|
|
|
|
|
|
commands = @last_command_list.map{|c| c =~ /^\s+\* ([^ ]+)\s+- [A-Z].+$/; [$1]}
|
|
|
|
table.diff!(commands)
|
|
|
|
end
|
2009-12-30 18:38:41 +00:00
|
|
|
|
|
|
|
|
|
|
|
Then /^the image ([^ ]+) has a size of (\d+)x(\d+)$/ do |file, width, height|
|
|
|
|
# see http://snippets.dzone.com/posts/show/805
|
|
|
|
IO.read(file)[0x10..0x18].unpack('NN').should == [width.to_i, height.to_i]
|
|
|
|
end
|
|
|
|
|
2010-05-29 21:57:00 +00:00
|
|
|
Then /^I should see the following lines of output:$/ do |table|
|
|
|
|
table.diff!([['blueprint'],['compass']])
|
|
|
|
end
|
2010-10-26 00:52:13 +00:00
|
|
|
|
|
|
|
Then /^I should see the following output: (.+)$/ do |expected|
|
|
|
|
(@last_result.strip + @last_error.strip).should == expected.gsub(/\$PROJECT_PATH/,Dir.pwd).strip
|
|
|
|
end
|