the_dude 0.0.2 → 0.0.3
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/Gemfile.lock +1 -1
- data/README.md +5 -5
- data/bin/dude +3 -2
- data/lib/the_dude/command.rb +8 -8
- data/lib/the_dude/dsl.rb +22 -1
- data/lib/the_dude/expression.rb +13 -9
- data/lib/the_dude/plugin.rb +34 -0
- data/lib/the_dude/setup.rb +2 -0
- data/lib/the_dude/version.rb +1 -1
- data/lib/the_dude.rb +28 -11
- data/spec/spec_helper.rb +7 -3
- data/spec/support/helpers/console.rb +77 -0
- data/spec/the_dude/command_spec.rb +16 -1
- data/spec/the_dude/dsl_spec.rb +13 -0
- data/spec/the_dude/expression_spec.rb +23 -9
- data/spec/the_dude/plugin_spec.rb +40 -0
- data/spec/the_dude_spec.rb +21 -0
- metadata +7 -4
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -13,16 +13,16 @@ For example:
|
|
13
13
|
$ dude show me pictures of cool stuff # opens a browser with a google images search for 'cool stuff'
|
14
14
|
$ dude wassup # starts top
|
15
15
|
|
16
|
-
|
17
|
-
|
18
|
-
Well, there's a few reasons
|
16
|
+
How can this be useful?
|
19
17
|
- a single dude command can trigger a bunch of other commands. Sure you
|
20
18
|
could write a shell script and run that using an alias but that assumes
|
21
19
|
you're happy writing shell scripts.
|
22
20
|
- for the command-line phobic, dude provides a friendly interface to the
|
23
21
|
command line.
|
24
|
-
- for those who are
|
25
|
-
in reducing the cognitive overhead required to run scripts
|
22
|
+
- for those who are at on the command line, there can still be a benefit
|
23
|
+
in reducing the cognitive overhead required to run scripts.
|
24
|
+
- Commands can be bundled and shared using gems meaning that command line savvy
|
25
|
+
devs can set up simpler commands for other team members to use.
|
26
26
|
|
27
27
|
## Talking to The Dude
|
28
28
|
|
data/bin/dude
CHANGED
@@ -1,10 +1,11 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
require 'the_dude'
|
3
3
|
|
4
|
-
include TheDude::Dsl
|
4
|
+
#include TheDude::Dsl
|
5
5
|
|
6
6
|
DUDERC_PATH = "#{ENV['HOME']}/.duderc"
|
7
|
-
load DUDERC_PATH if File.exists? DUDERC_PATH
|
7
|
+
#load DUDERC_PATH if File.exists? DUDERC_PATH
|
8
|
+
TheDude::Dsl.from_file DUDERC_PATH
|
8
9
|
|
9
10
|
# Setup rlwrap for readline support
|
10
11
|
if ARGV.include? '-i'
|
data/lib/the_dude/command.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
module TheDude
|
2
2
|
class Command
|
3
|
-
# [
|
4
|
-
attr_reader :
|
3
|
+
# [TheDude::Expression] The expression for this command
|
4
|
+
attr_reader :expression
|
5
5
|
|
6
6
|
# [String | Proc | Block] The answer for this command
|
7
7
|
attr_accessor :answer
|
@@ -23,12 +23,12 @@ module TheDude
|
|
23
23
|
# puts 'how are you?'
|
24
24
|
# end
|
25
25
|
#
|
26
|
-
# @param [String | Regexp]
|
27
|
-
# @param [String | Proc] answer
|
26
|
+
# @param [String | Regexp] expression the question to ask
|
27
|
+
# @param [String | Proc] answer the answer to the question
|
28
28
|
#
|
29
29
|
# @return [TheDude::Command]
|
30
|
-
def initialize
|
31
|
-
@
|
30
|
+
def initialize expression, answer=nil, &block_answer
|
31
|
+
@expression = Expression.new(expression)
|
32
32
|
@answer = block_answer || answer
|
33
33
|
|
34
34
|
TheDude.register_command self
|
@@ -39,8 +39,8 @@ module TheDude
|
|
39
39
|
# parameters.
|
40
40
|
def ask *args
|
41
41
|
begin
|
42
|
-
if answer.kind_of?
|
43
|
-
instance_exec(*args, &answer)
|
42
|
+
if answer.kind_of?(Proc)
|
43
|
+
TheDude::Dsl.new.instance_exec(*args, &answer)
|
44
44
|
else
|
45
45
|
answer
|
46
46
|
end
|
data/lib/the_dude/dsl.rb
CHANGED
@@ -1,7 +1,28 @@
|
|
1
1
|
module TheDude
|
2
|
-
|
2
|
+
class Dsl
|
3
|
+
# Forwards the call on to {TheDude.ask}
|
4
|
+
def ask *args
|
5
|
+
TheDude.ask *args
|
6
|
+
end
|
7
|
+
|
8
|
+
# Forwards the call on to {TheDude::Command.new}
|
3
9
|
def command *args, &block
|
4
10
|
TheDude::Command.new *args, &block
|
5
11
|
end
|
12
|
+
|
13
|
+
# Forwards the call on to {TheDude.say}
|
14
|
+
def say *args
|
15
|
+
TheDude.say *args
|
16
|
+
end
|
17
|
+
|
18
|
+
# Class methods
|
19
|
+
class << self
|
20
|
+
# Reads in a file and processes it using The Dude Dsl
|
21
|
+
#
|
22
|
+
# @param [String] path Path to the file to read
|
23
|
+
def from_file path
|
24
|
+
new.instance_eval File.read(path) if File.exists? path
|
25
|
+
end
|
26
|
+
end
|
6
27
|
end
|
7
28
|
end
|
data/lib/the_dude/expression.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
module TheDude
|
2
2
|
class Expression
|
3
|
-
|
3
|
+
PLACEHOLDER_REGEXP = /\s\:(\S+)/
|
4
4
|
|
5
5
|
# [String | Regexp] The expression
|
6
6
|
attr_reader :expression
|
@@ -12,6 +12,7 @@ module TheDude
|
|
12
12
|
# @return [TheDude::Expression]
|
13
13
|
def initialize expr
|
14
14
|
@expression = expr
|
15
|
+
#to_regexp
|
15
16
|
end
|
16
17
|
|
17
18
|
# Converts the expression to a regex.
|
@@ -20,21 +21,24 @@ module TheDude
|
|
20
21
|
# they are substituted for the associated regexs
|
21
22
|
#
|
22
23
|
# @return [Regexp]
|
23
|
-
def
|
24
|
+
def to_regexp
|
25
|
+
return @regexp unless @regexp.nil?
|
26
|
+
|
24
27
|
# If we have a string, escape it turn it into a regex and send it back
|
25
|
-
|
28
|
+
@regexp = /^#{Regexp.quote @expression}$/ and return @regexp if @expression.kind_of? String
|
29
|
+
@regexp = @expression
|
26
30
|
|
27
31
|
substitute_all_variables
|
28
32
|
check_for_undefined_variables
|
29
33
|
|
30
|
-
return @
|
34
|
+
return @regexp
|
31
35
|
end
|
32
36
|
|
33
37
|
private
|
34
38
|
|
35
39
|
# @return [Boolean] Whether the expression contains the specified variable
|
36
40
|
def contains_variable? var
|
37
|
-
@
|
41
|
+
@regexp.source.match /\:#{var.name.to_s}/
|
38
42
|
#@expression.source.match PLACEHOLDER_REGEX
|
39
43
|
end
|
40
44
|
|
@@ -42,16 +46,16 @@ module TheDude
|
|
42
46
|
# @return [Boolean] True if there are undefined variables
|
43
47
|
def check_for_undefined_variables
|
44
48
|
return false if @expression.kind_of? String
|
45
|
-
vars = @
|
49
|
+
vars = @regexp.source.scan(PLACEHOLDER_REGEXP)[0]
|
46
50
|
return false if vars.nil?
|
47
51
|
vars = vars.map{|v| v.strip.to_sym}
|
48
|
-
raise TheDude::UndefinedVariableError if (vars - TheDude.variables.keys).any?
|
52
|
+
raise TheDude::UndefinedVariableError.new("Undefined variables : #{(vars - TheDude.variables.keys).join(' ')} in #{@expression}") if (vars - TheDude.variables.keys).any?
|
49
53
|
end
|
50
54
|
|
51
55
|
# [Regexp] Substitues the specified variable for its pattern and converts
|
52
56
|
# the result back to a regex
|
53
57
|
def substitute_variable var
|
54
|
-
subbed = @
|
58
|
+
subbed = @regexp.source.gsub(/\:#{var.name}(\s|$)/, "(#{var.pattern.source}) ")
|
55
59
|
subbed.strip! if subbed
|
56
60
|
Regexp.new subbed
|
57
61
|
end
|
@@ -59,7 +63,7 @@ module TheDude
|
|
59
63
|
# Substitutes all variables in the expression for their pattern
|
60
64
|
def substitute_all_variables
|
61
65
|
TheDude.variables.each do |key, val|
|
62
|
-
@
|
66
|
+
@regexp = substitute_variable(val) if contains_variable? val
|
63
67
|
end
|
64
68
|
end
|
65
69
|
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
module TheDude
|
2
|
+
# Plugins can contain additional commands or integrate other tools into the
|
3
|
+
# dude
|
4
|
+
class Plugin
|
5
|
+
# [String] The name of the plugin
|
6
|
+
attr_reader :name
|
7
|
+
|
8
|
+
# Intializes a new TheDude::Plugin instance
|
9
|
+
def initialize name
|
10
|
+
@name = name
|
11
|
+
end
|
12
|
+
|
13
|
+
def gem_name
|
14
|
+
@gem_name ||= "the_dude-#{name}"
|
15
|
+
end
|
16
|
+
|
17
|
+
class << self
|
18
|
+
# Returns all the plugins that are installed. This works by examining the
|
19
|
+
# installed gems. Any installed gem whose name begins with the_dude- is
|
20
|
+
# assumed to be a plugin for The Dude
|
21
|
+
def all
|
22
|
+
begin
|
23
|
+
Gem::Specification.latest_specs. # Get all the installed gems
|
24
|
+
collect{|s| s.name}. # Collect the names
|
25
|
+
grep(/the_dude\-/). # Filter for those beginning with the_dude-
|
26
|
+
map{|s| TheDude::Plugin.new s[9..s.length]} # Trim off the prefix
|
27
|
+
# and convert to Plugin instance
|
28
|
+
rescue
|
29
|
+
[]
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
data/lib/the_dude/setup.rb
CHANGED
@@ -19,3 +19,5 @@ TheDude::Command.new /^show me pictures of (.*)/, ->(query){ `open "https://www.
|
|
19
19
|
TheDude::Command.new /source for :url/, ->(url){ `curl #{url} | highlight --syntax html -O xterm256` }
|
20
20
|
TheDude::Command.new /headers for :url/, ->(url){ `curl -I #{url}` }
|
21
21
|
|
22
|
+
# Load plugins
|
23
|
+
TheDude::Plugin.all.each {|r| require r.gem_name}
|
data/lib/the_dude/version.rb
CHANGED
data/lib/the_dude.rb
CHANGED
@@ -9,6 +9,7 @@ require 'the_dude/config'
|
|
9
9
|
require 'the_dude/dsl'
|
10
10
|
require 'the_dude/expression'
|
11
11
|
require 'the_dude/http'
|
12
|
+
require 'the_dude/plugin'
|
12
13
|
require 'the_dude/variable'
|
13
14
|
require 'the_dude/version'
|
14
15
|
|
@@ -28,6 +29,22 @@ module TheDude
|
|
28
29
|
command.ask *arguments
|
29
30
|
end
|
30
31
|
|
32
|
+
# Returns the command registered with the specified question. This should
|
33
|
+
# be the expression before it is processed and parsed for variables
|
34
|
+
#
|
35
|
+
# @example
|
36
|
+
#
|
37
|
+
# TheDude::Comand.new(/something :cool/)
|
38
|
+
# TheDude.command(/something :cool) # returns the above command
|
39
|
+
#
|
40
|
+
# @param [String | Regex] expression A dude command
|
41
|
+
#
|
42
|
+
# @return [TheDude::Command | false]
|
43
|
+
def command expression
|
44
|
+
c = commands.select {|c, v| v.expression.expression == expression}
|
45
|
+
(c.any?) ? c.first[1] : false
|
46
|
+
end
|
47
|
+
|
31
48
|
# @return [Hash] Returns the commands the dude knows about
|
32
49
|
def commands
|
33
50
|
@commands || {}
|
@@ -48,7 +65,7 @@ module TheDude
|
|
48
65
|
# @param [TheDude::Command] command The command to register
|
49
66
|
def register_command command
|
50
67
|
@commands ||= {}
|
51
|
-
@commands[command.
|
68
|
+
@commands[command.expression.to_regexp] = command
|
52
69
|
end
|
53
70
|
|
54
71
|
# Registers a new variable with the dude
|
@@ -77,14 +94,14 @@ module TheDude
|
|
77
94
|
string
|
78
95
|
end
|
79
96
|
|
80
|
-
# Returns the arguments for
|
97
|
+
# Returns the arguments for an expression based on the specified command
|
81
98
|
#
|
82
|
-
# @param [String]
|
83
|
-
# @param [TheDude::Command] command
|
99
|
+
# @param [String] expression The question or task
|
100
|
+
# @param [TheDude::Command] command The command
|
84
101
|
#
|
85
102
|
# @return [Array] An array of arguments
|
86
|
-
def arguments_for
|
87
|
-
|
103
|
+
def arguments_for expression, command
|
104
|
+
expression.scan(command.expression.to_regexp)[0]
|
88
105
|
end
|
89
106
|
|
90
107
|
# @return [String] Applies dude formatting
|
@@ -92,18 +109,18 @@ module TheDude
|
|
92
109
|
string
|
93
110
|
end
|
94
111
|
|
95
|
-
# Returns the command for answering the specified
|
112
|
+
# Returns the command for answering the specified expression
|
96
113
|
#
|
97
|
-
# @param [String]
|
114
|
+
# @param [String] expression The expression asked
|
98
115
|
#
|
99
116
|
# @return [TheDude::Command]
|
100
|
-
def find_command_for
|
117
|
+
def find_command_for expression
|
101
118
|
# if there's an exact match return that first
|
102
|
-
return commands[
|
119
|
+
return commands[expression] if commands[expression]
|
103
120
|
|
104
121
|
commands.each do |key, val|
|
105
122
|
if key.kind_of? Regexp
|
106
|
-
return val if key =~
|
123
|
+
return val if key =~ expression
|
107
124
|
end
|
108
125
|
end
|
109
126
|
|
data/spec/spec_helper.rb
CHANGED
@@ -1,7 +1,11 @@
|
|
1
|
-
require 'the_dude'
|
2
|
-
|
3
1
|
require 'fakeweb'
|
4
|
-
require '
|
2
|
+
require 'ostruct'
|
3
|
+
|
4
|
+
Dir["#{Dir.pwd}/spec/support/**/*.rb"].each {|f| require f}
|
5
|
+
|
6
|
+
include TestHelpers::Console
|
7
|
+
|
8
|
+
require 'the_dude'
|
5
9
|
|
6
10
|
RSpec.configure do |config|
|
7
11
|
config.before :each do
|
@@ -0,0 +1,77 @@
|
|
1
|
+
module TestHelpers
|
2
|
+
# Helpers to make life in the terminal a little more pleasant
|
3
|
+
# Include them in rspec by adding
|
4
|
+
# include TestHelpers::Console
|
5
|
+
#
|
6
|
+
# to spec_helper.rb
|
7
|
+
module Console
|
8
|
+
# Colour handling functionality
|
9
|
+
module Colors
|
10
|
+
# Standard terminal color codes
|
11
|
+
COLORS = {
|
12
|
+
:reset => '0',
|
13
|
+
:bold => '1',
|
14
|
+
:red => '31',
|
15
|
+
:green => '32',
|
16
|
+
:yellow => '33',
|
17
|
+
:blue => '34',
|
18
|
+
:magenta => '35',
|
19
|
+
:cyan => '36',
|
20
|
+
:white => '37'
|
21
|
+
}
|
22
|
+
|
23
|
+
# Colours the specified text by prepending it with the standard terminal
|
24
|
+
# colour code for the specified colour. A reset code is appended in order
|
25
|
+
# to avoid accidentally colourising subsequent text.
|
26
|
+
#
|
27
|
+
# @param [String] text The text to colourise
|
28
|
+
# @param [Symbol] color The colour to use
|
29
|
+
#
|
30
|
+
# @return [String] The colourised string
|
31
|
+
def color(text, color)
|
32
|
+
if COLORS[color]
|
33
|
+
"#{start_color color}#{text}#{reset_color}"
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
# The terminal reset code
|
38
|
+
#
|
39
|
+
# @return [String]
|
40
|
+
def reset_color
|
41
|
+
"\e[#{COLORS[:reset]}m"
|
42
|
+
end
|
43
|
+
|
44
|
+
# The code for the specified colour with the necessary escape characters
|
45
|
+
#
|
46
|
+
# @return [String]
|
47
|
+
def start_color color
|
48
|
+
"\e[#{COLORS[color]}m"
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
# Functions for outputting to the terminal
|
53
|
+
module Output
|
54
|
+
# Outputs the passed variable
|
55
|
+
#
|
56
|
+
# @param [Object] var The variable to be output
|
57
|
+
# @param [Symbol] colour The colour to use
|
58
|
+
# @param [String] title A descriptive title
|
59
|
+
def out var, colour=nil, title=''
|
60
|
+
#title ||= caller[0][/`([^']*)'/, 1]
|
61
|
+
loc = caller[0].scan(/[\s\/]`?([^\/:.']+)?/)[-2..-1].join(':')
|
62
|
+
title = " #{color(title, colour)} :" unless title == ''
|
63
|
+
out = var.inspect
|
64
|
+
out = "|> #{color(loc, colour)} :>#{title} #{color(out, colour)}"
|
65
|
+
puts color(out, colour)
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
def self.included base
|
70
|
+
base.send :include, Output
|
71
|
+
base.send :include, Colors
|
72
|
+
end
|
73
|
+
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
|
@@ -38,6 +38,21 @@ describe TheDude::Command do
|
|
38
38
|
end
|
39
39
|
end
|
40
40
|
|
41
|
+
context 'when passed a string and a block param using Dsl shortcuts and full commands' do
|
42
|
+
before :each do
|
43
|
+
TheDude::Command.new 'test child', ->{'it worked'}
|
44
|
+
TheDude::Command.new /test child 2 (.*)/, ->(message){"the message says #{message}"}
|
45
|
+
TheDude::Command.new 'test block' do
|
46
|
+
message = ask 'test child'
|
47
|
+
TheDude.ask "test child 2 #{message}"
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
it 'should process both commands correctly and return the return value from the last' do
|
52
|
+
TheDude.ask('test block').should == "the message says it worked"
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
41
56
|
context 'when passed an expression question containing a defined variable' do
|
42
57
|
before :each do
|
43
58
|
TheDude::Variable.new(:server, /\S+/).register
|
@@ -45,7 +60,7 @@ describe TheDude::Command do
|
|
45
60
|
end
|
46
61
|
|
47
62
|
it 'should convert the expression to a normal regex' do
|
48
|
-
@command.
|
63
|
+
@command.expression.to_regexp.should == /connect to (\S+)/
|
49
64
|
end
|
50
65
|
end
|
51
66
|
end
|
data/spec/the_dude/dsl_spec.rb
CHANGED
@@ -5,6 +5,19 @@ describe TheDude::Dsl do
|
|
5
5
|
include TheDude::Dsl
|
6
6
|
end
|
7
7
|
|
8
|
+
describe '#ask' do
|
9
|
+
context 'when asked' do
|
10
|
+
context 'and the command exists' do
|
11
|
+
before :each do
|
12
|
+
Anony.new.command 'hey', 'what'
|
13
|
+
end
|
14
|
+
it 'should perform the requested command' do
|
15
|
+
Anony.new.ask('hey').should == 'what'
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
8
21
|
describe '#command' do
|
9
22
|
context 'when passed a question' do
|
10
23
|
before :each do
|
@@ -1,35 +1,45 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe TheDude::Expression do
|
4
|
-
describe '
|
4
|
+
describe '#expression' do
|
5
|
+
it 'should equal the original expression used to create the instance' do
|
6
|
+
TheDude::Expression.new('something :cool').expression.should == 'something :cool'
|
7
|
+
TheDude::Expression.new(/something :cool/).expression.should == /something :cool/
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
describe '#to_regexp' do
|
5
12
|
context 'when the expression is created with a string' do
|
6
13
|
before :each do
|
7
14
|
@expr = TheDude::Expression.new 'some expression'
|
15
|
+
@expr.instance_variable_set(:@regexp, nil) # Clear out the cached regexp so that it gets rebuilt after we add variables
|
8
16
|
end
|
9
17
|
|
10
18
|
it 'should return a regex that exactly matches the string' do
|
11
|
-
@expr.
|
19
|
+
@expr.to_regexp.should == /^some\ expression$/
|
12
20
|
end
|
13
21
|
end
|
14
22
|
|
15
23
|
context 'when the expression is created with a regex' do
|
16
24
|
before :each do
|
17
25
|
@expr = TheDude::Expression.new /a regex/
|
26
|
+
@expr.instance_variable_set(:@regexp, nil) # Clear out the cached regexp so that it gets rebuilt after we add variables
|
18
27
|
end
|
19
28
|
|
20
29
|
it 'should return the regex' do
|
21
|
-
@expr.
|
30
|
+
@expr.to_regexp.should == /a regex/
|
22
31
|
end
|
23
32
|
end
|
24
33
|
|
25
34
|
context 'when the expression is created with a regex containing a variable' do
|
26
35
|
before :each do
|
27
36
|
@expr = TheDude::Expression.new /a :placeholder regex/
|
37
|
+
# @expr.instance_variable_set(:@regexp, nil) # Clear out the cached regexp so that it gets rebuilt after we add variables
|
28
38
|
end
|
29
39
|
|
30
40
|
context 'and the variable is not defined' do
|
31
41
|
it 'should raise an error' do
|
32
|
-
expect{@expr.
|
42
|
+
expect{@expr.to_regexp}.to raise_error TheDude::UndefinedVariableError
|
33
43
|
end
|
34
44
|
end
|
35
45
|
|
@@ -39,7 +49,7 @@ describe TheDude::Expression do
|
|
39
49
|
end
|
40
50
|
|
41
51
|
it 'should return the regex with the variable substituted' do
|
42
|
-
@expr.
|
52
|
+
@expr.to_regexp.should == /a (\S+) regex/
|
43
53
|
end
|
44
54
|
end
|
45
55
|
end
|
@@ -49,15 +59,19 @@ describe TheDude::Expression do
|
|
49
59
|
@expr = TheDude::Expression.new /a :multiple :placeholder regex/
|
50
60
|
end
|
51
61
|
|
52
|
-
context 'and neither variable is
|
62
|
+
context 'and neither variable is defined' do
|
53
63
|
it 'should raise an error' do
|
54
|
-
expect{@expr.
|
64
|
+
expect{@expr.to_regexp}.to raise_error TheDude::UndefinedVariableError
|
55
65
|
end
|
56
66
|
end
|
57
67
|
|
58
68
|
context 'and only one variable is defined' do
|
69
|
+
before :each do
|
70
|
+
TheDude::Variable.new(:multiple, /\d+/).register
|
71
|
+
end
|
72
|
+
|
59
73
|
it 'should raise an error' do
|
60
|
-
expect{@expr.
|
74
|
+
expect{@expr.to_regexp}.to raise_error TheDude::UndefinedVariableError
|
61
75
|
end
|
62
76
|
end
|
63
77
|
|
@@ -68,7 +82,7 @@ describe TheDude::Expression do
|
|
68
82
|
end
|
69
83
|
|
70
84
|
it 'should return the regex with the variable substituted' do
|
71
|
-
@expr.
|
85
|
+
@expr.to_regexp.should == /a (\d+) (\S+) regex/
|
72
86
|
end
|
73
87
|
end
|
74
88
|
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe TheDude::Plugin do
|
4
|
+
describe '#gem_name' do
|
5
|
+
it 'should be the name of plugin prefixed with the_ruby-' do
|
6
|
+
TheDude::Plugin.new('plugin').gem_name.should == 'the_dude-plugin'
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
describe '.all' do
|
11
|
+
subject {TheDude::Plugin.all}
|
12
|
+
|
13
|
+
context 'when a gems are installed with the the_dude- prefix' do
|
14
|
+
before :each do
|
15
|
+
# Stub the call to Gem::Specification.latest_specs
|
16
|
+
Gem::Specification.stub(:latest_specs).and_return([
|
17
|
+
OpenStruct.new(name: 'the_dude-plugin'),
|
18
|
+
OpenStruct.new(name: 'the_dude-plugin2'),
|
19
|
+
OpenStruct.new(name: 'other-gem')
|
20
|
+
])
|
21
|
+
end
|
22
|
+
|
23
|
+
its(:length) {should == 2}
|
24
|
+
|
25
|
+
describe '[0]' do
|
26
|
+
subject {TheDude::Plugin.all[0]}
|
27
|
+
|
28
|
+
it {should be_kind_of TheDude::Plugin}
|
29
|
+
its(:name) {should == 'plugin'}
|
30
|
+
end
|
31
|
+
|
32
|
+
describe '[1]' do
|
33
|
+
subject {TheDude::Plugin.all[1]}
|
34
|
+
|
35
|
+
it {should be_kind_of TheDude::Plugin}
|
36
|
+
its(:name) {should == 'plugin2'}
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
data/spec/the_dude_spec.rb
CHANGED
@@ -15,6 +15,27 @@ describe TheDude do
|
|
15
15
|
end
|
16
16
|
end
|
17
17
|
|
18
|
+
describe '.command' do
|
19
|
+
context 'when passed a command' do
|
20
|
+
context 'that has not been registered' do
|
21
|
+
it 'should return false' do
|
22
|
+
TheDude.command(/duff/).should be_false
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
context 'that has been registered' do
|
27
|
+
before :each do
|
28
|
+
TheDude::Variable.new(:cool, /.*/).register
|
29
|
+
@command = TheDude::Command.new(/something :cool/)
|
30
|
+
end
|
31
|
+
|
32
|
+
it 'should return the command' do
|
33
|
+
TheDude.command(/something :cool/).should == @command
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
18
39
|
describe '.register_command' do
|
19
40
|
context 'when passed a command' do
|
20
41
|
it 'should add the command to the commands collection' do
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: the_dude
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-05-
|
12
|
+
date: 2013-05-16 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rake
|
@@ -164,10 +164,12 @@ files:
|
|
164
164
|
- lib/the_dude/dsl.rb
|
165
165
|
- lib/the_dude/expression.rb
|
166
166
|
- lib/the_dude/http.rb
|
167
|
+
- lib/the_dude/plugin.rb
|
167
168
|
- lib/the_dude/setup.rb
|
168
169
|
- lib/the_dude/variable.rb
|
169
170
|
- lib/the_dude/version.rb
|
170
171
|
- spec/spec_helper.rb
|
172
|
+
- spec/support/helpers/console.rb
|
171
173
|
- spec/support/webmocks.rb
|
172
174
|
- spec/support/webmocks/google2.html
|
173
175
|
- spec/the_dude/command_spec.rb
|
@@ -175,6 +177,7 @@ files:
|
|
175
177
|
- spec/the_dude/dsl_spec.rb
|
176
178
|
- spec/the_dude/expression_spec.rb
|
177
179
|
- spec/the_dude/http_spec.rb
|
180
|
+
- spec/the_dude/plugin_spec.rb
|
178
181
|
- spec/the_dude/variable_spec.rb
|
179
182
|
- spec/the_dude_spec.rb
|
180
183
|
- the_dude.gemspec
|
@@ -193,7 +196,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
193
196
|
version: '0'
|
194
197
|
segments:
|
195
198
|
- 0
|
196
|
-
hash:
|
199
|
+
hash: 4224877102825340562
|
197
200
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
198
201
|
none: false
|
199
202
|
requirements:
|
@@ -202,7 +205,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
202
205
|
version: '0'
|
203
206
|
segments:
|
204
207
|
- 0
|
205
|
-
hash:
|
208
|
+
hash: 4224877102825340562
|
206
209
|
requirements: []
|
207
210
|
rubyforge_project:
|
208
211
|
rubygems_version: 1.8.25
|