Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added basic specs for Brice::History.
- Loading branch information
1 parent
f1fc759
commit 448de6d
Showing
3 changed files
with
121 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 | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,3 @@ | |||
--colour | |||
--debug | |||
--require spec/spec_helper |
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 | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,97 @@ | |||
require 'brice/history' | |||
|
|||
describe Brice::History do | |||
|
|||
def hist | |||
@hist_store ||= [] | |||
end | |||
|
|||
def init_hist(opt = {}) | |||
@hist = Brice::History.new(opt.merge(:path => @path), hist) | |||
end | |||
|
|||
def saved_hist | |||
@hist.send(:save_history) | |||
File.read(@path) | |||
end | |||
|
|||
def compare_hist(input, result = input, saved = result) | |||
input.each { |i| hist.push(i) } | |||
hist.should == result | |||
saved_hist.should == saved.map { |i| "#{i}\n" }.join | |||
end | |||
|
|||
describe 'no uniq, no merge' do | |||
|
|||
before :each do | |||
init_hist(:uniq => false, :merge => false) | |||
end | |||
|
|||
example { compare_hist(%w[]) } | |||
example { compare_hist(%w[1]) } | |||
example { compare_hist(%w[1 2 3]) } | |||
example { compare_hist(%w[1] * 3, %w[1 1 1]) } | |||
example { compare_hist(%w[1 2 3 1], %w[1 2 3 1]) } | |||
|
|||
end | |||
|
|||
describe 'uniq, no merge' do | |||
|
|||
before :each do | |||
init_hist(:uniq => true, :merge => false) | |||
end | |||
|
|||
example { compare_hist(%w[]) } | |||
example { compare_hist(%w[1]) } | |||
example { compare_hist(%w[1 2 3]) } | |||
example { compare_hist(%w[1] * 3, %w[1 1 1], %w[1]) } | |||
example { compare_hist(%w[1 2 3 1], %w[1 2 3 1], %w[1 2 3]) } | |||
|
|||
end | |||
|
|||
describe 'uniq, merge' do | |||
|
|||
before :each do | |||
init_hist(:uniq => true, :merge => true) | |||
end | |||
|
|||
example { compare_hist(%w[]) } | |||
example { compare_hist(%w[1]) } | |||
example { compare_hist(%w[1 2 3]) } | |||
example { compare_hist(%w[1] * 3, %w[1]) } | |||
|
|||
# TODO: describe merging | |||
|
|||
end | |||
|
|||
describe 'reverse uniq, no merge' do | |||
|
|||
before :each do | |||
init_hist(:uniq => :reverse, :merge => false) | |||
end | |||
|
|||
example { compare_hist(%w[]) } | |||
example { compare_hist(%w[1]) } | |||
example { compare_hist(%w[1 2 3]) } | |||
example { compare_hist(%w[1] * 3, %w[1 1 1], %w[1]) } | |||
example { compare_hist(%w[1 2 3 1], %w[1 2 3 1], %w[2 3 1]) } | |||
|
|||
end | |||
|
|||
describe 'reverse uniq, merge' do | |||
|
|||
before :each do | |||
init_hist(:uniq => :reverse, :merge => true) | |||
end | |||
|
|||
example { compare_hist(%w[]) } | |||
example { compare_hist(%w[1]) } | |||
example { compare_hist(%w[1 2 3]) } | |||
example { compare_hist(%w[1] * 3, %w[1]) } | |||
example { compare_hist(%w[1 2 3 1], %w[2 3 1]) } | |||
|
|||
# TODO: describe merging | |||
|
|||
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 | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,21 @@ | |||
$:.unshift('lib') unless $:.first == 'lib' | |||
|
|||
require 'tempfile' | |||
|
|||
RSpec.configure { |config| | |||
config.before(:each) { open_tempfile } | |||
config.after(:each) { close_tempfile } | |||
|
|||
config.include(Module.new { | |||
def open_tempfile | |||
@temp = Tempfile.open("wirble_spec_#{object_id}_temp") | |||
@path = path = @temp.path | |||
|
|||
Kernel.at_exit { File.unlink(path) if File.file?(path) } | |||
end | |||
|
|||
def close_tempfile | |||
@temp.close(true) if @temp | |||
end | |||
}) | |||
} |