diff --git a/features/command_line.feature b/features/command_line.feature index 931f8978..4c55ef91 100644 --- a/features/command_line.feature +++ b/features/command_line.feature @@ -144,3 +144,13 @@ Feature: Command Line And a sass file sass/print.sass is reported unchanged And a sass file sass/reset.sass is reported unchanged And a sass file sass/utilities.sass is reported unchanged + + Scenario: Watching a project for changes + Given I am using the existing project in test/fixtures/stylesheets/compass + When I run: compass compile + And I run in a separate process: compass watch + And I wait 1 second + And I touch sass/layout.sass + And I wait 2 seconds + And I shutdown the other process + And a css file tmp/layout.css is reported identical diff --git a/features/env.rb b/features/env.rb new file mode 100644 index 00000000..70f553de --- /dev/null +++ b/features/env.rb @@ -0,0 +1,35 @@ +require 'cucumber/ast/step_invocation' + +module Cucumber + module Ast + class StepInvocation #:nodoc: + def invoke(step_mother, options) + find_step_match!(step_mother) + unless @skip_invoke || options[:dry_run] || @exception || @step_collection.exception + @skip_invoke = true + begin + @step_match.invoke(@multiline_arg) + step_mother.after_step + status!(:passed) + rescue Pending => e + failed(options, e, false) + status!(:pending) + rescue Undefined => e + failed(options, e, false) + status!(:undefined) + rescue Cucumber::Ast::Table::Different => e + @different_table = e.table + failed(options, e, false) + status!(:failed) + rescue SystemExit => e + raise + rescue Exception => e + failed(options, e, false) + status!(:failed) + end + end + end + end + end +end + diff --git a/features/step_definitions/command_line_steps.rb b/features/step_definitions/command_line_steps.rb index 65e522ec..c319e510 100644 --- a/features/step_definitions/command_line_steps.rb +++ b/features/step_definitions/command_line_steps.rb @@ -42,6 +42,35 @@ When /^I run: compass ([^\s]+) ?(.+)?$/ do |command, args| compass command, *(args || '').split end +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 + exit # This doesn't exit + 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 + exit + 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 + When /^I touch ([^\s]+)$/ do |filename| FileUtils.touch filename end diff --git a/lib/compass/commands/watch_project.rb b/lib/compass/commands/watch_project.rb index 9841b3a9..0e5e90cd 100644 --- a/lib/compass/commands/watch_project.rb +++ b/lib/compass/commands/watch_project.rb @@ -7,6 +7,8 @@ module Compass module Commands class WatchProject < UpdateProject + register :watch + attr_accessor :last_update_time, :last_sass_files def perform @@ -66,4 +68,4 @@ module Compass end end -end \ No newline at end of file +end