wally 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,43 @@
1
+ module Wally
2
+ class SearchFeatures
3
+ def find(query)
4
+ results = []
5
+ ListsFeatures.features.each do |feature|
6
+ result = SearchResult.new(feature)
7
+
8
+ if feature["tags"]
9
+ feature["tags"].each do |tag|
10
+ if tag["name"].downcase.include? query[:query].downcase
11
+ result.matched_feature = feature
12
+ end
13
+ end
14
+ end
15
+
16
+ if feature["name"].downcase.include? query[:query].downcase
17
+ result.matched_feature = feature
18
+ end
19
+
20
+ if feature["elements"]
21
+ result.matched_scenarios = feature["elements"].select do |element|
22
+ if element["name"].downcase.include? query[:query].downcase
23
+ true
24
+ elsif element["steps"]
25
+ element["steps"].any? do |step|
26
+ step["name"].downcase.include? query[:query].downcase
27
+ end
28
+ elsif element["tags"]
29
+ element["tags"].any? do |tag|
30
+ tag["name"].downcase.include? query[:query].downcase
31
+ end
32
+ end
33
+ end
34
+ end
35
+
36
+ if result.matches?
37
+ results << result
38
+ end
39
+ end
40
+ results
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,16 @@
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
@@ -0,0 +1,3 @@
1
+ module Wally
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,11 @@
1
+ - if @feature["description"]
2
+ %h2 Scenarios
3
+ %section{:class=>"scenarios"}
4
+ %section{:class => 'feature'}
5
+ :markdown
6
+ #{@feature["description"]}
7
+ %ul
8
+ - @scenario_urls.keys.sort.each do |name|
9
+ %li
10
+ %a{:href => @scenario_urls[name]}
11
+ = name
File without changes
@@ -0,0 +1,31 @@
1
+ !!! 5
2
+ %html
3
+ %head
4
+ %title Wally
5
+ %link{:rel => 'stylesheet', :type => 'text/css', :href => '/bootstrap.min.css'}
6
+ %meta{:'http-equiv' => 'X-UA-Compatible', :content => 'IE=edge,chrome=1'}
7
+ %meta{:name => 'viewport', :content => 'width=device-width; initial-scale=1.0; maximum-scale=1.0; user-scalable=0;'}
8
+ %body
9
+ %div.container-fluid
10
+ %div.logo
11
+ %h1
12
+ %a{:href => "/"} Wally
13
+ %div.search-bar
14
+ %form{:method => "GET", :action => "/search", :id => "search"}
15
+ %input{:type => "text", :id => "q", :name => "q", :placeholder => 'text, @tags etc.', :value => @q }
16
+ %input.btn{:type => "submit", :id => "search", :value => "Search"}
17
+ %div.container-fluid
18
+ %div.sidebar
19
+ %h2
20
+ Features
21
+ %ul
22
+ - @features.each do |feature|
23
+ %li
24
+ %a{:href => "/features/#{feature["id"]}"}
25
+ = feature["name"]
26
+ - if feature["tags"]
27
+ - feature["tags"].each do |tag|
28
+ %span.label.notice
29
+ = tag["name"]
30
+ %div.content
31
+ = yield
@@ -0,0 +1,25 @@
1
+ %h2
2
+ = @scenario["keyword"] + ": " + @scenario["name"]
3
+ %span.label.notice
4
+ - if @scenario["tags"]
5
+ - @scenario["tags"].each do |tag|
6
+ %a{:href => "/search?q=#{tag["name"]}"}
7
+ = tag["name"]
8
+ - if @background
9
+ %h3
10
+ = @background["keyword"] + ":"
11
+ - if @scenario["tags"]
12
+ - @scenario["tags"].each do |tag|
13
+ %span.label.notice
14
+ %a{:href => "/search?q=#{tag["name"]}"}
15
+ = tag["name"]
16
+ - @background["steps"].each do |step|
17
+ = step["keyword"] + step["name"]
18
+ %br
19
+ - if @scenario["steps"]
20
+ %p
21
+ - @scenario["steps"].each do |step|
22
+ = step["keyword"] + step["name"] + '<br/>'
23
+ - else
24
+ %p{:class => 'nosteps'}
25
+ = "Where's Wally? This scenario has no steps!?"
@@ -0,0 +1,15 @@
1
+ %h2
2
+ = "Search for '#{params[:q]}'"
3
+ - if params[:q]
4
+ %ul
5
+ - @search_results.each do |search_result|
6
+ %li
7
+ %a{:href => "/features/#{search_result.feature["id"]}"}
8
+ = search_result.feature["name"]
9
+ %ul
10
+ - search_result.matched_scenarios.each do |scenario|
11
+ %li
12
+ %a{:href => "/features/#{scenario["id"].gsub(";", "/scenario/")}"}
13
+ = scenario["name"]
14
+ - else
15
+ %p Where's Wally? This search returned no results.
@@ -0,0 +1,6 @@
1
+ $:.unshift(File.join(File.dirname(__FILE__), "../lib"))
2
+ ENV['RACK_ENV'] = 'test'
3
+ require "rack/test"
4
+ require "fakefs/spec_helpers"
5
+ require "fileutils"
6
+ require "wally"
@@ -0,0 +1,30 @@
1
+ require File.join(File.dirname(__FILE__), "..", "spec_helper")
2
+ require 'fileutils'
3
+
4
+ module Wally
5
+ describe ListsFeatures do
6
+ before do
7
+ FileUtils.mkdir_p "application-features"
8
+ end
9
+
10
+ after do
11
+ FileUtils.rm_rf "application-features"
12
+ end
13
+
14
+ it "returns a list of alphabeticaly ordered features" do
15
+ File.open("application-features/1-sample.feature", "w") do |file|
16
+ file.write "Feature: Zorro"
17
+ end
18
+ File.open("application-features/2-sample.feature", "w") do |file|
19
+ file.write "Feature: Malgor"
20
+ end
21
+ File.open("application-features/3-sample.feature", "w") do |file|
22
+ file.write "Feature: Adrian"
23
+ end
24
+ ListsFeatures.features.size.should == 3
25
+ ListsFeatures.features[0]["name"].should == "Adrian"
26
+ ListsFeatures.features[1]["name"].should == "Malgor"
27
+ ListsFeatures.features[2]["name"].should == "Zorro"
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,82 @@
1
+ require File.join(File.dirname(__FILE__), "..", "spec_helper")
2
+
3
+ module Wally
4
+ describe SearchFeatures do
5
+ before do
6
+ FileUtils.mkdir "application-features"
7
+ end
8
+
9
+ after do
10
+ FileUtils.rm_rf "application-features"
11
+ end
12
+
13
+ def write_feature(name, contents)
14
+ File.open("application-features/#{name}", "w") do |file|
15
+ file.write(contents)
16
+ end
17
+ end
18
+
19
+ it "finds features containing text" do
20
+ write_feature("sample1.feature", "Feature: Bla")
21
+ write_feature("sample2.feature", "Feature: Meh")
22
+
23
+ results = SearchFeatures.new.find(:query => "Meh")
24
+ results.size.should == 1
25
+ results.first.matched_feature["name"].should == "Meh"
26
+ end
27
+
28
+ it "stores the original feature in the result" do
29
+ write_feature("sample1.feature", "Feature: Bla")
30
+ results = SearchFeatures.new.find(:query => "Bla")
31
+ results.first.feature["name"].should == "Bla"
32
+ end
33
+
34
+ it "finds features containing text with any case" do
35
+ write_feature("sample1.feature", "Feature: Bla")
36
+ write_feature("sample2.feature", "Feature: Meh")
37
+
38
+ results = SearchFeatures.new.find(:query => "MEH")
39
+ results.size.should == 1
40
+ results.first.matched_feature["name"].should == "Meh"
41
+ end
42
+
43
+ context "feature with multiple scenarios" do
44
+ before do
45
+ contents = <<-CONTENTS
46
+ Feature: Sample Feature
47
+ Scenario: Sample Scenario
48
+ Scenario: Matched Scenario
49
+ Given I do some things
50
+ Scenario: Another Scenario
51
+ CONTENTS
52
+ write_feature("sample1.feature", contents)
53
+ end
54
+
55
+ it "finds scenarios containing text" do
56
+ results = SearchFeatures.new.find(:query => "Matched SCENARIO")
57
+ results.first.matched_scenarios.size.should == 1
58
+ results.first.matched_scenarios.first["name"].should == "Matched Scenario"
59
+ end
60
+
61
+ it "finds scenario steps" do
62
+ results = SearchFeatures.new.find(:query => "I DO SOME THINGS")
63
+ results.first.matched_scenarios.size.should == 1
64
+ results.first.matched_scenarios.first["name"].should == "Matched Scenario"
65
+ end
66
+ end
67
+
68
+ context "feature with tags" do
69
+ it "finds features by tag" do
70
+ write_feature("example-feature.feature", "@tag_name\nFeature: Example Feature")
71
+ results = SearchFeatures.new.find(:query => "@tag_NAME")
72
+ results.first.matched_feature["name"].should == "Example Feature"
73
+ end
74
+
75
+ it "finds scenarios by tag" do
76
+ write_feature("example-feature.feature", "Feature: Example Feature\n@scenario_tag\nScenario: Example Scenario")
77
+ results = SearchFeatures.new.find(:query => "@scenario_TAG")
78
+ results.first.matched_scenarios.first["name"].should == "Example Scenario"
79
+ end
80
+ end
81
+ end
82
+ end
@@ -0,0 +1,25 @@
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
@@ -0,0 +1,29 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "wally/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "wally"
7
+ s.version = Wally::VERSION
8
+ s.authors = ["Andrew Vos"]
9
+ s.email = ["andrew.vos@gmail.com"]
10
+ s.homepage = ""
11
+ s.summary = %q{}
12
+ s.description = %q{}
13
+
14
+ s.rubyforge_project = "wally"
15
+
16
+ s.files = `git ls-files`.split("\n")
17
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
+ s.require_paths = ["lib"]
20
+
21
+ s.add_runtime_dependency "sinatra"
22
+ s.add_runtime_dependency "haml"
23
+ s.add_runtime_dependency "rdiscount"
24
+
25
+ s.add_development_dependency "cucumber"
26
+ s.add_development_dependency "capybara"
27
+ s.add_development_dependency "rspec"
28
+ s.add_development_dependency "fakefs"
29
+ end
metadata ADDED
@@ -0,0 +1,162 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: wally
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Andrew Vos
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2011-11-22 00:00:00.000000000Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: sinatra
16
+ requirement: &70189867702400 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *70189867702400
25
+ - !ruby/object:Gem::Dependency
26
+ name: haml
27
+ requirement: &70189867756760 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: *70189867756760
36
+ - !ruby/object:Gem::Dependency
37
+ name: rdiscount
38
+ requirement: &70189867884180 !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: *70189867884180
47
+ - !ruby/object:Gem::Dependency
48
+ name: cucumber
49
+ requirement: &70189867952160 !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ type: :development
56
+ prerelease: false
57
+ version_requirements: *70189867952160
58
+ - !ruby/object:Gem::Dependency
59
+ name: capybara
60
+ requirement: &70189868015860 !ruby/object:Gem::Requirement
61
+ none: false
62
+ requirements:
63
+ - - ! '>='
64
+ - !ruby/object:Gem::Version
65
+ version: '0'
66
+ type: :development
67
+ prerelease: false
68
+ version_requirements: *70189868015860
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: &70189868100060 !ruby/object:Gem::Requirement
72
+ none: false
73
+ requirements:
74
+ - - ! '>='
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ type: :development
78
+ prerelease: false
79
+ version_requirements: *70189868100060
80
+ - !ruby/object:Gem::Dependency
81
+ name: fakefs
82
+ requirement: &70189868197940 !ruby/object:Gem::Requirement
83
+ none: false
84
+ requirements:
85
+ - - ! '>='
86
+ - !ruby/object:Gem::Version
87
+ version: '0'
88
+ type: :development
89
+ prerelease: false
90
+ version_requirements: *70189868197940
91
+ description: ''
92
+ email:
93
+ - andrew.vos@gmail.com
94
+ executables: []
95
+ extensions: []
96
+ extra_rdoc_files: []
97
+ files:
98
+ - .gitignore
99
+ - Gemfile
100
+ - Gemfile.lock
101
+ - LICENSE
102
+ - README.md
103
+ - Rakefile
104
+ - config.ru
105
+ - features/browse_features.feature
106
+ - features/search_features.feature
107
+ - features/step_definitions/browse_features_steps.rb
108
+ - features/step_definitions/search_features_steps.rb
109
+ - features/step_definitions/steps.rb
110
+ - features/support/env.rb
111
+ - lib/wally.rb
112
+ - lib/wally/application.rb
113
+ - lib/wally/lists_features.rb
114
+ - lib/wally/public/bootstrap.min.css
115
+ - lib/wally/search_features.rb
116
+ - lib/wally/search_result.rb
117
+ - lib/wally/version.rb
118
+ - lib/wally/views/feature.haml
119
+ - lib/wally/views/index.haml
120
+ - lib/wally/views/layout.haml
121
+ - lib/wally/views/scenario.haml
122
+ - lib/wally/views/search.haml
123
+ - spec/spec_helper.rb
124
+ - spec/wally/lists_features_spec.rb
125
+ - spec/wally/search_features_spec.rb
126
+ - spec/wally/search_result_spec.rb
127
+ - wally.gemspec
128
+ homepage: ''
129
+ licenses: []
130
+ post_install_message:
131
+ rdoc_options: []
132
+ require_paths:
133
+ - lib
134
+ required_ruby_version: !ruby/object:Gem::Requirement
135
+ none: false
136
+ requirements:
137
+ - - ! '>='
138
+ - !ruby/object:Gem::Version
139
+ version: '0'
140
+ required_rubygems_version: !ruby/object:Gem::Requirement
141
+ none: false
142
+ requirements:
143
+ - - ! '>='
144
+ - !ruby/object:Gem::Version
145
+ version: '0'
146
+ requirements: []
147
+ rubyforge_project: wally
148
+ rubygems_version: 1.8.10
149
+ signing_key:
150
+ specification_version: 3
151
+ summary: ''
152
+ test_files:
153
+ - features/browse_features.feature
154
+ - features/search_features.feature
155
+ - features/step_definitions/browse_features_steps.rb
156
+ - features/step_definitions/search_features_steps.rb
157
+ - features/step_definitions/steps.rb
158
+ - features/support/env.rb
159
+ - spec/spec_helper.rb
160
+ - spec/wally/lists_features_spec.rb
161
+ - spec/wally/search_features_spec.rb
162
+ - spec/wally/search_result_spec.rb