[DRE-commits] [ruby-aruba] 14/74: Replace special variables in commandline string

Hideki Yamane henrich at moszumanska.debian.org
Sat Nov 28 01:16:29 UTC 2015


This is an automated email from the git hooks/post-receive script.

henrich pushed a commit to branch debian/sid
in repository ruby-aruba.

commit e86df438fc78b84822299709b287c14477c2850c
Author: Max Meyer <dev at fedux.org>
Date:   Tue Nov 24 10:10:47 2015 +0100

    Replace special variables in commandline string
---
 History.md                                  |  2 ++
 features/api/text/replace_variables.feature | 45 +++++++++++++++++++++++++++++
 lib/aruba/api/command.rb                    |  2 ++
 lib/aruba/api/text.rb                       |  9 ++++++
 4 files changed, 58 insertions(+)

diff --git a/History.md b/History.md
index 469ec67..0f22bba 100644
--- a/History.md
+++ b/History.md
@@ -439,6 +439,8 @@
 * Added a configurable amount of time after a command was started -
   startup_wait_time. Otherwise you get problems when a process takes to long to
   startup when you run in background and want to sent it a signal.
+* Replace `<variable>` in commandline, e.g. `<pid-last-command-started>`
+  [experimental]
 
 ## [v1.0.0](https://github.com/cucumber/aruba/compare/v0.11.0...v1.0.0)
 
diff --git a/features/api/text/replace_variables.feature b/features/api/text/replace_variables.feature
new file mode 100644
index 0000000..7e2ad19
--- /dev/null
+++ b/features/api/text/replace_variables.feature
@@ -0,0 +1,45 @@
+ at experimental
+Feature: Replace variables
+
+  There are use cases where you need access to some information from aruba in
+  your command line. The `#replace_variables`-method makes this information
+  available.
+
+  Please note, this feature is experimental for now. The implementation of this
+  feature and the name of variables may change without further notice.
+
+  Background:
+    Given I use a fixture named "cli-app"
+
+  Scenario: PID of last command started
+    Given an executable named "bin/cli" with:
+    """
+    #!/bin/bash
+    exit 0
+    """
+    And a file named "spec/replace_spec.rb" with:
+    """
+    require 'spec_helper'
+
+    RSpec.describe 'Run command', :type => :aruba do
+      before(:each) { run('cli') }
+      before(:each) { stop_all_commands }
+ 
+      it { expect(replace_variables('<pid-last-command-started>')).to eq last_command_started.pid.to_s }
+    end
+    """
+    When I run `rspec`
+    Then the specs should all pass
+
+  Scenario: No last command started
+    Given a file named "spec/replace_spec.rb" with:
+    """
+    require 'spec_helper'
+
+    RSpec.describe 'Run command', :type => :aruba do
+      it { expect(replace_variables('<pid-last-command-started>')).to eq '0' }
+    end
+    """
+    When I run `rspec`
+    Then the specs should all pass
+
diff --git a/lib/aruba/api/command.rb b/lib/aruba/api/command.rb
index 2d77032..3ff3cb1 100644
--- a/lib/aruba/api/command.rb
+++ b/lib/aruba/api/command.rb
@@ -136,6 +136,8 @@ module Aruba
         stop_signal ||= aruba.config.stop_signal
         startup_wait_time ||= aruba.config.startup_wait_time
 
+        cmd = replace_variables(cmd)
+
         @commands ||= []
         @commands << cmd
 
diff --git a/lib/aruba/api/text.rb b/lib/aruba/api/text.rb
index 5b9da04..86b78b7 100644
--- a/lib/aruba/api/text.rb
+++ b/lib/aruba/api/text.rb
@@ -36,6 +36,15 @@ module Aruba
 
         text.chomp
       end
+
+      # @experimental
+      #
+      # Replace variables in command string
+      def replace_variables(text)
+        text = text.gsub(/<pid-last-command-started>/, last_command_started.pid.to_s)
+
+        text
+      end
     end
   end
 end

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-ruby-extras/ruby-aruba.git



More information about the Pkg-ruby-extras-commits mailing list