blertr 0.1.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/lib/blertr.rb ADDED
@@ -0,0 +1,2 @@
1
+
2
+ require 'blertr/control'
data/scripts/blertr ADDED
@@ -0,0 +1,52 @@
1
+ #!/usr/bin/env bash
2
+
3
+ export HOME="${HOME%%+(\/)}" # Remove trailing slashes if they exist on HOME
4
+
5
+ if [[ -z "${blertr_path:-}" ]]
6
+ then
7
+
8
+ if [[ -z "${blertr_prefix:-}" ]]
9
+ then
10
+ true ${blertr_user_install_flag:=0}
11
+ if (( UID > 0 || blertr_user_install_flag == 1 ))
12
+ then
13
+ blertr_prefix="$HOME"
14
+ else
15
+ blertr_prefix="/usr/local"
16
+ fi
17
+ fi
18
+
19
+ if [[ -z "${blertr_path:-}" ]]
20
+ then
21
+ if [[ "$blertr_prefix" = "$HOME" ]]
22
+ then
23
+ blertr_path="${blertr_prefix}/.blertr"
24
+ else
25
+ blertr_path="${blertr_prefix}/blertr"
26
+ fi
27
+ fi
28
+
29
+ export blertr_path="${blertr_path%%+(\/)}"
30
+ true ${blertr_bin_path:="$blertr_path/bin"}
31
+ export blertr_bin_path="${blertr_bin_path%%+(\/)}"
32
+ fi
33
+
34
+ if [[ -n "${blertr_path}" && -d "$blertr_path" ]]
35
+ then
36
+ true ${blertr_scripts_path:="$blertr_path/scripts"}
37
+
38
+ for script in preexec cli
39
+ do
40
+ if [[ -f "$blertr_scripts_path/$script" ]]
41
+ then
42
+ source "$blertr_scripts_path/$script"
43
+ else
44
+ printf "WARNING:
45
+ Could not source '$blertr_scripts_path/$script' as file does not exist.
46
+ Blertr will likely not work as expected.\n"
47
+ fi
48
+ done
49
+ fi
50
+
51
+
52
+
data/scripts/cli ADDED
@@ -0,0 +1,28 @@
1
+ #!/usr/bin/env bash
2
+
3
+ # called before each command and starts stopwatch
4
+ function preexec () {
5
+ export PREEXEC_CMD="$BASH_COMMAND"
6
+ export PREEXEC_TIME=$(date +'%s')
7
+ }
8
+
9
+ # called after each command, stops stopwatch
10
+ # and notifies if time elpsed exceeds threshold
11
+ function precmd () {
12
+ stop=$(date +'%s')
13
+ start=${PREEXEC_TIME:-$stop}
14
+ let elapsed=$stop-$start
15
+ min=${PREEXEC_MIN:-5}
16
+
17
+ if [ $elapsed -gt $min ];
18
+ then
19
+ if [[ -f "$blertr_bin_path/blert_now" ]]
20
+ then
21
+ $blertr_bin_path/blert_now "${PREEXEC_CMD:-Terminal Command}" $elapsed
22
+ fi
23
+ fi
24
+ unset PREEXEC_TIME
25
+ }
26
+
27
+ preexec_install
28
+
data/scripts/preexec ADDED
@@ -0,0 +1,196 @@
1
+ #!/bin/bash
2
+
3
+ # preexec.bash -- Bash support for ZSH-like 'preexec' and 'precmd' functions.
4
+
5
+ # The 'preexec' function is executed before each interactive command is
6
+ # executed, with the interactive command as its argument. The 'precmd'
7
+ # function is executed before each prompt is displayed.
8
+
9
+ # To use, in order:
10
+
11
+ # 1. source this file
12
+ # 2. define 'preexec' and/or 'precmd' functions (AFTER sourcing this file),
13
+ # 3. as near as possible to the end of your shell setup, run 'preexec_install'
14
+ # to kick everything off.
15
+
16
+ # Note: this module requires 2 bash features which you must not otherwise be
17
+ # using: the "DEBUG" trap, and the "PROMPT_COMMAND" variable. preexec_install
18
+ # will override these and if you override one or the other this _will_ break.
19
+
20
+ # This is known to support bash3, as well as *mostly* support bash2.05b. It
21
+ # has been tested with the default shells on MacOS X 10.4 "Tiger", Ubuntu 5.10
22
+ # "Breezy Badger", Ubuntu 6.06 "Dapper Drake", and Ubuntu 6.10 "Edgy Eft".
23
+
24
+
25
+ # Copy screen-run variables from the remote host, if they're available.
26
+
27
+ if [[ "$SCREEN_RUN_HOST" == "" ]]
28
+ then
29
+ SCREEN_RUN_HOST="$LC_SCREEN_RUN_HOST"
30
+ SCREEN_RUN_USER="$LC_SCREEN_RUN_USER"
31
+ fi
32
+
33
+ # This variable describes whether we are currently in "interactive mode";
34
+ # i.e. whether this shell has just executed a prompt and is waiting for user
35
+ # input. It documents whether the current command invoked by the trace hook is
36
+ # run interactively by the user; it's set immediately after the prompt hook,
37
+ # and unset as soon as the trace hook is run.
38
+ preexec_interactive_mode=""
39
+
40
+ # Default do-nothing implementation of preexec.
41
+ function preexec () {
42
+ true
43
+ }
44
+
45
+ # Default do-nothing implementation of precmd.
46
+ function precmd () {
47
+ true
48
+ }
49
+
50
+ # This function is installed as the PROMPT_COMMAND; it is invoked before each
51
+ # interactive prompt display. It sets a variable to indicate that the prompt
52
+ # was just displayed, to allow the DEBUG trap, below, to know that the next
53
+ # command is likely interactive.
54
+ function preexec_invoke_cmd () {
55
+ precmd
56
+ preexec_interactive_mode="yes"
57
+ }
58
+
59
+ # This function is installed as the DEBUG trap. It is invoked before each
60
+ # interactive prompt display. Its purpose is to inspect the current
61
+ # environment to attempt to detect if the current command is being invoked
62
+ # interactively, and invoke 'preexec' if so.
63
+ function preexec_invoke_exec () {
64
+ if [[ -n "$COMP_LINE" ]]
65
+ then
66
+ # We're in the middle of a completer. This obviously can't be
67
+ # an interactively issued command.
68
+ return
69
+ fi
70
+ if [[ -z "$preexec_interactive_mode" ]]
71
+ then
72
+ # We're doing something related to displaying the prompt. Let the
73
+ # prompt set the title instead of me.
74
+ return
75
+ else
76
+ # If we're in a subshell, then the prompt won't be re-displayed to put
77
+ # us back into interactive mode, so let's not set the variable back.
78
+ # In other words, if you have a subshell like
79
+ # (sleep 1; sleep 2)
80
+ # You want to see the 'sleep 2' as a set_command_title as well.
81
+ if [[ 0 -eq "$BASH_SUBSHELL" ]]
82
+ then
83
+ preexec_interactive_mode=""
84
+ fi
85
+ fi
86
+ if [[ "preexec_invoke_cmd" == "$BASH_COMMAND" ]]
87
+ then
88
+ # Sadly, there's no cleaner way to detect two prompts being displayed
89
+ # one after another. This makes it important that PROMPT_COMMAND
90
+ # remain set _exactly_ as below in preexec_install. Let's switch back
91
+ # out of interactive mode and not trace any of the commands run in
92
+ # precmd.
93
+
94
+ # Given their buggy interaction between BASH_COMMAND and debug traps,
95
+ # versions of bash prior to 3.1 can't detect this at all.
96
+ preexec_interactive_mode=""
97
+ return
98
+ fi
99
+
100
+ # In more recent versions of bash, this could be set via the "BASH_COMMAND"
101
+ # variable, but using history here is better in some ways: for example, "ps
102
+ # auxf | less" will show up with both sides of the pipe if we use history,
103
+ # but only as "ps auxf" if not.
104
+ local this_command=`history 1 | sed -e "s/^[ ]*[0-9]*[ ]*//g"`;
105
+
106
+ # If none of the previous checks have earlied out of this function, then
107
+ # the command is in fact interactive and we should invoke the user's
108
+ # preexec hook with the running command as an argument.
109
+ preexec "$this_command"
110
+ }
111
+
112
+ # Execute this to set up preexec and precmd execution.
113
+ function preexec_install () {
114
+
115
+ # *BOTH* of these options need to be set for the DEBUG trap to be invoked
116
+ # in ( ) subshells. This smells like a bug in bash to me. The null stderr
117
+ # redirections are to quiet errors on bash2.05 (i.e. OSX's default shell)
118
+ # where the options can't be set, and it's impossible to inherit the trap
119
+ # into subshells.
120
+
121
+ set -o functrace > /dev/null 2>&1
122
+ shopt -s extdebug > /dev/null 2>&1
123
+
124
+ # Finally, install the actual traps.
125
+ PROMPT_COMMAND=preexec_invoke_cmd
126
+ trap 'preexec_invoke_exec' DEBUG
127
+ }
128
+
129
+ # Since this is the reason that 99% of everybody is going to bother with a
130
+ # pre-exec hook anyway, we'll include it in this module.
131
+
132
+ # Change the title of the xterm.
133
+ function preexec_xterm_title () {
134
+ local title="$1"
135
+ echo -ne "\e]0;$title\007"
136
+ }
137
+
138
+ function preexec_screen_title () {
139
+ local title="$1"
140
+ echo -ne "\ek$1\e\\"
141
+ }
142
+
143
+ # Abbreviate the "user@host" string as much as possible to preserve space in
144
+ # screen titles. Elide the host if the host is the same, elide the user if the
145
+ # user is the same.
146
+ function preexec_screen_user_at_host () {
147
+ local RESULT=""
148
+ if [[ "$SCREEN_RUN_HOST" == "$SCREEN_HOST" ]]
149
+ then
150
+ return
151
+ else
152
+ if [[ "$SCREEN_RUN_USER" == "$USER" ]]
153
+ then
154
+ echo -n "@${SCREEN_HOST}"
155
+ else
156
+ echo -n "${USER}@${SCREEN_HOST}"
157
+ fi
158
+ fi
159
+ }
160
+
161
+ function preexec_xterm_title_install () {
162
+ # These functions are defined here because they only make sense with the
163
+ # preexec_install below.
164
+ function precmd () {
165
+ preexec_xterm_title "${TERM} - ${USER}@${SCREEN_HOST} `dirs -0` $PROMPTCHAR"
166
+ if [[ "$TERM" == screen ]]
167
+ then
168
+ preexec_screen_title "`preexec_screen_user_at_host`${PROMPTCHAR}"
169
+ fi
170
+ }
171
+
172
+ function preexec () {
173
+ preexec_xterm_title "${TERM} - $1 {`dirs -0`} (${USER}@${SCREEN_HOST})"
174
+ if [[ $TERM == screen ]]
175
+ then
176
+ local cutit="$1"
177
+ local cmdtitle=`echo "$cutit" | cut -d " " -f 1`
178
+ if [[ "$cmdtitle" == "exec" ]]
179
+ then
180
+ local cmdtitle=`echo "$cutit" | cut -d " " -f 2`
181
+ fi
182
+ if [[ "$cmdtitle" == "screen" ]]
183
+ then
184
+ # Since stacked screens are quite common, it would be nice to
185
+ # just display them as '$$'.
186
+ local cmdtitle="${PROMPTCHAR}"
187
+ else
188
+ local cmdtitle=":$cmdtitle"
189
+ fi
190
+ preexec_screen_title "`preexec_screen_user_at_host`${PROMPTCHAR}$cmdtitle"
191
+ fi
192
+ }
193
+
194
+ preexec_install
195
+ }
196
+
@@ -0,0 +1,68 @@
1
+
2
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
3
+
4
+ describe Blertr::Blacklist do
5
+ before(:each) do
6
+ @blacklist_path = File.expand_path(destination_root + "/blacklist.yaml")
7
+ @blacklist = Blertr::Blacklist.new(@blacklist_path)
8
+ end
9
+
10
+ after(:each) do
11
+ @blacklist.clear
12
+ end
13
+
14
+ it "should load blank blacklist" do
15
+ blacklist_path = File.expand_path(destination_root + "/fakelist.yaml")
16
+ blacklist = Blertr::Blacklist.new(blacklist_path)
17
+ blacklist.list.should == []
18
+ end
19
+
20
+ it "should add name" do
21
+ name = "git"
22
+ @blacklist.add name
23
+ @blacklist.list.should == [name]
24
+ another_name = "ssh"
25
+ @blacklist.add another_name
26
+ @blacklist.list.should == [name,another_name]
27
+ end
28
+
29
+ it "should store names" do
30
+ name = "git"
31
+ @blacklist.add name
32
+ another_name = "ssh"
33
+ @blacklist.add another_name
34
+ another_blacklist = Blertr::Blacklist.new(@blacklist_path)
35
+ another_blacklist.list.should == [name, another_name]
36
+ end
37
+
38
+ it "should indicate blocked programs" do
39
+ names = ["git", "ssh", "once_over" "dadada"]
40
+ not_blocked = ["cp", "ssl", "screen", "mv"]
41
+ blacklist_path = File.expand_path(destination_root + "/blacklist.yaml")
42
+ blacklist = Blertr::Blacklist.new(blacklist_path)
43
+ names.each do |name|
44
+ blacklist.add name
45
+ blacklist.blacklisted?(name).should == true
46
+ not_blocked.each {|np| blacklist.blacklisted?(np).should == false}
47
+ end
48
+ blacklist.clear
49
+ end
50
+
51
+ it "should handle full commands" do
52
+ commands = [["git diff","git diff"], ["ssh", "ssh 123@123.com"], ["cp", "cp /ma/da ./da/ma"]]
53
+
54
+ commands.each do |name, command|
55
+ @blacklist.add name
56
+ @blacklist.blacklisted?(command).should == true
57
+ end
58
+ end
59
+
60
+ it "should not exclude similar commands" do
61
+ commands = [["git diff","git diff", "git log"], ["ssh", "ssh 123@123.com", "scp 123@123.com"], ["cp", "cp /ma/da ./da/ma"]]
62
+ commands.each do |name, command, similar_command|
63
+ @blacklist.add name
64
+ @blacklist.blacklisted?(command).should == true
65
+ @blacklist.blacklisted?(similar_command).should == false
66
+ end
67
+ end
68
+ end
@@ -0,0 +1,39 @@
1
+
2
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
3
+
4
+ describe Blertr::Control do
5
+ before(:each) do
6
+ end
7
+
8
+ it "should load notifiers" do
9
+ Blertr::Control::notifiers.empty?.should_not == true
10
+ notifier_names = Blertr::Control::notifiers.collect {|n| n.name}
11
+ notifier_names.include?('mail').should == true
12
+ notifier_names.include?(nil).should == false
13
+ end
14
+
15
+ it "should distinguish notifier names" do
16
+ notifier_names = Blertr::Control::notifiers.collect {|n| n.name}
17
+ notifier_names.each {|name| Blertr::Control::is_notifier?(name).should == true}
18
+ end
19
+
20
+ it "should distinguish bad notifier names" do
21
+ bad_names = ["asdf", 123, nil, "DdDdDd"]
22
+ bad_names.each {|name| Blertr::Control::is_notifier?(name).should == false}
23
+ end
24
+
25
+ it "should distinguish alias names" do
26
+ alias_names = ["mail", "tweet"]
27
+ alias_names.each {|name| Blertr::Control::is_notifier?(name).should == true}
28
+ end
29
+
30
+ it "should get notifier with name" do
31
+ notifier = Blertr::Control::notifier_with_name 'mail'
32
+ notifier.name.should == 'mail'
33
+ end
34
+
35
+ it "should return nil for invalid notifier" do
36
+ notifier = Blertr::Control::notifier_with_name 'caterall'
37
+ notifier.should == nil
38
+ end
39
+ end
@@ -0,0 +1,18 @@
1
+
2
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
3
+ require 'blertr/growl_notifier'
4
+
5
+ describe Blertr::GrowlNotifier do
6
+ before(:each) do
7
+ @notifier = Blertr::GrowlNotifier.new
8
+ end
9
+
10
+ it "should have a name" do
11
+ @notifier.name.should == "growl"
12
+ end
13
+
14
+ it "should be able to alert" do
15
+ #TODO: fix to be only true if growl_notify is installed
16
+ @notifier.can_alert?.should == true
17
+ end
18
+ end
@@ -0,0 +1,48 @@
1
+
2
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
3
+ require 'blertr/mail_notifier'
4
+
5
+
6
+ describe Blertr::MailNotifier do
7
+ before(:each) do
8
+ @notifier = Blertr::MailNotifier.new
9
+ end
10
+
11
+ it "should have a name" do
12
+ @notifier.name.should == "mail"
13
+ end
14
+
15
+ it "should have aliases" do
16
+ @notifier.names.include?("mail").should == true
17
+ end
18
+
19
+ it "should have options" do
20
+ @notifier.options.empty?.should == false
21
+ @notifier.options[:username].class.should == String
22
+ @notifier.options[:time].class.should == Fixnum
23
+ end
24
+
25
+ it "should be capable of alerting" do
26
+ @notifier.can_alert?.should == true
27
+ end
28
+
29
+ it "should alert if time is in range" do
30
+ @notifier.options[:time] = 20
31
+ @notifier.will_alert?("name", 21).should == true
32
+ @notifier.will_alert?("name", 19).should == false
33
+ @notifier.options[:time] = 19
34
+ @notifier.will_alert?("name", 19).should == true
35
+ @notifier.will_alert?("name", 20000).should == true
36
+ @notifier.options[:time] = 20001
37
+ @notifier.will_alert?("name", 20000).should == false
38
+ end
39
+
40
+ it "should save new time" do
41
+ old_time = @notifier.options[:time]
42
+ new_time = old_time + 100
43
+ @notifier.set_time new_time
44
+ @notifier.options[:time].should == new_time
45
+ @notifier.set_time old_time
46
+ @notifier.options[:time].should == old_time
47
+ end
48
+ end
@@ -0,0 +1,63 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe Blertr::Message do
4
+ describe "basic functionality" do
5
+ before(:each) do
6
+ @command = "cp -r ./ddd/aaa /aaa/ddd"
7
+ @short_name = "cp"
8
+ @seconds = 240
9
+ @message = Blertr::Message.new(@command, @seconds)
10
+ end
11
+
12
+ it "should output command name" do
13
+ @message.command.should == @command
14
+ end
15
+
16
+ it "should output time in seconds" do
17
+ @message.seconds.should == @seconds
18
+ end
19
+
20
+ it "should output command short name" do
21
+ @message.command_short_name.should == @short_name
22
+ end
23
+ end
24
+ describe "time string" do
25
+ before(:each) do
26
+ @command = "cp -r ./ddd/aaa /aaa/ddd"
27
+ @short_name = "cp"
28
+ @message = Blertr::Message.new(@command, 0)
29
+ @one_min = 60
30
+ @min_per_hour = 60
31
+ end
32
+
33
+ it "should describe time in seconds" do
34
+ [0, 10, 20, 35, 45, 55, 59].each do |seconds|
35
+ @message.seconds = seconds
36
+ @message.time_string.should == "#{seconds} seconds"
37
+ end
38
+ @message.seconds = 1
39
+ @message.time_string.should == "1 second"
40
+ end
41
+
42
+ it "should describe time in minutes" do
43
+ @message.seconds = 60
44
+ @message.time_string.should == "1 minute"
45
+ (2..59).each do |min|
46
+ seconds = min * @one_min
47
+ @message.seconds = seconds
48
+ @message.time_string.should == "#{min} minutes"
49
+ end
50
+ end
51
+
52
+ it "should describe time in hours" do
53
+ hour = 60 * 60
54
+ @message.seconds = hour
55
+ @message.time_string.should == "1 hour"
56
+ (2..59).each do |hour|
57
+ seconds = hour * @one_min * @min_per_hour
58
+ @message.seconds = seconds
59
+ @message.time_string.should == "#{hour.to_f} hours"
60
+ end
61
+ end
62
+ end
63
+ end
@@ -0,0 +1,26 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+ require 'blertr/notifier'
3
+
4
+ describe Blertr::Notifier do
5
+ before(:each) do
6
+ @notifier = Blertr::Notifier.new
7
+ end
8
+
9
+ it "should have no default name" do
10
+ @notifier.name.should == nil
11
+ end
12
+
13
+
14
+ it "should not have any options" do
15
+ @notifier.options.empty?.should == true
16
+ end
17
+
18
+ it "should not be able to alert" do
19
+ @notifier.can_alert?.should == false
20
+ end
21
+
22
+ it "should not alert by default" do
23
+ @notifier.will_alert?("name", 233).should == false
24
+ end
25
+
26
+ end
@@ -0,0 +1,44 @@
1
+
2
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
3
+ require 'blertr/options'
4
+
5
+ describe Blertr::Options do
6
+ before(:each) do
7
+ @mail_options = Blertr::Options::options_for("mail")
8
+ end
9
+
10
+ it "should get options given name" do
11
+ @mail_options.class.should == Hash
12
+ @mail_options.empty?.should_not == true
13
+ @mail_options[:username].should_not == nil
14
+ end
15
+
16
+ it "should have a valid config path and files" do
17
+ config_file = Blertr::Options::config_file_for("mail")
18
+ config_path = Blertr::Options::config_path
19
+ File.exists?(config_file).should == true
20
+ File.directory?(config_path).should == true
21
+ config_files = Dir.glob(File.join(config_path, "*_config.yaml"))
22
+ config_files.empty?.should == false
23
+ end
24
+
25
+ it "should be blank for missing notifiers" do
26
+ Blertr::Options::remove_optons_for "missing"
27
+ missing_options = Blertr::Options::options_for("missing")
28
+ missing_options.empty?.should == true
29
+ end
30
+
31
+ it "should create for new notifiers" do
32
+ missing_options = Blertr::Options::options_for("missing")
33
+ missing_options.empty?.should == true
34
+
35
+ missing_options[:time] = 123
36
+ missing_options[:status] = "help"
37
+ Blertr::Options::save_options_for "missing", missing_options
38
+
39
+ not_missing_options = Blertr::Options::options_for("missing")
40
+ not_missing_options.empty?.should == false
41
+
42
+ Blertr::Options::remove_optons_for "missing"
43
+ end
44
+ end
@@ -0,0 +1,43 @@
1
+ $TESTING=true
2
+
3
+ require 'simplecov'
4
+ SimpleCov.start do
5
+ add_group 'Libraries', 'lib'
6
+ add_group 'Specs', 'spec'
7
+ end
8
+
9
+ $:.unshift(File.join(File.dirname(__FILE__), "..", "lib"))
10
+ require 'blertr'
11
+ require 'stringio'
12
+
13
+ require 'rdoc'
14
+ require 'rspec'
15
+
16
+ # Load fixtures
17
+ #load File.join(File.dirname(__FILE__), "fixtures", "simple_pipeline.rb")
18
+
19
+ RSpec.configure do |config|
20
+ def capture(stream)
21
+ begin
22
+ stream = stream.to_s
23
+ eval "$#{stream} = StringIO.new"
24
+ yield
25
+ result = eval("$#{stream}").string
26
+ ensure
27
+ eval("$#{stream} = #{stream.upcase}")
28
+ end
29
+
30
+ result
31
+ end
32
+
33
+ def source_root
34
+ File.join(File.dirname(__FILE__), 'fixtures')
35
+ end
36
+
37
+ def destination_root
38
+ File.join(File.dirname(__FILE__), 'sandbox')
39
+ end
40
+
41
+ alias :silence :capture
42
+ end
43
+
@@ -0,0 +1,32 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe Blertr::TimeParser do
4
+ before(:each) do
5
+ end
6
+
7
+ it "should convert time words" do
8
+ ["seconds", "second", "sec", "secs", "s"].each do |sec_word|
9
+ Blertr::TimeParser.convert_word(sec_word).should == 1
10
+ end
11
+
12
+ ["min", "mins", "minutes", "minute", "m"].each do |min_word|
13
+ Blertr::TimeParser.convert_word(min_word).should == 60
14
+ end
15
+
16
+ ["h", "hrs", "hours", "hour"].each do |hr_word|
17
+ Blertr::TimeParser.convert_word(hr_word).should == (60 * 60)
18
+ end
19
+
20
+ ["d", "days", "day"].each do |day_word|
21
+ Blertr::TimeParser.convert_word(day_word).should == (60 * 60 * 24)
22
+ end
23
+ end
24
+
25
+ it "should convert to seconds" do
26
+ conversions = [["1 day", (60*60*24)], ["123", 123], ["2 mins", 120],
27
+ ["36 hours", (60*60*36)], ["1 second", 1], ["5 minutes", (60*5)]]
28
+ conversions.each do |string, seconds|
29
+ Blertr::TimeParser.to_seconds(string).should == seconds
30
+ end
31
+ end
32
+ end