Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Turned wally into a gem

  • Loading branch information...
commit 1f833afe76ed94d03d9a33cc03bdeeca64162d90 1 parent 2da32b1
@AndrewVos AndrewVos authored
View
4 .gitignore
@@ -1 +1,5 @@
*.swp
+*.gem
+.bundle
+Gemfile.lock
+pkg/*
View
12 Gemfile
@@ -1,8 +1,4 @@
-source :rubygems
-gem "sinatra"
-gem "cucumber"
-gem "capybara"
-gem "rspec"
-gem "haml"
-gem "fakefs"
-gem "rdiscount"
+source "http://rubygems.org"
+
+# Specify your gem's dependencies in wally.gemspec
+gemspec
View
12 Gemfile.lock
@@ -1,3 +1,11 @@
+PATH
+ remote: .
+ specs:
+ wally (0.0.1)
+ haml
+ rdiscount
+ sinatra
+
GEM
remote: http://rubygems.org/
specs:
@@ -63,7 +71,5 @@ DEPENDENCIES
capybara
cucumber
fakefs
- haml
- rdiscount
rspec
- sinatra
+ wally!
View
1  Rakefile
@@ -0,0 +1 @@
+require "bundler/gem_tasks"
View
3  features/support/env.rb
@@ -1,12 +1,11 @@
$:.unshift(File.join(File.dirname(__FILE__), "../../lib"))
ENV['RACK_ENV'] = 'test'
+require "wally"
require "fileutils"
-require "application"
require "capybara/cucumber"
require "rspec"
require "fakefs/spec_helpers"
-
Capybara.app = Sinatra::Application
FEATURE_PATH = File.join(File.dirname(__FILE__), "../../application-features")
View
19 lib/conf.yml
@@ -1,19 +0,0 @@
-# Our device test suite
-devices:
- - Geoff
- - Len
- - Andy
- - Kenny
- - Roxy
- - Kylie
- - Bob
- - Adrian
- - Huey
- - Midge
- - Don
-
-# A list of substitutions to perform while rendering the step definitions.
-substitutions:
- frontpage: '<a href="https://www.int.bbc.co.uk/news">frontpage</a>'
- 'home page': '<a href="https://www.int.bbc.co.uk/news">homepage</a>'
- 'Live Events': '<a href="https://www.int.bbc.co.uk/news/fakeLiveEvent">live event</a>'
View
34 lib/lists_features.rb
@@ -1,34 +0,0 @@
-require 'gherkin/formatter/json_formatter'
-require 'gherkin/parser/parser'
-
-module Gherkin::Formatter
- class JSONFormatter
- def to_hash
- @feature_hash
- end
- end
-end
-
-class ListsFeatures
- class << self
- def features
- features = []
- Dir.glob("application-features/*.feature").each do |path|
- uri = "/features/#{path.gsub("application-features/", "")}"
- features << parse_gherkin(uri, File.read(path))
- end
- features.sort {|a,b| a["name"] <=> b["name"]}
- end
-
- private
-
- def parse_gherkin(uri, text)
- io = StringIO.new
- formatter = Gherkin::Formatter::JSONFormatter.new(io)
- parser = Gherkin::Parser::Parser.new(formatter, false, 'root')
- parser.parse(text, uri, 0)
- hash = formatter.to_hash
- hash
- end
- end
-end
View
44 lib/search_features.rb
@@ -1,44 +0,0 @@
-require "lists_features"
-require "search_result"
-
-class SearchFeatures
- def find(query)
- results = []
- ListsFeatures.features.each do |feature|
- result = SearchResult.new(feature)
-
- if feature["tags"]
- feature["tags"].each do |tag|
- if tag["name"].downcase.include? query[:query].downcase
- result.matched_feature = feature
- end
- end
- end
-
- if feature["name"].downcase.include? query[:query].downcase
- result.matched_feature = feature
- end
-
- if feature["elements"]
- result.matched_scenarios = feature["elements"].select do |element|
- if element["name"].downcase.include? query[:query].downcase
- true
- elsif element["steps"]
- element["steps"].any? do |step|
- step["name"].downcase.include? query[:query].downcase
- end
- elsif element["tags"]
- element["tags"].any? do |tag|
- tag["name"].downcase.include? query[:query].downcase
- end
- end
- end
- end
-
- if result.matches?
- results << result
- end
- end
- results
- end
-end
View
14 lib/search_result.rb
@@ -1,14 +0,0 @@
-class SearchResult
- attr_accessor :feature, :matched_feature, :matched_scenarios
-
- def initialize feature
- @feature = feature
- @matched_scenarios = []
- end
-
- def matches?
- return true if matched_feature
- return true unless matched_scenarios.empty?
- false
- end
-end
View
6 lib/wally.rb
@@ -0,0 +1,6 @@
+$:.unshift(File.expand_path(File.dirname(__FILE__)))
+require "wally/version"
+require "wally/application"
+require "wally/lists_features"
+require "wally/search_features"
+require "wally/search_result"
View
13 lib/application.rb → lib/wally/application.rb
@@ -1,26 +1,23 @@
$:.unshift(File.join(File.dirname(__FILE__)))
-
require 'sinatra'
require 'haml'
require 'rdiscount'
-require 'lists_features'
-require 'search_features'
configure do
set :haml, { :ugly=>true }
end
before do
- @features = ListsFeatures.features
+ @features = Wally::ListsFeatures.features
end
get '/?' do
- @features = ListsFeatures.features
+ @features = Wally::ListsFeatures.features
haml :index
end
get '/features/:feature/?' do |feature|
- features = ListsFeatures.features
+ features = Wally::ListsFeatures.features
features.each do |feature_hash|
@feature = feature_hash if feature_hash["id"] == feature
end
@@ -31,13 +28,13 @@
get '/search/?' do
if params[:q]
- @search_results = SearchFeatures.new.find(:query => params[:q])
+ @search_results = Wally::SearchFeatures.new.find(:query => params[:q])
end
haml :search
end
get '/features/:feature/scenario/:scenario/?' do |feature_id, scenario_id|
- ListsFeatures.features.each do |feature|
+ Wally::ListsFeatures.features.each do |feature|
if feature["id"] == feature_id
feature["elements"].each do |element|
if element["type"] == "background"
View
36 lib/wally/lists_features.rb
@@ -0,0 +1,36 @@
+require 'gherkin/formatter/json_formatter'
+require 'gherkin/parser/parser'
+
+module Gherkin::Formatter
+ class JSONFormatter
+ def to_hash
+ @feature_hash
+ end
+ end
+end
+
+module Wally
+ class ListsFeatures
+ class << self
+ def features
+ features = []
+ Dir.glob("application-features/*.feature").each do |path|
+ uri = "/features/#{path.gsub("application-features/", "")}"
+ features << parse_gherkin(uri, File.read(path))
+ end
+ features.sort {|a,b| a["name"] <=> b["name"]}
+ end
+
+ private
+
+ def parse_gherkin(uri, text)
+ io = StringIO.new
+ formatter = Gherkin::Formatter::JSONFormatter.new(io)
+ parser = Gherkin::Parser::Parser.new(formatter, false, 'root')
+ parser.parse(text, uri, 0)
+ hash = formatter.to_hash
+ hash
+ end
+ end
+ end
+end
View
0  lib/public/bootstrap.min.css → lib/wally/public/bootstrap.min.css
File renamed without changes
View
43 lib/wally/search_features.rb
@@ -0,0 +1,43 @@
+module Wally
+ class SearchFeatures
+ def find(query)
+ results = []
+ ListsFeatures.features.each do |feature|
+ result = SearchResult.new(feature)
+
+ if feature["tags"]
+ feature["tags"].each do |tag|
+ if tag["name"].downcase.include? query[:query].downcase
+ result.matched_feature = feature
+ end
+ end
+ end
+
+ if feature["name"].downcase.include? query[:query].downcase
+ result.matched_feature = feature
+ end
+
+ if feature["elements"]
+ result.matched_scenarios = feature["elements"].select do |element|
+ if element["name"].downcase.include? query[:query].downcase
+ true
+ elsif element["steps"]
+ element["steps"].any? do |step|
+ step["name"].downcase.include? query[:query].downcase
+ end
+ elsif element["tags"]
+ element["tags"].any? do |tag|
+ tag["name"].downcase.include? query[:query].downcase
+ end
+ end
+ end
+ end
+
+ if result.matches?
+ results << result
+ end
+ end
+ results
+ end
+ end
+end
View
16 lib/wally/search_result.rb
@@ -0,0 +1,16 @@
+module Wally
+ class SearchResult
+ attr_accessor :feature, :matched_feature, :matched_scenarios
+
+ def initialize feature
+ @feature = feature
+ @matched_scenarios = []
+ end
+
+ def matches?
+ return true if matched_feature
+ return true unless matched_scenarios.empty?
+ false
+ end
+ end
+end
View
3  lib/wally/version.rb
@@ -0,0 +1,3 @@
+module Wally
+ VERSION = "0.0.1"
+end
View
0  lib/views/feature.haml → lib/wally/views/feature.haml
File renamed without changes
View
0  lib/views/index.haml → lib/wally/views/index.haml
File renamed without changes
View
0  lib/views/layout.haml → lib/wally/views/layout.haml
File renamed without changes
View
0  lib/views/scenario.haml → lib/wally/views/scenario.haml
File renamed without changes
View
0  lib/views/search.haml → lib/wally/views/search.haml
File renamed without changes
View
29 spec/lists_features_spec.rb
@@ -1,29 +0,0 @@
-require File.join(File.dirname(__FILE__), "spec_helper")
-require 'fileutils'
-require 'lists_features'
-
-describe ListsFeatures do
- before do
- FileUtils.mkdir_p "application-features"
- end
-
- after do
- FileUtils.rm_rf "application-features"
- end
-
- it "returns a list of alphabeticaly ordered features" do
- File.open("application-features/1-sample.feature", "w") do |file|
- file.write "Feature: Zorro"
- end
- File.open("application-features/2-sample.feature", "w") do |file|
- file.write "Feature: Malgor"
- end
- File.open("application-features/3-sample.feature", "w") do |file|
- file.write "Feature: Adrian"
- end
- ListsFeatures.features.size.should == 3
- ListsFeatures.features[0]["name"].should == "Adrian"
- ListsFeatures.features[1]["name"].should == "Malgor"
- ListsFeatures.features[2]["name"].should == "Zorro"
- end
-end
View
81 spec/search_features_spec.rb
@@ -1,81 +0,0 @@
-require File.join(File.dirname(__FILE__), "spec_helper")
-require "search_features"
-
-describe SearchFeatures do
- before do
- FileUtils.mkdir "application-features"
- end
-
- after do
- FileUtils.rm_rf "application-features"
- end
-
- def write_feature(name, contents)
- File.open("application-features/#{name}", "w") do |file|
- file.write(contents)
- end
- end
-
- it "finds features containing text" do
- write_feature("sample1.feature", "Feature: Bla")
- write_feature("sample2.feature", "Feature: Meh")
-
- results = SearchFeatures.new.find(:query => "Meh")
- results.size.should == 1
- results.first.matched_feature["name"].should == "Meh"
- end
-
- it "stores the original feature in the result" do
- write_feature("sample1.feature", "Feature: Bla")
- results = SearchFeatures.new.find(:query => "Bla")
- results.first.feature["name"].should == "Bla"
- end
-
- it "finds features containing text with any case" do
- write_feature("sample1.feature", "Feature: Bla")
- write_feature("sample2.feature", "Feature: Meh")
-
- results = SearchFeatures.new.find(:query => "MEH")
- results.size.should == 1
- results.first.matched_feature["name"].should == "Meh"
- end
-
- context "feature with multiple scenarios" do
- before do
- contents = <<-CONTENTS
- Feature: Sample Feature
- Scenario: Sample Scenario
- Scenario: Matched Scenario
- Given I do some things
- Scenario: Another Scenario
- CONTENTS
- write_feature("sample1.feature", contents)
- end
-
- it "finds scenarios containing text" do
- results = SearchFeatures.new.find(:query => "Matched SCENARIO")
- results.first.matched_scenarios.size.should == 1
- results.first.matched_scenarios.first["name"].should == "Matched Scenario"
- end
-
- it "finds scenario steps" do
- results = SearchFeatures.new.find(:query => "I DO SOME THINGS")
- results.first.matched_scenarios.size.should == 1
- results.first.matched_scenarios.first["name"].should == "Matched Scenario"
- end
- end
-
- context "feature with tags" do
- it "finds features by tag" do
- write_feature("example-feature.feature", "@tag_name\nFeature: Example Feature")
- results = SearchFeatures.new.find(:query => "@tag_NAME")
- results.first.matched_feature["name"].should == "Example Feature"
- end
-
- it "finds scenarios by tag" do
- write_feature("example-feature.feature", "Feature: Example Feature\n@scenario_tag\nScenario: Example Scenario")
- results = SearchFeatures.new.find(:query => "@scenario_TAG")
- results.first.matched_scenarios.first["name"].should == "Example Scenario"
- end
- end
-end
View
24 spec/search_result_spec.rb
@@ -1,24 +0,0 @@
-require File.join(File.dirname(__FILE__), "spec_helper")
-require "search_result"
-
-describe SearchResult do
- subject { SearchResult.new(nil) }
-
- it "knows when there are no results" do
- subject.matches?.should == false
- end
-
- it "contains no matched scenarios" do
- subject.matched_scenarios.should == []
- end
-
- it "knows when there is a feature match" do
- subject.matched_feature = {}
- subject.matches?.should == true
- end
-
- it "knows when there are scenario matches" do
- subject.matched_scenarios = [{}]
- subject.matches?.should == true
- end
-end
View
7 spec/spec_helper.rb
@@ -1,5 +1,6 @@
$:.unshift(File.join(File.dirname(__FILE__), "../lib"))
ENV['RACK_ENV'] = 'test'
-require 'rack/test'
-require 'fakefs/spec_helpers'
-require 'fileutils'
+require "rack/test"
+require "fakefs/spec_helpers"
+require "fileutils"
+require "wally"
View
30 spec/wally/lists_features_spec.rb
@@ -0,0 +1,30 @@
+require File.join(File.dirname(__FILE__), "..", "spec_helper")
+require 'fileutils'
+
+module Wally
+ describe ListsFeatures do
+ before do
+ FileUtils.mkdir_p "application-features"
+ end
+
+ after do
+ FileUtils.rm_rf "application-features"
+ end
+
+ it "returns a list of alphabeticaly ordered features" do
+ File.open("application-features/1-sample.feature", "w") do |file|
+ file.write "Feature: Zorro"
+ end
+ File.open("application-features/2-sample.feature", "w") do |file|
+ file.write "Feature: Malgor"
+ end
+ File.open("application-features/3-sample.feature", "w") do |file|
+ file.write "Feature: Adrian"
+ end
+ ListsFeatures.features.size.should == 3
+ ListsFeatures.features[0]["name"].should == "Adrian"
+ ListsFeatures.features[1]["name"].should == "Malgor"
+ ListsFeatures.features[2]["name"].should == "Zorro"
+ end
+ end
+end
View
82 spec/wally/search_features_spec.rb
@@ -0,0 +1,82 @@
+require File.join(File.dirname(__FILE__), "..", "spec_helper")
+
+module Wally
+ describe SearchFeatures do
+ before do
+ FileUtils.mkdir "application-features"
+ end
+
+ after do
+ FileUtils.rm_rf "application-features"
+ end
+
+ def write_feature(name, contents)
+ File.open("application-features/#{name}", "w") do |file|
+ file.write(contents)
+ end
+ end
+
+ it "finds features containing text" do
+ write_feature("sample1.feature", "Feature: Bla")
+ write_feature("sample2.feature", "Feature: Meh")
+
+ results = SearchFeatures.new.find(:query => "Meh")
+ results.size.should == 1
+ results.first.matched_feature["name"].should == "Meh"
+ end
+
+ it "stores the original feature in the result" do
+ write_feature("sample1.feature", "Feature: Bla")
+ results = SearchFeatures.new.find(:query => "Bla")
+ results.first.feature["name"].should == "Bla"
+ end
+
+ it "finds features containing text with any case" do
+ write_feature("sample1.feature", "Feature: Bla")
+ write_feature("sample2.feature", "Feature: Meh")
+
+ results = SearchFeatures.new.find(:query => "MEH")
+ results.size.should == 1
+ results.first.matched_feature["name"].should == "Meh"
+ end
+
+ context "feature with multiple scenarios" do
+ before do
+ contents = <<-CONTENTS
+ Feature: Sample Feature
+ Scenario: Sample Scenario
+ Scenario: Matched Scenario
+ Given I do some things
+ Scenario: Another Scenario
+ CONTENTS
+ write_feature("sample1.feature", contents)
+ end
+
+ it "finds scenarios containing text" do
+ results = SearchFeatures.new.find(:query => "Matched SCENARIO")
+ results.first.matched_scenarios.size.should == 1
+ results.first.matched_scenarios.first["name"].should == "Matched Scenario"
+ end
+
+ it "finds scenario steps" do
+ results = SearchFeatures.new.find(:query => "I DO SOME THINGS")
+ results.first.matched_scenarios.size.should == 1
+ results.first.matched_scenarios.first["name"].should == "Matched Scenario"
+ end
+ end
+
+ context "feature with tags" do
+ it "finds features by tag" do
+ write_feature("example-feature.feature", "@tag_name\nFeature: Example Feature")
+ results = SearchFeatures.new.find(:query => "@tag_NAME")
+ results.first.matched_feature["name"].should == "Example Feature"
+ end
+
+ it "finds scenarios by tag" do
+ write_feature("example-feature.feature", "Feature: Example Feature\n@scenario_tag\nScenario: Example Scenario")
+ results = SearchFeatures.new.find(:query => "@scenario_TAG")
+ results.first.matched_scenarios.first["name"].should == "Example Scenario"
+ end
+ end
+ end
+end
View
25 spec/wally/search_result_spec.rb
@@ -0,0 +1,25 @@
+require File.join(File.dirname(__FILE__), "..", "spec_helper")
+
+module Wally
+ describe SearchResult do
+ subject { SearchResult.new(nil) }
+
+ it "knows when there are no results" do
+ subject.matches?.should == false
+ end
+
+ it "contains no matched scenarios" do
+ subject.matched_scenarios.should == []
+ end
+
+ it "knows when there is a feature match" do
+ subject.matched_feature = {}
+ subject.matches?.should == true
+ end
+
+ it "knows when there are scenario matches" do
+ subject.matched_scenarios = [{}]
+ subject.matches?.should == true
+ end
+ end
+end
View
29 wally.gemspec
@@ -0,0 +1,29 @@
+# -*- encoding: utf-8 -*-
+$:.push File.expand_path("../lib", __FILE__)
+require "wally/version"
+
+Gem::Specification.new do |s|
+ s.name = "wally"
+ s.version = Wally::VERSION
+ s.authors = ["Andrew Vos"]
+ s.email = ["andrew.vos@gmail.com"]
+ s.homepage = ""
+ s.summary = %q{}
+ s.description = %q{}
+
+ s.rubyforge_project = "wally"
+
+ s.files = `git ls-files`.split("\n")
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
+ s.require_paths = ["lib"]
+
+ s.add_runtime_dependency "sinatra"
+ s.add_runtime_dependency "haml"
+ s.add_runtime_dependency "rdiscount"
+
+ s.add_development_dependency "cucumber"
+ s.add_development_dependency "capybara"
+ s.add_development_dependency "rspec"
+ s.add_development_dependency "fakefs"
+end
Please sign in to comment.
Something went wrong with that request. Please try again.