Sha256: 39a18684d5d3d11923e89eabff134926d2b4d0a4afd7682305440b26ef6c8d79

Contents?: true

Size: 1.35 KB

Versions: 3

Compression:

Stored size: 1.35 KB

Contents

require 'device_map'

RSpec.describe DeviceMap::DeviceData::Patterns do
  let(:keyword) { 'keyword' }

  let(:pattern) do
    DeviceMap::Pattern.new(keyword, 'device_id', 1)
  end

  # FIXME: Bad specs
  describe '.parse' do
    it 'returns instance of patterns class' do
      builder_stub = double(:builder, patterns: Array(pattern))
      expect(DeviceMap::DeviceData::Builder).to receive(:find) { builder_stub }

      openddr_builder = Nokogiri::XML::Builder.new do |xml|
        xml.ODDR do
          xml.Builders do
            xml.builder do
              xml.device do
                xml.list do
                  xml.value_ 'test'
                end
              end
            end
          end
        end
      end

      patterns = described_class.parse(openddr_builder.to_xml)

      expect(patterns).to be_a(described_class)
      expect(patterns.find(keyword)).to include pattern
    end
  end

  describe '#find' do
    it 'returns list of patterns for the given keyword' do
      patterns = described_class.new(Array(pattern))
      search_results = patterns.find(keyword)

      expect(search_results).to include pattern
    end

    it 'returns empty list if keyword is not found' do
      all_patterns = []
      patterns = described_class.new(all_patterns)
      devices = patterns.find('anything')
      expect(devices).to be_empty
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
device_map-0.1.2 spec/device_data/patterns_spec.rb
device_map-0.1.1 spec/device_data/patterns_spec.rb
device_map-0.1.0 spec/device_data/patterns_spec.rb