From bb648c9edd7cc04d577ebbad86036c3257021bf4 Mon Sep 17 00:00:00 2001 From: Adam Prescott Date: Mon, 25 Aug 2014 14:28:13 -0400 Subject: [PATCH] Restructure specs and move to RSpec 3. --- .gitignore | 1 + .rspec | 1 + rakefile | 9 ++-- {test => spec}/data/delta | Bin {test => spec}/data/source | 0 {test => spec}/data/target | 0 spec/spec_helper.rb | 51 +++++++++++++++++++++++ {test => spec}/vcdiff_code_table_spec.rb | 4 +- {test => spec}/vcdiff_decoder_spec.rb | 12 +++--- {test => spec}/vcdiff_integer_spec.rb | 8 ++-- {test => spec}/vcdiff_records_spec.rb | 14 +++---- test/test_helper.rb | 3 -- vcdiff.rb.gemspec | 4 +- 13 files changed, 76 insertions(+), 31 deletions(-) create mode 100644 .gitignore create mode 100644 .rspec rename {test => spec}/data/delta (100%) rename {test => spec}/data/source (100%) rename {test => spec}/data/target (100%) create mode 100644 spec/spec_helper.rb rename {test => spec}/vcdiff_code_table_spec.rb (85%) rename {test => spec}/vcdiff_decoder_spec.rb (71%) rename {test => spec}/vcdiff_integer_spec.rb (85%) rename {test => spec}/vcdiff_records_spec.rb (69%) delete mode 100644 test/test_helper.rb diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..66f8ed3 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/Gemfile.lock diff --git a/.rspec b/.rspec new file mode 100644 index 0000000..4e1e0d2 --- /dev/null +++ b/.rspec @@ -0,0 +1 @@ +--color diff --git a/rakefile b/rakefile index 9406fb3..721504e 100644 --- a/rakefile +++ b/rakefile @@ -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 diff --git a/test/data/delta b/spec/data/delta similarity index 100% rename from test/data/delta rename to spec/data/delta diff --git a/test/data/source b/spec/data/source similarity index 100% rename from test/data/source rename to spec/data/source diff --git a/test/data/target b/spec/data/target similarity index 100% rename from test/data/target rename to spec/data/target diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb new file mode 100644 index 0000000..90c7b8e --- /dev/null +++ b/spec/spec_helper.rb @@ -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 diff --git a/test/vcdiff_code_table_spec.rb b/spec/vcdiff_code_table_spec.rb similarity index 85% rename from test/vcdiff_code_table_spec.rb rename to spec/vcdiff_code_table_spec.rb index 5738e33..496452e 100644 --- a/test/vcdiff_code_table_spec.rb +++ b/spec/vcdiff_code_table_spec.rb @@ -1,4 +1,4 @@ -require "test_helper" +require "spec_helper" describe VCDIFF::CodeTable do describe "DEFAULT_TABLE" do @@ -6,4 +6,4 @@ VCDIFF::CodeTable::DEFAULT_TABLE.length == 256 end end -end \ No newline at end of file +end diff --git a/test/vcdiff_decoder_spec.rb b/spec/vcdiff_decoder_spec.rb similarity index 71% rename from test/vcdiff_decoder_spec.rb rename to spec/vcdiff_decoder_spec.rb index 495a55d..94ff659 100644 --- a/test/vcdiff_decoder_spec.rb +++ b/spec/vcdiff_decoder_spec.rb @@ -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 @@ -20,7 +20,7 @@ # 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 @@ -28,4 +28,4 @@ expect { subject.decode(delta) }.to raise_error(NotImplementedError) end end -end \ No newline at end of file +end diff --git a/test/vcdiff_integer_spec.rb b/spec/vcdiff_integer_spec.rb similarity index 85% rename from test/vcdiff_integer_spec.rb rename to spec/vcdiff_integer_spec.rb index d049523..bf14025 100644 --- a/test/vcdiff_integer_spec.rb +++ b/spec/vcdiff_integer_spec.rb @@ -1,4 +1,4 @@ -require "test_helper" +require "spec_helper" KNOWN_ENCODINGS = { 266478 => "100100001010000101101110", @@ -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 diff --git a/test/vcdiff_records_spec.rb b/spec/vcdiff_records_spec.rb similarity index 69% rename from test/vcdiff_records_spec.rb rename to spec/vcdiff_records_spec.rb index 6c94fe2..6f2196b 100644 --- a/test/vcdiff_records_spec.rb +++ b/spec/vcdiff_records_spec.rb @@ -1,17 +1,16 @@ -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 @@ -19,15 +18,14 @@ 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 \ No newline at end of file +end diff --git a/test/test_helper.rb b/test/test_helper.rb deleted file mode 100644 index 40b1f1f..0000000 --- a/test/test_helper.rb +++ /dev/null @@ -1,3 +0,0 @@ -require "tempfile" - -require "vcdiff" diff --git a/vcdiff.rb.gemspec b/vcdiff.rb.gemspec index 4bad8ec..1055364 100644 --- a/vcdiff.rb.gemspec +++ b/vcdiff.rb.gemspec @@ -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 \ No newline at end of file +end