-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Ubuntu
committed
May 26, 2012
0 parents
commit 864c64f
Showing
5 changed files
with
85 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# A sample Gemfile | ||
source "https://rubygems.org" | ||
|
||
gem "rspec" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
require 'lib/clipboard' |