Permalink
Browse files

Turned wally into a gem

  • Loading branch information...
AndrewVos committed Nov 22, 2011
1 parent 2da32b1 commit 1f833afe76ed94d03d9a33cc03bdeeca64162d90
View
@@ -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
@@ -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
@@ -0,0 +1 @@
+require "bundler/gem_tasks"
View
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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"
@@ -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"
@@ -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
File renamed without changes.
@@ -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
@@ -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
@@ -0,0 +1,3 @@
+module Wally
+ VERSION = "0.0.1"
+end
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
@@ -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
Oops, something went wrong.

0 comments on commit 1f833af

Please sign in to comment.