Sha256: c87ecef9199caf056f9ae7d46c7eed6963549359a4cca02f09405093af6d8233

Contents?: true

Size: 1.32 KB

Versions: 8

Compression:

Stored size: 1.32 KB

Contents

# encoding: utf-8
#
# This file is part of the brauser gem. Copyright (C) 2013 and above Shogun <shogun@cowtech.it>.
# Licensed under the MIT license, which can be found at http://www.opensource.org/licenses/mit-license.php.
#

require "spec_helper"

describe Brauser::Definition do
  let(:definition) { ::Brauser::Definition.new(:tag, "Label", "ABC", /(abc)+/) }

  describe "#initialize" do
    it "should assign attributes" do
      other = ::Brauser::Definition.new("A", "B", "C", "D")
      expect(other.tag).to eq("A")
      expect(other.label).to eq("B")
      expect(other.primary).to eq("C")
      expect(other.secondary).to eq("D")
    end
  end

  describe "#match" do
    it "should apply the correct matcher and return the correct value" do
      expect(definition.match(:primary, nil, "ABC")).to eq("ABC")
      expect(definition.match(:primary, nil, "CDE")).to be_nil
      expect(definition.match(:secondary, nil, "abcabc")).to be_a(MatchData)
      expect(definition.match(:secondary, nil, "abx")).to be_nil
    end

    it "should support a block matcher" do
      definition.primary = Proc.new { |definition, a, b, c| a + b + c }
      expect(definition.match(:primary, nil, 1, 2, 3)).to eq(6)
    end

    it "should return nil when the matcher is not valid" do
      expect(definition.match(:tertiary)).to be_nil
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
brauser-3.3.2 spec/brauser/definition_spec.rb
brauser-3.3.1 spec/brauser/definition_spec.rb
brauser-3.3.0 spec/brauser/definition_spec.rb
brauser-3.2.6 spec/brauser/definition_spec.rb
brauser-3.2.5 spec/brauser/definition_spec.rb
brauser-3.2.4 spec/brauser/definition_spec.rb
brauser-3.2.3 spec/brauser/definition_spec.rb
brauser-3.2.2 spec/brauser/definition_spec.rb