Permalink
Browse files

Specs passing

  • Loading branch information...
1 parent b4fcb84 commit cc04144a750491855c7b9120d41ca8abc56490b4 @tj tj committed Oct 20, 2009
Showing with 94 additions and 59 deletions.
  1. +58 −59 lib/growl.js
  2. +36 −0 spec/spec.core.js
View
@@ -3,66 +3,65 @@
;(function(){
- /**
- * Execute the given _cmd_, returning an array of lines from stdout.
- *
- * Growl.exec('growlnotify', '-m', msg)
- *
- * @param {string ...} cmd
- * @return {array}
- * @api public
- */
-
- function exec(cmd) {
- var lines = [], line
- with (JavaImporter(java.lang, java.io)) {
- var proccess = Runtime.getRuntime().exec(Array.prototype.slice.call(arguments))
- var stream = new DataInputStream(proccess.getInputStream())
- while (line = stream.readLine())
- lines.push(line)
- stream.close()
- }
- return lines
- }
-
- /**
- * Version of the 'growlnotify' binary.
- *
- * @return {string}
- * @api private
- */
-
- function version() {
- try { return exec('growlnotify', '-v')[0].split(' ')[1] } catch (e) {}
- }
-
- /**
- * Send growl notification _msg_ with _options_.
- *
- * Options:
- *
- * - title Notification title
- *
- * Growl.notify('New email')
- * Growl.notify('5 new emails', { title: 'Thunderbird' })
- *
- * @param {string} msg
- * @param {options} hash
- * @api public
- */
-
- function notify(msg, options) {
- options = options || {}
- if (!Growl.version) throw new Error('growlnotify executable is required')
- exec('growlnotify', '-m', msg, options.title || '')
- }
-
- // --- Expose
-
Growl = {
- exec: exec,
- version: version(),
- notify: notify
+
+ // --- Version
+
+ version: '0.0.1',
+
+ /**
+ * Execute the given _cmd_, returning an array of lines from stdout.
+ *
+ * Growl.exec('growlnotify', '-m', msg)
+ *
+ * @param {string ...} cmd
+ * @return {array}
+ * @api public
+ */
+
+ exec: function(cmd) {
+ var lines = [], line
+ with (JavaImporter(java.lang, java.io)) {
+ var proccess = Runtime.getRuntime().exec(Array.prototype.slice.call(arguments))
+ var stream = new DataInputStream(proccess.getInputStream())
+ while (line = stream.readLine())
+ lines.push(line)
+ stream.close()
+ }
+ return lines
+ },
+
+ /**
+ * Version of the 'growlnotify' binary.
+ *
+ * @return {string}
+ * @api private
+ */
+
+ binVersion: function() {
+ try { return this.exec('growlnotify', '-v')[0].split(' ')[1] } catch (e) {}
+ },
+
+ /**
+ * Send growl notification _msg_ with _options_.
+ *
+ * Options:
+ *
+ * - title Notification title
+ *
+ * Growl.notify('New email')
+ * Growl.notify('5 new emails', { title: 'Thunderbird' })
+ *
+ * @param {string} msg
+ * @param {options} hash
+ * @api public
+ */
+
+ notify: function(msg, options) {
+ options = options || {}
+ if (!this.binVersion()) throw new Error('growlnotify executable is required')
+ this.exec('growlnotify', '-m', msg, options.title || '')
+ }
}
})()
View
@@ -1,5 +1,25 @@
describe 'Growl'
+ before_each
+ var exec = Growl.exec
+ Growl.exec = function(){
+ args = Array.prototype.slice.apply(arguments)
+ return exec.apply(this, arguments)
+ }
+ end
+
+ describe '.version'
+ it 'should be a version triple for our Growl library'
+ Growl.version.should.match(/^\d+\.\d+\.\d+$/)
+ end
+ end
+
+ describe '.binVersion()'
+ it 'should be set to the growlnotify version'
+ Growl.binVersion().should.match(/^\d+\.\d+\.\d+$/)
+ end
+ end
+
describe '.exec()'
it 'should execute a single arg command'
Growl.exec('ls').length.should.be_at_least 1
@@ -9,4 +29,20 @@ describe 'Growl'
Growl.exec('ls', '-ls').length.should.be_at_least 1
end
end
+
+ describe '.notify()'
+ describe 'given a message only'
+ it 'should add the -m option'
+ Growl.notify('wahoo')
+ args.should.eql ['growlnotify', '-m', 'wahoo', '']
+ end
+ end
+
+ describe 'given the title option'
+ it 'should add a trailing argument'
+ Growl.notify('5 passes', { title: 'JSpec' })
+ args.should.eql ['growlnotify', '-m', '5 passes', 'JSpec']
+ end
+ end
+ end
end

0 comments on commit cc04144

Please sign in to comment.