Skip to content
Browse files

shelr dump

  - removed mocha
  - some specs for publisher
  - updated man
  • Loading branch information...
1 parent 25bcc57 commit 726292b27a4fe3130b896e9fe45686c55f6cd51c @antono antono committed Mar 25, 2012
Showing with 114 additions and 25 deletions.
  1. +3 −1 Gemfile
  2. +11 −4 Gemfile.lock
  3. +13 −4 bin/shelr
  4. +1 −1 features/recording.feature
  5. +34 −6 lib/shelr/publisher.rb
  6. +5 −1 shelr.1
  7. +3 −0 shelr.1.ronn
  8. +1 −0 spec/fixtures/record1.json
  9. +33 −2 spec/shelr/publisher_spec.rb
  10. +3 −3 spec/shelr/recorder_spec.rb
  11. +7 −3 spec/spec_helper.rb
View
4 Gemfile
@@ -3,9 +3,11 @@ source "http://rubygems.org"
gem 'json'
group :development, :test do
+ gem "pry"
+ gem "pry-nav"
+ gem "rspec"
gem "rspec"
gem "aruba", :git => 'git://github.com/cucumber/aruba.git'
- gem "mocha"
gem "bundler"
gem "jeweler"
gem "simplecov"
View
15 Gemfile.lock
@@ -14,6 +14,7 @@ GEM
builder (3.0.0)
childprocess (0.3.1)
ffi (~> 1.0.6)
+ coderay (1.0.5)
cucumber (1.1.9)
builder (>= 2.1.2)
diff-lcs (>= 1.1.2)
@@ -31,10 +32,14 @@ GEM
rake
rdoc
json (1.6.5)
- metaclass (0.0.1)
- mocha (0.10.5)
- metaclass (~> 0.0.1)
+ method_source (0.7.1)
multi_json (1.1.0)
+ pry (0.9.8.2)
+ coderay (~> 1.0.5)
+ method_source (~> 0.7)
+ slop (>= 2.4.4, < 3)
+ pry-nav (0.1.0)
+ pry (~> 0.9.8.1)
rake (0.9.2.2)
rdoc (3.12)
json (~> 1.4)
@@ -50,6 +55,7 @@ GEM
multi_json (~> 1.0)
simplecov-html (~> 0.5.3)
simplecov-html (0.5.3)
+ slop (2.4.4)
term-ansicolor (1.0.7)
PLATFORMS
@@ -60,6 +66,7 @@ DEPENDENCIES
bundler
jeweler
json
- mocha
+ pry
+ pry-nav
rspec
simplecov
View
17 bin/shelr
@@ -19,6 +19,11 @@ HELP = <<-HELP
push last - publish last record
push RECORD_ID - publish
+ Getting record as json:
+
+ dump last - dump last record as json to current dir
+ dump RECORD_ID - dump any record as json to current dir
+
Replaying:
list - print list of records
@@ -53,7 +58,14 @@ when 'play'
puts "Missing id for shellcast"
Shelr::Player.list
puts "Select one..."
- exit
+ end
+when 'dump'
+ if ARGV[1]
+ Shelr::Publisher.new.dump(ARGV[1])
+ else
+ puts "What do you want to dump?"
+ Shelr::Player.list
+ puts "Select one..."
end
when 'push'
if ARGV[1]
@@ -62,21 +74,18 @@ when 'push'
puts "What do you want to publish?"
Shelr::Player.list
puts "Select one..."
- exit
end
when 'setup'
if ARGV[1]
Shelr.api_key = ARGV[1]
else
puts "\n\tUsage: #{BASENAME} setup API_KEY\n\n"
- exit
end
when 'backend'
if ARGV[1]
Shelr.backend = ARGV[1]
else
puts "\n\tUsage: #{BASENAME} backend [ttyrec|script]\n\n"
- exit
end
when 'version'
puts Shelr::VERSION
View
2 features/recording.feature
@@ -1,7 +1,7 @@
Feature: Recording shell
In order to impress the world
- As a `shelr` user
+ As a `Ŝelr` user
I would like to record my terminal
Background:
View
40 lib/shelr/publisher.rb
@@ -5,10 +5,34 @@ module Shelr
class Publisher
def publish(id)
- uri = URI.parse(Shelr::API_URL + '/records')
- params = { 'record' => prepare(id) }
- params.merge!({'api_key' => Shelr.api_key}) if api_key
- res = Net::HTTP.post_form(uri, params)
+ with_exception_handler do
+ uri = URI.parse(Shelr::API_URL + '/records')
+ params = { 'record' => prepare(id) }
+ params.merge!({'api_key' => Shelr.api_key}) if api_key
+ handle_response Net::HTTP.post_form(uri, params)
+ end
+ end
+
+ def dump(id)
+ with_exception_handler do
+ File.open(dump_filename, 'w+') do |f|
+ f.puts(prepare(id))
+ end
+ puts "=> record dumped to #{dump_filename}"
+ end
+ end
+
+ private
+
+ def with_exception_handler(&block)
+ yield
+ rescue => e
+ puts "=> Something went wrong..."
+ puts e.message
+ puts e.backtrace.join("\n")
+ end
+
+ def handle_response(res)
res = JSON.parse(res.body)
if res['ok']
puts res['message']
@@ -18,6 +42,10 @@ def publish(id)
end
end
+ def dump_filename
+ File.join(Dir.getwd, 'shelr-record.json')
+ end
+
def api_key
unless Shelr.api_key
print 'Paste your API KEY [or Enter to publish as Anonymous]: '
@@ -29,8 +57,8 @@ def api_key
def prepare(id)
puts
- puts 'Your record will be published under terms'
- puts 'of Creative Commons Attribution-ShareAlike 3.0 Unported'
+ puts 'Your record will be published under terms of'
+ puts 'Creative Commons Attribution-ShareAlike 3.0 Unported'
puts 'See http://creativecommons.org/licenses/by-sa/3.0/ for details.'
puts
View
6 shelr.1
@@ -1,7 +1,7 @@
.\" generated with Ronn/v0.7.3
.\" http://github.com/rtomayko/ronn/tree/0.7.3
.
-.TH "SHELR" "1" "February 2012" "" ""
+.TH "SHELR" "1" "March 2012" "" ""
.
.SH "NAME"
\fBshelr\fR \- screencasting for shell ninjas
@@ -33,6 +33,10 @@ plays local or remote shellcast\.
\fBpush\fR
publish your shellcast
.
+.TP
+\fBdump\fR
+dump shellcast as json to current directory\.
+.
.SH "EXAMPLES"
Record your shellcast:
.
View
3 shelr.1.ronn
@@ -27,6 +27,9 @@ or other services.
* `push`:
publish your shellcast
+ * `dump`:
+ dump shellcast as json to current directory.
+
## EXAMPLES
Record your shellcast:
View
1 spec/fixtures/record1.json
@@ -0,0 +1 @@
+{"timing":"0.117451 100\n2.245175 1\n0.645616 1\n0.131508 2\n0.265617 41\n0.006015 198\n0.002213 174\n0.000021 100\n0.045656 1\n1.635819 1\n0.158412 1\n0.438685 1\n0.408513 4\n1.611577 41\n0.005889 100\n0.053797 6\n","typescript":"Script started on Sun 25 Mar 2012 02:09:04 PM FET\n\u001b]0;antono@libero ~/Code/shelr.tv \u0007\u001b[0;36m(\u001b[0;32mnext \u001b[0;31m✗\u001b[0;36m)\u001b[39m \u001b[0;36mshelr.tv\u001b[39m ls\r\n\u001b]0;ls {~/Code/shelr.tv} (antono@libero)\u0007\u001b[0m\u001b[01;34mapp\u001b[0m config.ru \u001b[01;34mdoc\u001b[0m Gemfile.lock Guardfile \u001b[01;34mlog\u001b[0m Rakefile \u001b[01;32mrun.sh\u001b[0m \u001b[01;34msolr\u001b[0m tags \u001b[01;34mtmp\u001b[0m \u001b[01;34mvendor\u001b[0m\r\n\u001b[01;34mconfig\u001b[0m \u001b[01;34mdb\u001b[0m Gemfile gems.tags \u001b[01;34mlib\u001b[0m \u001b[01;34mpublic\u001b[0m README.md \u001b[01;34mscript\u001b[0m \u001b[01;34mspec\u001b[0m TAGS TODO.org\r\n\u001b]0;antono@libero ~/Code/shelr.tv \u0007\u001b[0;36m(\u001b[0;32mnext \u001b[0;31m✗\u001b[0;36m)\u001b[39m \u001b[0;36mshelr.tv\u001b[39m yo !^C\r\n\u001b]0;ls {~/Code/shelr.tv} (antono@libero)\u0007\u001b]0;antono@libero ~/Code/shelr.tv \u0007\u001b[0;36m(\u001b[0;32mnext \u001b[0;31m✗\u001b[0;36m)\u001b[39m \u001b[0;36mshelr.tv\u001b[39m exit\r\n\nScript done on Sun 25 Mar 2012 02:09:12 PM FET\n","title":"hello fixture","created_at":"1332673740","columns":"141","rows":"40","description":"hello fixture","tags":"fixture, linux"}
View
35 spec/shelr/publisher_spec.rb
@@ -1,9 +1,40 @@
require 'spec_helper'
describe Shelr::Publisher do
+ before :each do
+ File.stub(:open)
+ Net::HTTP.stub(:post_form)
+ end
+
describe "#publish(id)" do
- it "should publish shellcast with API_KEY" do
- pending
+ it "should prepare record as json" do
+ STDIN.stub(:gets).and_return('something')
+ subject.stub(:handle_response)
+ subject.stub(:prepare).and_return(fixture('record1.json'))
+ subject.should_receive(:prepare).with('hello')
+
+ subject.publish('hello')
+ end
+ end
+
+ describe "#dump_filename" do
+ it "should return `pwd` + /shelr-record.json" do
+ subject.send(:dump_filename).should == File.join(Dir.getwd, 'shelr-record.json')
end
end
+
+ describe "#dump(id)" do
+ before :each do
+ @file = mock('dump file')
+ File.stub(:open).and_yield @file
+ end
+
+ it "should save prepared dump to #dump_filename" do
+ File.should_receive(:open).with(subject.send(:dump_filename), 'w+')
+ subject.should_receive(:prepare).with('hello').and_return('dump')
+ @file.should_receive(:puts).with('dump')
+ subject.dump('hello')
+ end
+ end
+
end
View
6 spec/shelr/recorder_spec.rb
@@ -3,17 +3,17 @@
describe Shelr::Recorder do
before(:each) do
- STDIN.stubs(:gets).returns('my shellcast')
+ STDIN.stub(:gets).and_return('my shellcast')
Shelr.backend = 'script'
end
describe "#record!" do
before(:each) do
- subject.stubs(:system).with(anything).returns(true)
+ subject.stub(:system).with(anything).and_return(true)
end
it "should start script session" do
- subject.expects("system").with(regexp_matches Regexp.compile("script"))
+ subject.should_receive("system").with(Regexp.compile("script"))
subject.record!
end
end
View
10 spec/spec_helper.rb
@@ -23,12 +23,16 @@
require 'shelr'
require "rubygems"
require "bundler/setup"
+require 'pry'
+require 'pry-nav'
# Requires supporting files with custom matchers and macros, etc,
# in ./support/ and its subdirectories.
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
-
-RSpec.configure do |config|
- config.mock_with :mocha
+def fixture(name)
+ file = File.join(File.expand_path("../fixtures/#{name}", __FILE__))
+ require 'pp'
+ pp file
+ JSON.parse(File.read(file))
end

0 comments on commit 726292b

Please sign in to comment.
Something went wrong with that request. Please try again.