Permalink
Browse files

can test with rspec

  • Loading branch information...
1 parent 58926b0 commit d77fdceaf345a293b9fb874480c1dcd8a21ad0ae @jtarchie committed Mar 12, 2012
Showing with 135 additions and 12 deletions.
  1. +1 −0 .gitignore
  2. +2 −0 .rspec
  3. +11 −0 Gemfile
  4. +43 −0 Gemfile.lock
  5. +4 −12 nginx.conf
  6. +18 −0 spec/requests/server_spec.rb
  7. +22 −0 spec/spec_helper.rb
  8. +5 −0 spec/support/capybara.rb
  9. +5 −0 spec/support/env.yml
  10. +24 −0 spec/support/start_server.rb
View
1 .gitignore
@@ -0,0 +1 @@
+logs
View
2 .rspec
@@ -0,0 +1,2 @@
+--color
+--format progress
View
11 Gemfile
@@ -0,0 +1,11 @@
+source :rubygems
+
+group :test do
+ gem 'rspec'
+ gem 'capybara'
+end
+
+# Gem should have
+# * convert nginx file for local development
+# * supports config/env.yml for development
+# * suy
View
43 Gemfile.lock
@@ -0,0 +1,43 @@
+GEM
+ remote: http://rubygems.org/
+ specs:
+ capybara (1.1.2)
+ mime-types (>= 1.16)
+ nokogiri (>= 1.3.3)
+ rack (>= 1.0.0)
+ rack-test (>= 0.5.4)
+ selenium-webdriver (~> 2.0)
+ xpath (~> 0.1.4)
+ childprocess (0.3.1)
+ ffi (~> 1.0.6)
+ diff-lcs (1.1.3)
+ ffi (1.0.11)
+ mime-types (1.17.2)
+ multi_json (1.1.0)
+ nokogiri (1.5.2)
+ rack (1.4.1)
+ rack-test (0.6.1)
+ rack (>= 1.0)
+ rspec (2.8.0)
+ rspec-core (~> 2.8.0)
+ rspec-expectations (~> 2.8.0)
+ rspec-mocks (~> 2.8.0)
+ rspec-core (2.8.0)
+ rspec-expectations (2.8.0)
+ diff-lcs (~> 1.1.2)
+ rspec-mocks (2.8.0)
+ rubyzip (0.9.6.1)
+ selenium-webdriver (2.20.0)
+ childprocess (>= 0.2.5)
+ ffi (~> 1.0)
+ multi_json (~> 1.0)
+ rubyzip
+ xpath (0.1.4)
+ nokogiri (~> 1.3)
+
+PLATFORMS
+ ruby
+
+DEPENDENCIES
+ capybara
+ rspec
View
16 nginx.conf
@@ -1,14 +1,13 @@
worker_processes 1;
-error_log logs/error.log;
events {
worker_connections 1024;
}
http {
upstream database {
- postgres_server ec2-23-21-253-206.compute-1.amazonaws.com
- dbname=uwbhkfjkof
- user=uwbhkfjkof
- password=8VuHOGfNXS5d6Iq0qzNd;
+ postgres_server $ENV_DB_HOST
+ dbname=$ENV_DB_NAME
+ user=$ENV_DB_USERNAME
+ password=$ENV_DB_PASSWORD;
}
server {
listen $ENV_PORT;
@@ -18,15 +17,8 @@ http {
rds_json on;
postgres_query "SELECT * FROM venues";
- postgres_rewrite no_rows 403;
}
- location /arrays {
- postgres_pass database;
- rds_json on;
-
- postgres_query "SELECT ARRAY[1,2,3]";
- }
location / {
default_type text/html;
content_by_lua '
View
18 spec/requests/server_spec.rb
@@ -0,0 +1,18 @@
+require 'spec_helper'
+
+feature 'Venue API' do
+
+ context "GET#index" do
+ it "works" do
+ visit '/'
+ page.should have_content("hello, world")
+ end
+ end
+
+ context "GET#venues" do
+ it "it works" do
+ visit '/venues'
+ json.should == []
+ end
+ end
+end
View
22 spec/spec_helper.rb
@@ -0,0 +1,22 @@
+require 'rubygems'
+require 'bundler/setup'
+Bundler.require(:default, :test)
+
+require 'capybara/rspec'
+
+Dir[File.join(File.dirname(__FILE__), "support/**/*.rb")].each {|f| require f}
+
+Capybara.run_server = false
+Capybara.app_host = "http://localhost:#{ENV_YAML['PORT']}"
+
+RSpec.configure do |config|
+ config.treat_symbols_as_metadata_keys_with_true_values = true
+ config.run_all_when_everything_filtered = true
+ config.filter_run :focus
+
+ def json
+ current_html = body
+ current_html =~ /<pre.*?>(.*)<\/pre>/
+ JSON.parse($1)
+ end
+end
View
5 spec/support/capybara.rb
@@ -0,0 +1,5 @@
+Capybara.register_driver :selenium do |app|
+ Capybara::Selenium::Driver.new(app, :browser => :chrome)
+end
+
+Capybara.default_driver = :selenium
View
5 spec/support/env.yml
@@ -0,0 +1,5 @@
+PORT: 3456
+DB_HOST: 127.0.0.1
+DB_NAME: venues_api_dev
+DB_USERNAME: jtarchie
+DB_PASSWORD:
View
24 spec/support/start_server.rb
@@ -0,0 +1,24 @@
+ENV_YAML = YAML.load_file(File.join(File.dirname(__FILE__), "env.yml"))
+APP_DIR = File.dirname(__FILE__)
+APP_CFG = File.join(APP_DIR, "..", "..", ".env_nginx.conf")
+
+conf_file = File.read(File.join(APP_DIR, "..", "..", "nginx.conf"))
+conf_file.gsub!(/\$ENV_(\w+)/) do
+ ENV_YAML[$1]
+end
+File.open(APP_CFG, "w") do |file|
+ file.puts conf_file
+end
+
+BIN_DIR = '/usr/local/openresty'
+
+RSpec.configure do |config|
+ config.before(:all) do
+ `#{BIN_DIR}/nginx/sbin/nginx -c #{APP_CFG} -g "daemon on;"`
+ end
+
+ config.after(:all) do
+ `rm #{APP_CFG}`
+ `kill $(ps ax | awk '/nginx: master/ {print $1}')`
+ end
+end

0 comments on commit d77fdce

Please sign in to comment.