bahia 0.2.0 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/CHANGELOG.rdoc +4 -0
- data/README.md +25 -21
- data/lib/bahia.rb +4 -3
- data/spec/bahia_spec.rb +30 -4
- metadata +2 -2
data/CHANGELOG.rdoc
CHANGED
data/README.md
CHANGED
@@ -7,8 +7,31 @@ onde nasceu capoeira. In other words, aruba for any non-cucumber test framework.
|
|
7
7
|
Usage
|
8
8
|
=====
|
9
9
|
|
10
|
-
Say you want to test your gem's executable, blarg
|
11
|
-
|
10
|
+
Say you want to test your gem's executable, blarg:
|
11
|
+
|
12
|
+
describe "blarg" do
|
13
|
+
it "prints usage without args" do
|
14
|
+
blarg
|
15
|
+
stdout.should == 'Usage: blarg COMMAND'
|
16
|
+
end
|
17
|
+
|
18
|
+
it 'prints error for double blarging' do
|
19
|
+
blarg "blarg"
|
20
|
+
stderr.should == "Bad human! No double blarging allowed"
|
21
|
+
process.success?.should == false
|
22
|
+
end
|
23
|
+
|
24
|
+
it "prints message for quoted args" do
|
25
|
+
blarg %[please handle 'blarg multiple' "blarg words"]
|
26
|
+
stdout.should == "Why u like quote so much?"
|
27
|
+
process.success?.should == true
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
As you can see, bahia provided helpers stdout, stderr and process as well as
|
32
|
+
automatically creates a method to invoke your executable.
|
33
|
+
|
34
|
+
Setting it up in your {test,spec}/helper.rb is just a simple include:
|
12
35
|
|
13
36
|
require 'bahia'
|
14
37
|
|
@@ -28,25 +51,6 @@ Say you want to test your gem's executable, blarg. So in your
|
|
28
51
|
# for your preferred framework
|
29
52
|
include some shit ...
|
30
53
|
|
31
|
-
Now acceptance test away your executable:
|
32
|
-
|
33
|
-
describe "blarg" do
|
34
|
-
it "prints usage without args" do
|
35
|
-
blarg ""
|
36
|
-
stdout.should == 'Usage: blarg COMMAND'
|
37
|
-
process.success?.should == true
|
38
|
-
end
|
39
|
-
|
40
|
-
it 'prints error for double blarging' do
|
41
|
-
blarg "blarg"
|
42
|
-
stderr.should == "Bad human! No double blarging allowed"
|
43
|
-
process.success?.should == false
|
44
|
-
end
|
45
|
-
end
|
46
|
-
|
47
|
-
As you can see, bahia provided helpers stdout, stderr and process as well as
|
48
|
-
automatically creates a blarg method.
|
49
|
-
|
50
54
|
If the above doesn't automagically work for you, configure Bahia before
|
51
55
|
including it:
|
52
56
|
|
data/lib/bahia.rb
CHANGED
@@ -1,7 +1,8 @@
|
|
1
1
|
require 'open3'
|
2
|
+
require 'shellwords'
|
2
3
|
|
3
4
|
module Bahia
|
4
|
-
VERSION = '0.
|
5
|
+
VERSION = '0.3.0'
|
5
6
|
|
6
7
|
class DetectionError < StandardError
|
7
8
|
def initialize(name)
|
@@ -18,8 +19,8 @@ module Bahia
|
|
18
19
|
raise DetectionError.new(:command)
|
19
20
|
self.command_method ||= File.basename(command)
|
20
21
|
|
21
|
-
define_method(command_method) do |cmd|
|
22
|
-
args =
|
22
|
+
define_method(command_method) do |cmd = ''|
|
23
|
+
args = Shellwords.split(cmd)
|
23
24
|
args.unshift Bahia.command
|
24
25
|
args.unshift({'RUBYLIB' => "#{Bahia.project_directory}/lib:" +
|
25
26
|
ENV['RUBYLIB']})
|
data/spec/bahia_spec.rb
CHANGED
@@ -67,10 +67,36 @@ describe Bahia do
|
|
67
67
|
Bahia.instance_method(:blarg).should_not be_nil
|
68
68
|
end
|
69
69
|
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
70
|
+
context "helper method blarg correctly calls Open3.capture" do
|
71
|
+
def open3_receives(*args)
|
72
|
+
Open3.should_receive(:capture3).with(
|
73
|
+
{'RUBYLIB' => "/dir/lib:#{ENV['RUBYLIB']}"}, executable, *args)
|
74
|
+
end
|
75
|
+
|
76
|
+
it "with no arguments" do
|
77
|
+
open3_receives
|
78
|
+
test_class.new.blarg
|
79
|
+
end
|
80
|
+
|
81
|
+
it "with word arguments" do
|
82
|
+
open3_receives 'is', 'blarg'
|
83
|
+
test_class.new.blarg('is blarg')
|
84
|
+
end
|
85
|
+
|
86
|
+
it "with single quoted arguments" do
|
87
|
+
open3_receives 'this', 'single quoteness'
|
88
|
+
test_class.new.blarg("this 'single quoteness'")
|
89
|
+
end
|
90
|
+
|
91
|
+
it "with double quoted arguments" do
|
92
|
+
open3_receives 'this', 'double quoteness'
|
93
|
+
test_class.new.blarg('this "double quoteness"')
|
94
|
+
end
|
95
|
+
|
96
|
+
it "with escaped quote arguments" do
|
97
|
+
open3_receives "can't", 'be', 'stopped'
|
98
|
+
test_class.new.blarg("can\\'t be stopped")
|
99
|
+
end
|
74
100
|
end
|
75
101
|
end
|
76
102
|
end
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: bahia
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.
|
5
|
+
version: 0.3.0
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Gabriel Horner
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2011-12-
|
13
|
+
date: 2011-12-17 00:00:00 -05:00
|
14
14
|
default_executable:
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|