thinking-sphinx-rspec-matchers 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +6 -0
- data/Gemfile +4 -0
- data/README.md +41 -0
- data/Rakefile +1 -0
- data/lib/thinking-sphinx-rspec-matchers.rb +2 -0
- data/lib/thinking-sphinx-rspec-matchers/attribute_matcher.rb +31 -0
- data/lib/thinking-sphinx-rspec-matchers/field_matcher.rb +35 -0
- data/thinking-sphinx-rspec-matchers.gemspec +24 -0
- metadata +86 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
# Thinking Sphinx matchers
|
2
|
+
Ok, so here I present you my first gem. It was created out of necessity and I hope to both be useful to the community and learn a lot in the process!
|
3
|
+
|
4
|
+
|
5
|
+
# Installation
|
6
|
+
To install the matchers you only have to add the gem to your test group in `Gemfile`:
|
7
|
+
|
8
|
+
group :test do
|
9
|
+
gem 'thinking-sphinx-rspec-matchers'
|
10
|
+
end
|
11
|
+
|
12
|
+
|
13
|
+
# Use
|
14
|
+
describe "fields" do
|
15
|
+
it { should index :name, :from = :client, :as = :client_name }
|
16
|
+
it { should index :content }
|
17
|
+
end
|
18
|
+
|
19
|
+
describe "attributes" do
|
20
|
+
it { should have_attribute :user_id, :as = :users }
|
21
|
+
end
|
22
|
+
|
23
|
+
Field options
|
24
|
+
:from
|
25
|
+
:as
|
26
|
+
:facet
|
27
|
+
:sortable
|
28
|
+
|
29
|
+
Attribute Field options
|
30
|
+
:as
|
31
|
+
:facet
|
32
|
+
|
33
|
+
# References
|
34
|
+
[1] http://openmonkey.com/2009/07/19/thinking-sphinx-rspec-matchers/
|
35
|
+
|
36
|
+
[2] https://gist.github.com/21755
|
37
|
+
|
38
|
+
|
39
|
+
# Credits
|
40
|
+
Thanks to Pal Allan from http://freelancing-gods.com/ for creating Thinking Sphinx!
|
41
|
+
Thanks to Tim Riley for the initial version of the matcher
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'rspec'
|
2
|
+
|
3
|
+
RSpec::Matchers.define(:have_attribute) do |attribute, args|
|
4
|
+
options = args.nil? ? {} : args.dup
|
5
|
+
options[:facet] ||= false
|
6
|
+
|
7
|
+
match do |model|
|
8
|
+
if model.sphinx_indexes?
|
9
|
+
model.class.define_indexes
|
10
|
+
model.sphinx_indexes.first.attributes.select {|a|
|
11
|
+
a.columns.first.__name == attribute &&
|
12
|
+
a.alias == options[:as] &&
|
13
|
+
(a.faceted.nil? ? true : a.faceted == options[:facet])
|
14
|
+
}.count == 1
|
15
|
+
else
|
16
|
+
false
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
failure_message_for_should do |actual|
|
21
|
+
"expected #{actual} to have an attribute for #{attribute.to_sym} with params #{args}"
|
22
|
+
end
|
23
|
+
|
24
|
+
failure_message_for_should_not do |actual|
|
25
|
+
"expected #{actual} not to define an attribute for #{attribute.to_sym} with params #{args}"
|
26
|
+
end
|
27
|
+
|
28
|
+
description do
|
29
|
+
"have a search attribute for #{options[:as] || attribute}"
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'rspec'
|
2
|
+
|
3
|
+
RSpec::Matchers.define(:index) do |field, args|
|
4
|
+
options = args.nil? ? {} : args.dup
|
5
|
+
options[:from] = Array(options[:from])
|
6
|
+
options[:sortable] ||= false
|
7
|
+
options[:facet] ||= false
|
8
|
+
|
9
|
+
match do |model|
|
10
|
+
if model.sphinx_indexes?
|
11
|
+
model.class.define_indexes
|
12
|
+
model.sphinx_indexes.first.fields.select {|f|
|
13
|
+
f.columns.first.__name == field &&
|
14
|
+
f.columns.first.__stack == options[:from] &&
|
15
|
+
f.alias == options[:as] &&
|
16
|
+
f.sortable == options[:sortable] &&
|
17
|
+
(f.faceted.nil? ? true : f.faceted == options[:facet])
|
18
|
+
}.count == 1
|
19
|
+
else
|
20
|
+
false
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
failure_message_for_should do |actual|
|
25
|
+
"expected #{actual} to define an index for #{field.to_sym} with params #{args}"
|
26
|
+
end
|
27
|
+
|
28
|
+
failure_message_for_should_not do |actual|
|
29
|
+
"expected #{actual} not to define an index for #{field.to_sym} with params #{args}"
|
30
|
+
end
|
31
|
+
|
32
|
+
description do
|
33
|
+
"have an index field for #{options[:as] || field}"
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |s|
|
5
|
+
s.name = "thinking-sphinx-rspec-matchers"
|
6
|
+
s.version = "0.0.2"
|
7
|
+
s.authors = ["Alejandro Andres"]
|
8
|
+
s.email = ["fuzzy.alej@gmail.com"]
|
9
|
+
s.homepage = "http://alejandroandres.com/"
|
10
|
+
s.summary = %q{Rspec2 matchers for Thinking Sphinx}
|
11
|
+
s.description = %q{Rspec2 matchers for Thinking Sphinx}
|
12
|
+
|
13
|
+
s.rubyforge_project = "thinking-sphinx-rspec-matchers"
|
14
|
+
|
15
|
+
s.files = `git ls-files`.split("\n")
|
16
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
17
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
18
|
+
s.require_paths = ["lib"]
|
19
|
+
|
20
|
+
# specify any dependencies here; for example:
|
21
|
+
s.add_development_dependency "rake"
|
22
|
+
s.add_development_dependency "rspec"
|
23
|
+
s.add_runtime_dependency "rspec"
|
24
|
+
end
|
metadata
ADDED
@@ -0,0 +1,86 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: thinking-sphinx-rspec-matchers
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.2
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Alejandro Andres
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2011-11-29 00:00:00.000000000Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rake
|
16
|
+
requirement: &17539740 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *17539740
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: rspec
|
27
|
+
requirement: &17539300 !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
29
|
+
requirements:
|
30
|
+
- - ! '>='
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0'
|
33
|
+
type: :development
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: *17539300
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: rspec
|
38
|
+
requirement: &17538880 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ! '>='
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: '0'
|
44
|
+
type: :runtime
|
45
|
+
prerelease: false
|
46
|
+
version_requirements: *17538880
|
47
|
+
description: Rspec2 matchers for Thinking Sphinx
|
48
|
+
email:
|
49
|
+
- fuzzy.alej@gmail.com
|
50
|
+
executables: []
|
51
|
+
extensions: []
|
52
|
+
extra_rdoc_files: []
|
53
|
+
files:
|
54
|
+
- .gitignore
|
55
|
+
- Gemfile
|
56
|
+
- README.md
|
57
|
+
- Rakefile
|
58
|
+
- lib/thinking-sphinx-rspec-matchers.rb
|
59
|
+
- lib/thinking-sphinx-rspec-matchers/attribute_matcher.rb
|
60
|
+
- lib/thinking-sphinx-rspec-matchers/field_matcher.rb
|
61
|
+
- thinking-sphinx-rspec-matchers.gemspec
|
62
|
+
homepage: http://alejandroandres.com/
|
63
|
+
licenses: []
|
64
|
+
post_install_message:
|
65
|
+
rdoc_options: []
|
66
|
+
require_paths:
|
67
|
+
- lib
|
68
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
69
|
+
none: false
|
70
|
+
requirements:
|
71
|
+
- - ! '>='
|
72
|
+
- !ruby/object:Gem::Version
|
73
|
+
version: '0'
|
74
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
75
|
+
none: false
|
76
|
+
requirements:
|
77
|
+
- - ! '>='
|
78
|
+
- !ruby/object:Gem::Version
|
79
|
+
version: '0'
|
80
|
+
requirements: []
|
81
|
+
rubyforge_project: thinking-sphinx-rspec-matchers
|
82
|
+
rubygems_version: 1.8.11
|
83
|
+
signing_key:
|
84
|
+
specification_version: 3
|
85
|
+
summary: Rspec2 matchers for Thinking Sphinx
|
86
|
+
test_files: []
|