Sha256: 922754052f0fa6f49deff349b216b919b353db762a5af635451cf2e445b4ea4f

Contents?: true

Size: 1.66 KB

Versions: 4

Compression:

Stored size: 1.66 KB

Contents

# -*- encoding: utf-8 -*-
require 'cucumber/rails/database'

describe Cucumber::Rails::Database do

  let(:strategy) { stub(:before_js => nil, :before_non_js => nil) }

  it 'forwards events to the selected strategy' do
    Cucumber::Rails::Database::TruncationStrategy.stub(:new => strategy)
    Cucumber::Rails::Database.javascript_strategy = :truncation

    strategy.should_receive(:before_non_js).ordered
    Cucumber::Rails::Database.before_non_js

    strategy.should_receive(:before_js).ordered
    Cucumber::Rails::Database.before_js
  end

  it 'raises an error if you use a non-understood strategy' do
    expect { Cucumber::Rails::Database.javascript_strategy = :invalid }.to raise_error(Cucumber::Rails::Database::InvalidStrategy)
  end

  describe 'using a custom strategy' do
    class ValidStrategy
      def before_js
        # Anything
      end

      def before_non_js
        # Likewise
      end
    end

    class InvalidStrategy
    end

    it 'raises an error if the strategy doens\'t support the protocol' do
      expect { Cucumber::Rails::Database.javascript_strategy = InvalidStrategy }.to raise_error(ArgumentError)
    end

    it 'accepts a custom strategy with a valid interface' do
      expect { Cucumber::Rails::Database.javascript_strategy = ValidStrategy }.not_to raise_error
    end

    it 'forwards events to a custom strategy' do
      ValidStrategy.stub(:new => strategy)
      Cucumber::Rails::Database.javascript_strategy = ValidStrategy

      strategy.should_receive(:before_non_js).ordered
      Cucumber::Rails::Database.before_non_js

      strategy.should_receive(:before_js).ordered
      Cucumber::Rails::Database.before_js
    end
  end

end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
cucumber-rails-1.4.0 spec/cucumber/rails/database_spec.rb
cucumber-rails-1.3.1 spec/cucumber/rails/database_spec.rb
cucumber-rails-1.3.0 spec/cucumber/rails/database_spec.rb
cucumber-rails-1.2.1 spec/cucumber/rails/database_spec.rb