Skip to content

Commit

Permalink
Merge pull request #3 from aprescott/spec-changes
Browse files Browse the repository at this point in the history
Restructure specs and move to RSpec 3
  • Loading branch information
aprescott committed Aug 25, 2014
2 parents 9ba376f + bb648c9 commit 717a61d
Show file tree
Hide file tree
Showing 13 changed files with 76 additions and 31 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/Gemfile.lock
1 change: 1 addition & 0 deletions .rspec
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
--color
9 changes: 3 additions & 6 deletions rakefile
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
require "rake"
require "rspec/core/rake_task"

RSpec::Core::RakeTask.new(:test) do |t|
t.rspec_opts = "-I test --color --format nested"
t.pattern = "test/**/*_spec.rb"
t.verbose = false
t.fail_on_error = true
RSpec::Core::RakeTask.new(:spec) do |t|
t.pattern = ["spec/**/*_spec.rb"]
end

task :default => :test
task :default => :spec
File renamed without changes.
File renamed without changes.
File renamed without changes.
51 changes: 51 additions & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
require "tempfile"

require "vcdiff"

RSpec.configure do |config|
config.raise_errors_for_deprecations!

# rspec-expectations config goes here. You can use an alternate
# assertion/expectation library such as wrong or the stdlib/minitest
# assertions if you prefer.
config.expect_with :rspec do |expectations|
expectations.syntax = :expect
end

# rspec-mocks config goes here. You can use an alternate test double
# library (such as bogus or mocha) by changing the `mock_with` option here.
config.mock_with :rspec do |mocks|
# Enable only the newer, non-monkey-patching expect syntax.
# For more details, see:
# - http://teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
mocks.syntax = :expect

# Prevents you from mocking or stubbing a method that does not exist on
# a real object. This is generally recommended.
mocks.verify_partial_doubles = true
end

config.filter_run :focus
config.run_all_when_everything_filtered = true

if config.files_to_run.one?
config.full_backtrace = true
end

# Run specs in random order to surface order dependencies. If you find an
# order dependency and want to debug it, you can fix the order by providing
# the seed, which is printed after each run.
# --seed 1234
config.order = :random

# Seed global randomization in this process using the `--seed` CLI option.
# Setting this allows you to use `--seed` to deterministically reproduce
# test failures related to randomization by passing the same `--seed` value
# as the one that triggered the failure.
Kernel.srand config.seed

# TODO: Stop doing FileUtils.cd at runtime to avoid the need for this.
config.before :each do
FileUtils.cd File.expand_path(File.join(__FILE__, "..", ".."))
end
end
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
require "test_helper"
require "spec_helper"

describe VCDIFF::CodeTable do
describe "DEFAULT_TABLE" do
it "has 256 entries" do
VCDIFF::CodeTable::DEFAULT_TABLE.length == 256
end
end
end
end
12 changes: 6 additions & 6 deletions test/vcdiff_decoder_spec.rb → spec/vcdiff_decoder_spec.rb
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
require "test_helper"
require "spec_helper"

describe VCDIFF::Decoder do
subject { VCDIFF::Decoder.new("test/data/source") }
subject { VCDIFF::Decoder.new("spec/data/source") }

describe "#decode" do
it "can decode delta files, given the source, to derive the target" do
subject.decode(File.new("test/data/delta")).should == File.read("test/data/target")
expect(subject.decode(File.new("spec/data/delta"))).to eq(File.read("spec/data/target"))
end

it "cannot handle a non-zero header indicator" do
# secondary compressor
delta = Tempfile.new("secondary_compressor_bit_set")
content = File.read("test/data/delta")
content = File.read("spec/data/delta")
content.setbyte(4, 0x01)
delta.write(content)
delta.rewind
Expand All @@ -20,12 +20,12 @@

# custom codetable
delta = Tempfile.new("custom_codetable_bit_set")
content = File.read("test/data/delta")
content = File.read("spec/data/delta")
content.setbyte(4, 0x02)
delta.write(content)
delta.rewind

expect { subject.decode(delta) }.to raise_error(NotImplementedError)
end
end
end
end
8 changes: 4 additions & 4 deletions test/vcdiff_integer_spec.rb → spec/vcdiff_integer_spec.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require "test_helper"
require "spec_helper"

KNOWN_ENCODINGS = {
266478 => "100100001010000101101110",
Expand All @@ -20,9 +20,9 @@

i = VCDIFF::VCDIFFInt.read(packed)

i.snapshot.should == int
i.to_binary_s.should == packed
i.to_i.should == i.snapshot
expect(i.snapshot).to eq(int)
expect(i.to_binary_s).to eq(packed)
expect(i.to_i).to eq(i.snapshot)
end
end
end
14 changes: 6 additions & 8 deletions test/vcdiff_records_spec.rb → spec/vcdiff_records_spec.rb
Original file line number Diff line number Diff line change
@@ -1,33 +1,31 @@
require "test_helper"
require "spec_helper"

describe VCDIFF::VCDIFFHeader do
it "requires a valid header" do
# requires VCD\0 with the uppermost bits set to 1 for "V","C","D"
expect { VCDIFF::VCDIFFHeader.read("\xD6\xC3\xC4\x00") }.to_not raise_error(BinData::ValidityError)
expect { VCDIFF::VCDIFFHeader.read("\x01\x02\x03\x00") }.to raise_error(BinData::ValidityError)
end

describe "#secondary_compressor?" do
it "is true if the header_indicator has the appropriate bit set" do
header = VCDIFF::VCDIFFHeader.read("\xD6\xC3\xC4\x00\x01\x00\x00\x00\x00\x00\x00")
header.secondary_compressor?.should be_true
header.header_indicator[0].should == 1
expect(header.secondary_compressor?).to be_truthy
expect(header.header_indicator[0]).to eq(1)
end
end

describe "#custom_codetable?" do
it "is true if the header_indicator has the appropriate bit set" do
# VCD\0 + 0b10 for custom code table, plus a bunch of zeroes to have enough bytes to read
header = VCDIFF::VCDIFFHeader.read("\xD6\xC3\xC4\x00\x02\x00\x00\x00\x00\x00\x00")
header.custom_codetable?.should be_true
header.header_indicator[1].should == 1
expect(header.custom_codetable?).to be_truthy
expect(header.header_indicator[1]).to eq(1)
end
end
end

describe VCDIFF::DeltaFile do
it "requires a valid header" do
expect { VCDIFF::DeltaFile.read("\xD6\xC3\xC4\x00") }.to_not raise_error(BinData::ValidityError)
expect { VCDIFF::DeltaFile.read("\x01\x02\x03\x00") }.to raise_error(BinData::ValidityError)
end
end
end
3 changes: 0 additions & 3 deletions test/test_helper.rb

This file was deleted.

4 changes: 2 additions & 2 deletions vcdiff.rb.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ Gem::Specification.new do |gem|

[
"rake", "~> 10.0.0",
"rspec", "~> 2.5"
"rspec", "~> 3.0"
].each_slice(2) do |name, version|
gem.add_runtime_dependency(name, version)
end
end
end

0 comments on commit 717a61d

Please sign in to comment.