Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

simple support for rspec tests and make the search term configurable …

…via your yaml file
  • Loading branch information...
commit e910c031cac3ca4d90f5b87bde42f91895f189ba 1 parent d796da1
@atmos authored
View
1  .gitignore
@@ -3,3 +3,4 @@ tmp
db/*
bin
vendor
+config/config.yml
View
21 Gemfile
@@ -1,15 +1,22 @@
-gem 'sinatra', :require_as => 'sinatra/base'
-gem 'mongo'
-gem 'mongo_ext', :require_as => [ ]
-gem 'mustache', :require_as => 'mustache/sinatra'
-gem 'nokogiri'
+only :runtime do
+ gem 'sinatra'
+ gem 'mongo'
+ gem 'mongo_ext'
+ gem 'mustache'
+ gem 'nokogiri'
+ gem 'rack-bug'
+end
only :development do
- gem 'shotgun'
gem 'rake'
- gem 'rack-bug', :require_as => 'rack/bug'
+ gem 'shotgun'
end
only :test do
+ gem 'webrat'
+ gem 'rspec', :require_as => 'spec'
+ gem 'fakeweb'
+ gem 'diff-lcs'
gem 'rack-test', :require_as => 'rack/test'
+ gem 'ruby-debug'
end
View
27 Rakefile
@@ -1,21 +1,10 @@
-require "rake/testtask"
+require 'bundler'
+Bundler.require_env(:test)
+require "spec/rake/spectask"
desc "Default: run all tests"
-task :default => :test
+task :default => :spec
-desc "Run tests"
-task :test => %w(test:units test:acceptance)
-namespace :test do
- desc "Run unit tests"
- Rake::TestTask.new(:units) do |t|
- t.test_files = FileList["test/unit/*_test.rb"]
- end
-
- desc "Run acceptance tests"
- Rake::TestTask.new(:acceptance) do |t|
- t.test_files = FileList["test/acceptance/*_test.rb"]
- end
-end
namespace :mongodb do
desc "Start MongoDB for development"
@@ -41,4 +30,10 @@ namespace :app do
end
end
-multitask :start => [ 'mongodb:start', 'app:start' ]
+multitask :start => [ 'mongodb:start', 'app:start' ]
+
+desc "Run tests"
+Spec::Rake::SpecTask.new do |t|
+ t.spec_opts << "-c -D"
+ t.pattern = "spec/**/*_spec.rb"
+end
View
6 config/config.yml → config/config.yml.example
@@ -8,7 +8,9 @@
# Note:
# * The appropriate data_objects adapter must be installed (`do_mysql`, etc)
# * You must create the `watchtower` database on localhost, of course.
-:database_uri: mysql://root@localhost/watchtower_dev
+# :database_uri: mysql://root@localhost/watchtower_dev
# Path to the watchtower log file
-:log: /var/log/watchtower.log
+:log: /var/log/watchtower.log
+
+:search_term: github
View
3  lib/watchtower.rb
@@ -32,6 +32,7 @@ def self.default_configuration
@defaults ||= { :database_uri => "sqlite3::memory:",
:log => STDOUT,
:base_uri => "http://localhost:8910",
+ :search_term => 'github',
:log_debug_info => false }
end
@@ -59,4 +60,4 @@ def call(severity, time, progname, msg)
time.strftime("[%H:%M:%S] ") + msg2str(msg) + "\n"
end
end
-end
+end
View
2  lib/watchtower/app.rb
@@ -30,4 +30,4 @@ class App < Sinatra::Default
end
end
-end
+end
View
6 lib/watchtower/beam/hacker_news.rb
@@ -8,10 +8,12 @@ def initialize
end
def find_github_stories
+ term = Watchtower.config[:search_term]
+
stories = []
@stories_document.css('tr').each do |row|
link = row.css('td.title a').first
- if link && (link['href'].downcase =~ (/github/) || link.content.downcase =~ (/github/))
+ if link && (link['href'].downcase =~ (/#{term}/) || link.content.downcase =~ (/#{term}/))
author, author_url, comments, hn_url, points = "?"
meta_row = row.next
@@ -49,4 +51,4 @@ def results
end
end
end
-end
+end
View
5 lib/watchtower/beam/twitter.rb
@@ -2,7 +2,8 @@ module Watchtower
module Beam
class Twitter
def initialize
- @tweets_document = Nokogiri::HTML(open('http://search.twitter.com/search.atom?q=github'))
+ term = Watchtower.config[:search_term]
+ @tweets_document = Nokogiri::HTML(open("http://search.twitter.com/search.atom?q=#{term}"))
@results = self.find_github_tweets
end
@@ -31,4 +32,4 @@ def results
end
end
end
-end
+end
View
21 spec/homepage_spec.rb
@@ -0,0 +1,21 @@
+require File.dirname(__FILE__) + '/spec_helper'
+
+describe "hitting the root url" do
+
+ it "works" do
+ response = get '/'
+ response.should be_successful
+ response.should have_selector("#sidebar > #logo", :content => 'Watchtower')
+ response.should have_selector("#main > ul.events")
+ end
+
+ it 'polls and upates' do
+ response = get '/poll'
+
+ response.body.should_not be_empty
+
+ response = get '/poll'
+ response.body.should be_empty
+ end
+
+end
View
19 spec/spec_helper.rb
@@ -0,0 +1,19 @@
+Bundler.require_env(:test)
+require File.join(File.dirname(__FILE__), '..', 'lib', 'watchtower')
+require 'pp'
+
+Spec::Runner.configure do |config|
+ config.include(Rack::Test::Methods)
+ config.include(Webrat::Methods)
+ config.include(Webrat::Matchers)
+
+ config.before(:each) do
+ MONGO.drop_collection('beams')
+ end
+
+ def app
+ @app = Rack::Builder.new do
+ run Watchtower::App
+ end
+ end
+end
View
12 templates/layout.mustache
@@ -1,14 +1,14 @@
<!DOCTYPE html>
<html>
<head>
- <title>GitHub Watchtower</title>
- <link rel="stylesheet" href="/stylesheets/base.css" type="text/css" />
- <script src="/javascripts/lib/jquery.js" type="text/javascript" charset="utf-8"></script>
- <script src="/javascripts/application.js" type="text/javascript" charset="utf-8"></script>
+ <title>Watchtower</title>
+ <link rel="stylesheet" href="/stylesheets/base.css" type="text/css" />
+ <script src="/javascripts/lib/jquery.js" type="text/javascript" charset="utf-8"></script>
+ <script src="/javascripts/application.js" type="text/javascript" charset="utf-8"></script>
</head>
<body>
<div id="sidebar">
- <h2 id="logo">GitHub Watchtower</h2>
+ <h2 id="logo">Watchtower</h2>
<ul id="nav">
<li data-title="All Events" data-service="all">
<strong>All Events</strong>
@@ -29,4 +29,4 @@
{{{yield}}}
</div>
</body>
-</html>
+</html>
Please sign in to comment.
Something went wrong with that request. Please try again.