Skip to content

Commit

Permalink
dojopi
Browse files Browse the repository at this point in the history
  • Loading branch information
Ubuntu committed May 26, 2012
0 parents commit 864c64f
Show file tree
Hide file tree
Showing 5 changed files with 85 additions and 0 deletions.
4 changes: 4 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# A sample Gemfile
source "https://rubygems.org"

gem "rspec"
18 changes: 18 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
GEM
remote: https://rubygems.org/
specs:
diff-lcs (1.1.3)
rspec (2.10.0)
rspec-core (~> 2.10.0)
rspec-expectations (~> 2.10.0)
rspec-mocks (~> 2.10.0)
rspec-core (2.10.1)
rspec-expectations (2.10.0)
diff-lcs (~> 1.1.3)
rspec-mocks (2.10.1)

PLATFORMS
ruby

DEPENDENCIES
rspec
18 changes: 18 additions & 0 deletions lib/clipboard.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
class Clipboard
attr_accessor :commands, :last_commands

def initialize
@commands = []
@last_commands = []
end

def undo
@last_commands << @commands.pop
self
end

def redo
@commands << @last_commands.pop
self
end
end
44 changes: 44 additions & 0 deletions spec/clipboard_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
require 'spec_helper'

describe Clipboard do
let :mkdir do
double(:name => 'mkdir')
end

let :ls do
double(:name => 'ls')
end

before do
subject.commands << mkdir
end

it 'should respond to undo' do
subject.should respond_to :undo
end

it 'should add last_undo command' do
subject.undo
subject.commands.should be_empty
end

it 'should readdd last undo command on redo' do
subject.undo.redo
subject.commands.should == [mkdir]
end

it 'should return self when call undo' do
subject.undo.should eq subject
end

it 'should return self when call redo' do
subject.redo.should eq subject
end

it 'should undo twice and redo' do
subject.commands << ls
subject.undo.undo.redo.redo
subject.commands.should == [mkdir,ls]
subject.last_commands.should be_empty
end
end
1 change: 1 addition & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
require 'lib/clipboard'

0 comments on commit 864c64f

Please sign in to comment.