Skip to content

Commit

Permalink
Merge pull request #257 from dg-ratiodata/feature/use_current_working…
Browse files Browse the repository at this point in the history
…_directory_for_process

Cleanup "Process Management" #1
  • Loading branch information
maxmeyer committed Jun 26, 2015
2 parents ec69fde + cbf64c7 commit cbfcb1d
Show file tree
Hide file tree
Showing 25 changed files with 991 additions and 339 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -185,8 +185,8 @@ Then wire it all up in your `features/support/env.rb` file:
require 'aruba'
require 'aruba/in_process'

Aruba::InProcess.main_class = MyMain
Aruba.process = Aruba::InProcess
Aruba.process = Aruba::Processes::InProcess
Aruba.process.main_class = MyMain
```

That's it! Everything will now run inside the same ruby process, making your suite
Expand Down
11 changes: 5 additions & 6 deletions cucumber.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
<%
java_version = (RUBY_DESCRIPTION.match(/.*?on.*?(1\.[\d]\..*? )/))[1] if defined?(JRUBY_VERSION)
std_opts = "--color --tags ~@wip"
std_opts << " --tags [email protected]" if defined?(JRUBY_VERSION) && (java_version < '1.7.0')
wip_opts = "--color --tags @wip:3"
wip_opts = "--color --tags @wip:3,@wip-jruby-java-1.6:3" if defined?(JRUBY_VERSION) && (java_version < '1.7.0')
std_opts = "--color --exclude features/fixtures"
java_default_opts = "--tags [email protected]" if defined?(JRUBY_VERSION) && (java_version < '1.7.0')
java_wip_opts = "--tags @wip-jruby-java-1.6:3" if defined?(JRUBY_VERSION) && (java_version < '1.7.0')
%>
default: <%= std_opts %>
wip: --wip <%= wip_opts %>
default: <%= std_opts %> --tags ~@wip <%= java_default_opts %>
wip: <%= std_opts %> --wip --tags @wip:3 <%= java_wip_opts %>
15 changes: 15 additions & 0 deletions features/debug.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
Feature: Debug command execution

As a developer
I want to use some debugger in my code and therefor need system() to execute my program
In order to find a bug

@debug
Scenario: Run program with debug code
When I run `true`
Then the exit status should be 0

@debug
Scenario: Run failing program with debug code
When I run `false`
Then the exit status should be 1
3 changes: 3 additions & 0 deletions features/fixtures/spawn_process/stderr.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/usr/bin/env bash

echo $* >&2
10 changes: 5 additions & 5 deletions features/support/custom_main.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require 'aruba'
require 'aruba/spawn_process'
require 'aruba/in_process'
require 'aruba/processes/spawn_process'
require 'aruba/processes/in_process'
require 'shellwords'
require 'stringio'

Expand All @@ -19,10 +19,10 @@ def execute!
end

Before('@in-process') do
Aruba::InProcess.main_class = CustomMain
Aruba.process = Aruba::InProcess
Aruba.process = Aruba::Processes::InProcess
Aruba.process.main_class = CustomMain
end

After('~@in-process') do
Aruba.process = Aruba::SpawnProcess
Aruba.process = Aruba::Processes::SpawnProcess
end
4 changes: 2 additions & 2 deletions lib/aruba.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
require 'aruba/spawn_process'
require 'aruba/processes/spawn_process'

module Aruba
class << self
attr_accessor :process
end
self.process = Aruba::SpawnProcess
self.process = Aruba::Processes::SpawnProcess
end
161 changes: 161 additions & 0 deletions lib/aruba/announcer.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,161 @@
module Aruba
# Announcer
#
# @example Activate your you own channel in cucumber
#
# Before('@announce-my-channel') do
# announcer.activate :my_channel
# end
#
# @example Activate your you own channel in rspec > 3
#
# before do
# current_example = context.example
# announcer.activate :my_channel if current_example.metadata[:announce_my_channel]
# end
#
# Aruba.announcer.announce(:my_channel, 'my message')
#
class Announcer
# Dev null
class NullAnnouncer
def announce(*)
nil
end

def mode?(*)
true
end
end

# Announcer using Kernel.puts
class KernelPutsAnnouncer
def announce(message)
Kernel.puts message
end

def mode?(m)
:kernel_puts == m
end
end

# Announcer using Main#puts
class PutsAnnouncer
def announce(message)
Kernel.puts message
end

def mode?(m)
:puts == m
end
end

private

attr_reader :announcers, :default_announcer, :announcer, :channels, :format_strings

public

def initialize(_, options)
@announcers = []
@announcers << PutsAnnouncer.new
@announcers << KernelPutsAnnouncer.new
@announcers << NullAnnouncer.new

@default_announcer = @announcers.last
@announcer = @announcers.first
@channels = {}
@format_strings = {}

@options = options

after_init
end

# rubocop:disable Metrics/MethodLength
def after_init
format_string :directory, '$ cd %s'
format_string :command, '$ %s'
format_string :environment, '$ export %s=%s"'

# rubocop:disable Metrics/LineLength
if @options[:stdout]
warn('The use of "@announce_stdout-instance" variable and "options[:stdout] = true" for Announcer.new is deprecated. Please use "announcer.activate(:stdout)" instead.')
activate :stdout
end
if @options[:stderr]
warn('The use of "@announce_stderr-instance" variable and "options[:stderr] = true" for Announcer.new is deprecated. Please use "announcer.activate(:stderr)" instead.')
activate :stderr
end
if @options[:dir]
warn('The use of "@announce_dir-instance" variable and "options[:dir] = true" for Announcer.new is deprecated. Please use "announcer.activate(:directory)" instead.')
activate :directory
end
if @options[:cmd]
warn('The use of "@announce_cmd-instance" variable and "options[:cmd] = true" for Announcer.new is deprecated. Please use "announcer.activate(:command)" instead.')
activate :command
end
if @options[:env]
warn('The use of "@announce_env-instance" variable and "options[:env] = true" for Announcer.new is deprecated. Please use "announcer.activate(:environment)" instead.')
activate :enviroment
end
# rubocop:enable Metrics/LineLength
end
# rubocop:enable Metrics/MethodLength

def reset
@default_announcer = @announcers.last
@announcer = @announcers.first
end

def format_string(channel, string)
format_strings[channel] = string

self
end

def mode=(m)
@announcer = @announcers.find { |a| f.mode? m }

self
end

def activate(channel)
channels[channel] = true

self
end

def announce(channel, *args)
message = format(format_strings.fetch(channel, '%s'), *args)
announcer.announce(message) if @channels[channel]

default_announcer.announce message
end

def stdout(content)
warn('The announcer now has a new api to activate channels. Please use this one: announce(:stdout, message)')
announce :stdout, content
end

def stderr(content)
warn('The announcer now has a new api to activate channels. Please use this one: announce(:stderr, message)')
announce :stderr, content
end

def dir(dir)
warn('The announcer now has a new api to activate channels. Please use this one announce(:directory, message)')
announce :directory, dir
end

def cmd(cmd)
warn('The announcer now has a new api to activate channels. Please use this one announce(:command, message)')
announce :command, cmd
end

def env(key, value)
warn('The announcer now has a new api to activate channels. Please use this one: announce(:environment, key, value)')
announce :environment, key, value
end
end
end
Loading

0 comments on commit cbfcb1d

Please sign in to comment.