diff --git a/lib/vegetable_glue.rb b/lib/vegetable_glue.rb index 188e28a..9f54929 100644 --- a/lib/vegetable_glue.rb +++ b/lib/vegetable_glue.rb @@ -15,8 +15,8 @@ module VegetableGlue Runner.new(options).shutdown end - def clean - Runner.new(options).clean + def clean(name = nil) + Runner.new(options).clean(name) end def env @@ -30,4 +30,3 @@ module VegetableGlue end end - diff --git a/lib/vegetable_glue/cucumber.rb b/lib/vegetable_glue/cucumber.rb index 30d8018..0f212f9 100644 --- a/lib/vegetable_glue/cucumber.rb +++ b/lib/vegetable_glue/cucumber.rb @@ -1,10 +1,10 @@ -Before do +Before do |scenario| if ENV['REGLUE'] VegetableGlue.shutdown ENV.delete('REGLUE') end - VegetableGlue.clean + VegetableGlue.clean(scenario.to_sexp[3]) end diff --git a/lib/vegetable_glue/routes.rb b/lib/vegetable_glue/routes.rb index 0313b2d..67a750b 100644 --- a/lib/vegetable_glue/routes.rb +++ b/lib/vegetable_glue/routes.rb @@ -12,6 +12,10 @@ class ActionDispatch::Routing::Mapper DatabaseCleaner.clean_with :truncation + if scenario_name = URI.decode_www_form(env['QUERY_STRING']).first + Rails.logger.info "Cleaning database for #{scenario_name.last}" + end + [ 200, {}, [ VegetableGlue::CLEAN ] ] } end diff --git a/lib/vegetable_glue/runner.rb b/lib/vegetable_glue/runner.rb index 6ea8adc..9b7f13e 100644 --- a/lib/vegetable_glue/runner.rb +++ b/lib/vegetable_glue/runner.rb @@ -10,9 +10,11 @@ module VegetableGlue port = options[:url].port result = nil + was_running = false begin result = get_acceptance + was_running = true rescue Errno::ECONNREFUSED => e $stdout.puts "Starting #{app_name}..." @@ -24,7 +26,7 @@ module VegetableGlue end if result == VegetableGlue::ACCEPTANCE - $stdout.puts "#{app_name} running on port #{port}" + $stdout.puts "#{app_name} running on port #{port}" if !was_running else raise StandardError.new("Is #{app_name} running? You should have included the routes with `acceptance_helper_routes`") end @@ -42,10 +44,13 @@ module VegetableGlue FileUtils.rm_f pid_path end - def clean + def clean(name = nil) ensure_running - result = Net::HTTP.get(options[:url].merge(URI("/#{VegetableGlue::CLEAN}"))) + uri = options[:url].merge(URI("/#{VegetableGlue::CLEAN}")) + uri.query = URI.encode_www_form(:scenario => name) if name + + result = Net::HTTP.get(uri) raise StandardError.new("#{app_name} database not cleaned") if result != VegetableGlue::CLEAN end