implement file format 2.0
[coquelicot.git] / spec / spec_helper.rb
index 369e923..2546dde 100644 (file)
@@ -24,3 +24,51 @@ require 'rack/test'
 require 'rspec'
 
 require 'coquelicot'
+
+shared_context 'with Coquelicot::Application' do
+  def app
+    Coquelicot::Application
+  end
+
+  before do
+    app.set :environment, :test
+  end
+
+  around(:each) do |example|
+    path = Dir.mktmpdir('coquelicot')
+    begin
+      app.set :depot_path, path
+      example.run
+    ensure
+      FileUtils.remove_entry_secure path
+    end
+  end
+end
+
+module StoredFileHelpers
+  FIXTURES = { 'LICENSE-secret-1.0' => '1.0',
+               'small-secret-1.0' => 'small 1.0',
+               'LICENSE-secret-2.0' => '2.0'
+             }
+
+  shared_context 'with a StoredFile fixture' do |name|
+    let(:stored_file_path) {
+      File.expand_path("../fixtures/#{name}/stored_file", __FILE__)
+    }
+    let(:stored_file) { Coquelicot::StoredFile.open(stored_file_path, 'secret') }
+    let(:reference) {
+      YAML.load_file(File.expand_path("../fixtures/#{name}/reference", __FILE__))
+    }
+  end
+
+  def for_all_file_versions(&block)
+    FIXTURES.each_pair do |name, description|
+      context "with a #{description} file" do
+        include_context 'with a StoredFile fixture', name
+        instance_eval &block
+      end
+    end
+  end
+end
+
+::RSpec.configure { |c| c.extend StoredFileHelpers }