Sha256: 4f1ea83ad16f59c4f73c684fcacdec97fb6b8e2dfd79a2bbab670ed097eedc06

Contents?: true

Size: 1.54 KB

Versions: 1

Compression:

Stored size: 1.54 KB

Contents

require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
require 'tempfile'

describe Spotlight::Query do
  before do
    @query = Spotlight::Query.new('kMDItemDisplayName = "spotlight_query_spec.rb"')
  end

  it "should create query from saved search" do
    query = Spotlight::Query.from_saved_search(fixture('test.savedSearch'))
    query.query_string.should eql('((true) && (true)) && ((* = "test*"cdw || kMDItemTextContent = "test*"cdw))')
    query.scopes.should eql(['kMDQueryScopeComputer'])
  end

  it "should create saved search from query" do
    tempfile = Tempfile.new('saved_search')

    @query.scopes << '/foo/bar'
    @query.to_saved_search(tempfile.path)

    plist = Plist::parse_xml(tempfile.path)
    plist['RawQuery'].should eql('kMDItemDisplayName = "spotlight_query_spec.rb"')
    plist['SearchCriteria']['FXScopeArrayOfPaths'].should eql(['/foo/bar'])
  end

  it "should have query string" do
    @query.query_string.should eql('kMDItemDisplayName = "spotlight_query_spec.rb"')
  end

  it "should execute query" do
    @query.scopes << File.expand_path(File.dirname(__FILE__))
    result = @query.execute
    result.size.should eql(1)
    result.first.should be_an_instance_of(Spotlight::MDItemNative)
    result.first.get(:kMDItemPath).should eql(File.expand_path(File.dirname(__FILE__) + '/spotlight_query_spec.rb'))

    @query.scopes = ['/tmp/xxx/yyy']
    result = @query.execute
    result.should be_empty
  end

  it "should execute query with empty scope" do
    result = @query.execute
    result.should_not be_empty 
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
spotlight-0.0.5 spec/spotlight_query_spec.rb