wally 0.0.5 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
@@ -39,3 +39,13 @@ Feature: Search features
39
39
  And I am on the search page
40
40
  When I search for "I do something"
41
41
  Then I should see a link to "Sample Scenario" with the url "/features/sample-feature/scenario/sample-scenario"
42
+
43
+ Scenario: Search suggests other searches
44
+ Given a feature file named "sample.feature" with the contents:
45
+ """
46
+ Feature: Batman
47
+ """
48
+ And I am on the search page
49
+ When I search for "btman"
50
+ Then I should see "Did you mean"
51
+ And I should see a link to "Batman" with the url "/search?q=Batman"
@@ -1,3 +1,5 @@
1
+ require "komainu"
2
+
1
3
  module Wally
2
4
  class SearchFeatures
3
5
  def initialize lists_features
@@ -5,43 +7,38 @@ module Wally
5
7
  end
6
8
 
7
9
  def find(query)
8
- results = []
9
- @lists_features.features.each do |feature|
10
- result = SearchResult.new(feature)
10
+ searchables = []
11
11
 
12
+ @lists_features.features.each do |feature|
13
+ feature_text = feature["name"]
12
14
  if feature["tags"]
13
- feature["tags"].each do |tag|
14
- if tag["name"].downcase.include? query[:query].downcase
15
- result.matched_feature = feature
16
- end
17
- end
18
- end
19
-
20
- if feature["name"].downcase.include? query[:query].downcase
21
- result.matched_feature = feature
15
+ feature_text += " " + feature["tags"].map { |tag| tag["name"] }.join(" ")
22
16
  end
17
+ feature_data = OpenStruct.new
18
+ feature_data.feature = feature
19
+ feature_data.text = feature_text
20
+ searchables << feature_data
23
21
 
24
22
  if feature["elements"]
25
- result.matched_scenarios = feature["elements"].select do |element|
26
- if element["name"].downcase.include? query[:query].downcase
27
- true
28
- elsif element["steps"]
29
- element["steps"].any? do |step|
30
- step["name"].downcase.include? query[:query].downcase
31
- end
32
- elsif element["tags"]
33
- element["tags"].any? do |tag|
34
- tag["name"].downcase.include? query[:query].downcase
35
- end
23
+ feature["elements"].each do |element|
24
+ element_text = [element["name"]]
25
+ if element["steps"]
26
+ element_text << element["steps"].map { |s| s["name"] }
27
+ end
28
+ if element["tags"]
29
+ element_text << element["tags"].map { |t| t["name"] }
36
30
  end
31
+ scenario_data = OpenStruct.new
32
+ scenario_data.feature = feature
33
+ scenario_data.scenario = element
34
+ scenario_data.text = element_text.join(" ")
35
+ searchables << scenario_data
37
36
  end
38
37
  end
39
-
40
- if result.matches?
41
- results << result
42
- end
43
38
  end
44
- results
39
+
40
+ searches_text = Komainu::SearchesText.new(searchables)
41
+ searches_text.search(query[:query])
45
42
  end
46
43
  end
47
44
  end
data/lib/wally/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Wally
2
- VERSION = "0.0.5"
2
+ VERSION = "0.0.6"
3
3
  end
@@ -1,15 +1,19 @@
1
- %h2
2
- = "Search for '#{params[:q]}'"
3
1
  - if params[:q]
2
+ %h2
3
+ = "Search for '#{params[:q]}'"
4
+ %p
5
+ Did you mean
6
+ %a{:href => "/search?q=#{@search_results.suggestion}"}
7
+ = @search_results.suggestion
4
8
  %ul
5
- - @search_results.each do |search_result|
9
+ - @search_results.items.each do |search_result|
6
10
  %li
7
11
  %a{:href => "/features/#{search_result.feature["id"]}"}
8
12
  = search_result.feature["name"]
9
13
  %ul
10
- - search_result.matched_scenarios.each do |scenario|
14
+ - if search_result.scenario
11
15
  %li
12
- %a{:href => "/features/#{scenario["id"].gsub(";", "/scenario/")}"}
13
- = scenario["name"]
16
+ %a{:href => "/features/#{search_result.scenario["id"].gsub(";", "/scenario/")}"}
17
+ = search_result.scenario["name"]
14
18
  - else
15
19
  %p Where's Wally? This search returned no results.
data/lib/wally.rb CHANGED
@@ -7,4 +7,3 @@ require "wally/version"
7
7
  require "wally/application"
8
8
  require "wally/lists_features"
9
9
  require "wally/search_features"
10
- require "wally/search_result"
@@ -25,23 +25,14 @@ module Wally
25
25
  write_feature("sample2.feature", "Feature: Meh")
26
26
 
27
27
  results = SearchFeatures.new(lists_features).find(:query => "Meh")
28
- results.size.should == 1
29
- results.first.matched_feature["name"].should == "Meh"
28
+ results.items.size.should == 1
29
+ results.items.first.feature["name"].should == "Meh"
30
30
  end
31
31
 
32
- it "stores the original feature in the result" do
33
- write_feature("sample1.feature", "Feature: Bla")
34
- results = SearchFeatures.new(lists_features).find(:query => "Bla")
35
- results.first.feature["name"].should == "Bla"
36
- end
37
-
38
- it "finds features containing text with any case" do
39
- write_feature("sample1.feature", "Feature: Bla")
40
- write_feature("sample2.feature", "Feature: Meh")
41
-
42
- results = SearchFeatures.new(lists_features).find(:query => "MEH")
43
- results.size.should == 1
44
- results.first.matched_feature["name"].should == "Meh"
32
+ it "has a suggestion" do
33
+ write_feature("sample1.feature", "Feature: Monkeys")
34
+ results = SearchFeatures.new(lists_features).find(:query => "mnkeys")
35
+ results.suggestion.should == "Monkeys"
45
36
  end
46
37
 
47
38
  context "feature with multiple scenarios" do
@@ -50,22 +41,22 @@ module Wally
50
41
  Feature: Sample Feature
51
42
  Scenario: Sample Scenario
52
43
  Scenario: Matched Scenario
53
- Given I do some things
44
+ Given I eat some doughnuts
54
45
  Scenario: Another Scenario
55
46
  CONTENTS
56
47
  write_feature("sample1.feature", contents)
57
48
  end
58
49
 
59
50
  it "finds scenarios containing text" do
60
- results = SearchFeatures.new(lists_features).find(:query => "Matched SCENARIO")
61
- results.first.matched_scenarios.size.should == 1
62
- results.first.matched_scenarios.first["name"].should == "Matched Scenario"
51
+ results = SearchFeatures.new(lists_features).find(:query => "MATCHED")
52
+ results.items.size.should == 1
53
+ results.items.first.scenario["name"].should == "Matched Scenario"
63
54
  end
64
55
 
65
56
  it "finds scenario steps" do
66
- results = SearchFeatures.new(lists_features).find(:query => "I DO SOME THINGS")
67
- results.first.matched_scenarios.size.should == 1
68
- results.first.matched_scenarios.first["name"].should == "Matched Scenario"
57
+ results = SearchFeatures.new(lists_features).find(:query => "DOUGHNUTS")
58
+ results.items.size.should == 1
59
+ results.items.first.scenario["name"].should == "Matched Scenario"
69
60
  end
70
61
  end
71
62
 
@@ -73,13 +64,13 @@ module Wally
73
64
  it "finds features by tag" do
74
65
  write_feature("example-feature.feature", "@tag_name\nFeature: Example Feature")
75
66
  results = SearchFeatures.new(lists_features).find(:query => "@tag_NAME")
76
- results.first.matched_feature["name"].should == "Example Feature"
67
+ results.items.first.feature["name"].should == "Example Feature"
77
68
  end
78
69
 
79
70
  it "finds scenarios by tag" do
80
71
  write_feature("example-feature.feature", "Feature: Example Feature\n@scenario_tag\nScenario: Example Scenario")
81
72
  results = SearchFeatures.new(lists_features).find(:query => "@scenario_TAG")
82
- results.first.matched_scenarios.first["name"].should == "Example Scenario"
73
+ results.items.first.scenario["name"].should == "Example Scenario"
83
74
  end
84
75
  end
85
76
  end
data/wally.gemspec CHANGED
@@ -22,6 +22,7 @@ Gem::Specification.new do |s|
22
22
  s.add_runtime_dependency "haml"
23
23
  s.add_runtime_dependency "rdiscount"
24
24
  s.add_runtime_dependency "gherkin"
25
+ s.add_runtime_dependency "komainu"
25
26
 
26
27
  s.add_development_dependency "cucumber"
27
28
  s.add_development_dependency "capybara"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: wally
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.6
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-11-22 00:00:00.000000000Z
12
+ date: 2011-11-23 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: sinatra
16
- requirement: &70185102349080 !ruby/object:Gem::Requirement
16
+ requirement: &70328576388100 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70185102349080
24
+ version_requirements: *70328576388100
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: haml
27
- requirement: &70185102348660 !ruby/object:Gem::Requirement
27
+ requirement: &70328576387400 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '0'
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *70185102348660
35
+ version_requirements: *70328576387400
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: rdiscount
38
- requirement: &70185102348240 !ruby/object:Gem::Requirement
38
+ requirement: &70328576386660 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: '0'
44
44
  type: :runtime
45
45
  prerelease: false
46
- version_requirements: *70185102348240
46
+ version_requirements: *70328576386660
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: gherkin
49
- requirement: &70185102347820 !ruby/object:Gem::Requirement
49
+ requirement: &70328576386240 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ! '>='
@@ -54,10 +54,21 @@ dependencies:
54
54
  version: '0'
55
55
  type: :runtime
56
56
  prerelease: false
57
- version_requirements: *70185102347820
57
+ version_requirements: *70328576386240
58
+ - !ruby/object:Gem::Dependency
59
+ name: komainu
60
+ requirement: &70328576385760 !ruby/object:Gem::Requirement
61
+ none: false
62
+ requirements:
63
+ - - ! '>='
64
+ - !ruby/object:Gem::Version
65
+ version: '0'
66
+ type: :runtime
67
+ prerelease: false
68
+ version_requirements: *70328576385760
58
69
  - !ruby/object:Gem::Dependency
59
70
  name: cucumber
60
- requirement: &70185102347400 !ruby/object:Gem::Requirement
71
+ requirement: &70328576385100 !ruby/object:Gem::Requirement
61
72
  none: false
62
73
  requirements:
63
74
  - - ! '>='
@@ -65,10 +76,10 @@ dependencies:
65
76
  version: '0'
66
77
  type: :development
67
78
  prerelease: false
68
- version_requirements: *70185102347400
79
+ version_requirements: *70328576385100
69
80
  - !ruby/object:Gem::Dependency
70
81
  name: capybara
71
- requirement: &70185102346980 !ruby/object:Gem::Requirement
82
+ requirement: &70328576384380 !ruby/object:Gem::Requirement
72
83
  none: false
73
84
  requirements:
74
85
  - - ! '>='
@@ -76,10 +87,10 @@ dependencies:
76
87
  version: '0'
77
88
  type: :development
78
89
  prerelease: false
79
- version_requirements: *70185102346980
90
+ version_requirements: *70328576384380
80
91
  - !ruby/object:Gem::Dependency
81
92
  name: rspec
82
- requirement: &70185102346560 !ruby/object:Gem::Requirement
93
+ requirement: &70328576383780 !ruby/object:Gem::Requirement
83
94
  none: false
84
95
  requirements:
85
96
  - - ! '>='
@@ -87,10 +98,10 @@ dependencies:
87
98
  version: '0'
88
99
  type: :development
89
100
  prerelease: false
90
- version_requirements: *70185102346560
101
+ version_requirements: *70328576383780
91
102
  - !ruby/object:Gem::Dependency
92
103
  name: fakefs
93
- requirement: &70185102337160 !ruby/object:Gem::Requirement
104
+ requirement: &70328576383160 !ruby/object:Gem::Requirement
94
105
  none: false
95
106
  requirements:
96
107
  - - ! '>='
@@ -98,7 +109,7 @@ dependencies:
98
109
  version: '0'
99
110
  type: :development
100
111
  prerelease: false
101
- version_requirements: *70185102337160
112
+ version_requirements: *70328576383160
102
113
  description: ''
103
114
  email:
104
115
  - andrew.vos@gmail.com
@@ -126,7 +137,6 @@ files:
126
137
  - lib/wally/lists_features.rb
127
138
  - lib/wally/public/bootstrap.min.css
128
139
  - lib/wally/search_features.rb
129
- - lib/wally/search_result.rb
130
140
  - lib/wally/version.rb
131
141
  - lib/wally/views/feature.haml
132
142
  - lib/wally/views/index.haml
@@ -136,7 +146,6 @@ files:
136
146
  - spec/spec_helper.rb
137
147
  - spec/wally/lists_features_spec.rb
138
148
  - spec/wally/search_features_spec.rb
139
- - spec/wally/search_result_spec.rb
140
149
  - wally.gemspec
141
150
  homepage: ''
142
151
  licenses: []
@@ -172,4 +181,3 @@ test_files:
172
181
  - spec/spec_helper.rb
173
182
  - spec/wally/lists_features_spec.rb
174
183
  - spec/wally/search_features_spec.rb
175
- - spec/wally/search_result_spec.rb
@@ -1,16 +0,0 @@
1
- module Wally
2
- class SearchResult
3
- attr_accessor :feature, :matched_feature, :matched_scenarios
4
-
5
- def initialize feature
6
- @feature = feature
7
- @matched_scenarios = []
8
- end
9
-
10
- def matches?
11
- return true if matched_feature
12
- return true unless matched_scenarios.empty?
13
- false
14
- end
15
- end
16
- end
@@ -1,25 +0,0 @@
1
- require File.join(File.dirname(__FILE__), "..", "spec_helper")
2
-
3
- module Wally
4
- describe SearchResult do
5
- subject { SearchResult.new(nil) }
6
-
7
- it "knows when there are no results" do
8
- subject.matches?.should == false
9
- end
10
-
11
- it "contains no matched scenarios" do
12
- subject.matched_scenarios.should == []
13
- end
14
-
15
- it "knows when there is a feature match" do
16
- subject.matched_feature = {}
17
- subject.matches?.should == true
18
- end
19
-
20
- it "knows when there are scenario matches" do
21
- subject.matched_scenarios = [{}]
22
- subject.matches?.should == true
23
- end
24
- end
25
- end