Skip to content

Commit

Permalink
can test with rspec
Browse files Browse the repository at this point in the history
  • Loading branch information
jtarchie committed Mar 12, 2012
1 parent 58926b0 commit d77fdce
Show file tree
Hide file tree
Showing 10 changed files with 135 additions and 12 deletions.
1 change: 1 addition & 0 deletions .gitignore
@@ -0,0 +1 @@
logs
2 changes: 2 additions & 0 deletions .rspec
@@ -0,0 +1,2 @@
--color
--format progress
11 changes: 11 additions & 0 deletions 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
43 changes: 43 additions & 0 deletions 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
16 changes: 4 additions & 12 deletions 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;
Expand All @@ -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 '
Expand Down
18 changes: 18 additions & 0 deletions 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
22 changes: 22 additions & 0 deletions 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
5 changes: 5 additions & 0 deletions 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
5 changes: 5 additions & 0 deletions 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:
24 changes: 24 additions & 0 deletions 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.