Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Sweet test setup

  • Loading branch information...
commit 5373034a76933ae8c28aa247cbef9491b8e92047 1 parent db70951
@lapluviosilla lapluviosilla authored
View
31 Gemfile
@@ -22,6 +22,37 @@ end
gem 'jquery-rails'
+group :development do
+ gem 'letter_opener'
+
+ # Speed and testing Tools (not needed on testing/integration server)
+ gem 'guard'
+ gem 'rb-fsevent'
+ gem 'zeus'
+ gem 'guard-rspec'
+
+ # Debugger and REPL
+ gem 'pry'
+ gem 'pry-stack_explorer'
+ gem 'pry-debugger'
+end
+
+group :test, :development do
+ gem 'rspec'
+ gem 'rspec-rails', ">= 2.0"
+ gem 'shoulda-matchers'
+ gem 'factory_girl', ">= 4.2.0"
+ gem 'factory_girl_rails'
+ gem 'capybara'
+ gem 'poltergeist'
+ gem 'rr'
+ gem 'ffaker'
+ gem 'database_cleaner'
+
+ gem 'ruby_gntp'
+ gem 'fuubar'
+end
+
# To use ActiveModel has_secure_password
# gem 'bcrypt-ruby', '~> 3.0.0'
View
123 Gemfile.lock
@@ -28,8 +28,18 @@ GEM
activesupport (3.2.13)
i18n (= 0.6.1)
multi_json (~> 1.0)
+ addressable (2.3.5)
arel (3.0.2)
+ binding_of_caller (0.7.2)
+ debug_inspector (>= 0.0.1)
builder (3.0.4)
+ capybara (2.1.0)
+ mime-types (>= 1.16)
+ nokogiri (>= 1.3.3)
+ rack (>= 1.0.0)
+ rack-test (>= 0.5.4)
+ xpath (~> 2.0)
+ coderay (1.0.9)
coffee-rails (3.2.2)
coffee-script (>= 2.2.0)
railties (~> 3.2.0)
@@ -37,23 +47,85 @@ GEM
coffee-script-source
execjs
coffee-script-source (1.6.2)
+ columnize (0.3.6)
+ database_cleaner (1.0.1)
+ debug_inspector (0.0.2)
+ debugger (1.6.0)
+ columnize (>= 0.3.1)
+ debugger-linecache (~> 1.2.0)
+ debugger-ruby_core_source (~> 1.2.1)
+ debugger-linecache (1.2.0)
+ debugger-ruby_core_source (1.2.3)
+ diff-lcs (1.2.4)
erubis (2.7.0)
+ eventmachine (1.0.3)
execjs (1.4.0)
multi_json (~> 1.0)
+ factory_girl (4.2.0)
+ activesupport (>= 3.0.0)
+ factory_girl_rails (4.2.1)
+ factory_girl (~> 4.2.0)
+ railties (>= 3.0.0)
+ faye-websocket (0.4.7)
+ eventmachine (>= 0.12.0)
+ ffaker (1.16.1)
+ ffi (1.9.0)
+ formatador (0.2.4)
+ fuubar (1.1.1)
+ rspec (~> 2.0)
+ rspec-instafail (~> 0.2.0)
+ ruby-progressbar (~> 1.0)
+ guard (1.8.1)
+ formatador (>= 0.2.4)
+ listen (>= 1.0.0)
+ lumberjack (>= 1.0.2)
+ pry (>= 0.9.10)
+ thor (>= 0.14.6)
+ guard-rspec (3.0.2)
+ guard (>= 1.8)
+ rspec (~> 2.13)
hike (1.2.3)
+ http_parser.rb (0.5.3)
i18n (0.6.1)
journey (1.0.4)
jquery-rails (3.0.1)
railties (>= 3.0, < 5.0)
thor (>= 0.14, < 2.0)
json (1.8.0)
+ launchy (2.3.0)
+ addressable (~> 2.3)
+ letter_opener (1.1.2)
+ launchy (~> 2.2)
+ listen (1.2.2)
+ rb-fsevent (>= 0.9.3)
+ rb-inotify (>= 0.9)
+ rb-kqueue (>= 0.2)
+ lumberjack (1.0.4)
mail (2.5.4)
mime-types (~> 1.16)
treetop (~> 1.4.8)
+ method_source (0.8.1)
mime-types (1.23)
+ mini_portile (0.5.0)
multi_json (1.7.7)
+ nokogiri (1.6.0)
+ mini_portile (~> 0.5.0)
pg (0.15.1)
+ poltergeist (1.3.0)
+ capybara (~> 2.1.0)
+ faye-websocket (>= 0.4.4, < 0.5.0)
+ http_parser.rb (~> 0.5.3)
polyglot (0.3.3)
+ pry (0.9.12.2)
+ coderay (~> 1.0.5)
+ method_source (~> 0.8)
+ slop (~> 3.4)
+ pry-debugger (0.2.2)
+ debugger (~> 1.3)
+ pry (~> 0.9.10)
+ pry-stack_explorer (0.4.9)
+ binding_of_caller (>= 0.7)
+ pry (~> 0.9.11)
rack (1.4.5)
rack-cache (1.2)
rack (>= 0.4)
@@ -77,13 +149,40 @@ GEM
rdoc (~> 3.4)
thor (>= 0.14.6, < 2.0)
rake (10.1.0)
+ rb-fsevent (0.9.3)
+ rb-inotify (0.9.0)
+ ffi (>= 0.5.0)
+ rb-kqueue (0.2.0)
+ ffi (>= 0.5.0)
rdoc (3.12.2)
json (~> 1.4)
+ rr (1.1.1)
+ rspec (2.13.0)
+ rspec-core (~> 2.13.0)
+ rspec-expectations (~> 2.13.0)
+ rspec-mocks (~> 2.13.0)
+ rspec-core (2.13.1)
+ rspec-expectations (2.13.0)
+ diff-lcs (>= 1.1.3, < 2.0)
+ rspec-instafail (0.2.4)
+ rspec-mocks (2.13.1)
+ rspec-rails (2.13.2)
+ actionpack (>= 3.0)
+ activesupport (>= 3.0)
+ railties (>= 3.0)
+ rspec-core (~> 2.13.0)
+ rspec-expectations (~> 2.13.0)
+ rspec-mocks (~> 2.13.0)
+ ruby-progressbar (1.1.1)
+ ruby_gntp (0.3.4)
sass (3.2.9)
sass-rails (3.2.6)
railties (~> 3.2.0)
sass (>= 3.1.10)
tilt (~> 1.3)
+ shoulda-matchers (2.2.0)
+ activesupport (>= 3.0.0)
+ slop (3.4.5)
sprockets (2.2.2)
hike (~> 1.2)
multi_json (~> 1.0)
@@ -98,14 +197,38 @@ GEM
uglifier (2.1.1)
execjs (>= 0.3.0)
multi_json (~> 1.0, >= 1.0.2)
+ xpath (2.0.0)
+ nokogiri (~> 1.3)
+ zeus (0.13.3)
+ method_source (>= 0.6.7)
PLATFORMS
ruby
DEPENDENCIES
+ capybara
coffee-rails (~> 3.2.1)
+ database_cleaner
+ factory_girl (>= 4.2.0)
+ factory_girl_rails
+ ffaker
+ fuubar
+ guard
+ guard-rspec
jquery-rails
+ letter_opener
pg
+ poltergeist
+ pry
+ pry-debugger
+ pry-stack_explorer
rails (= 3.2.13)
+ rb-fsevent
+ rr
+ rspec
+ rspec-rails (>= 2.0)
+ ruby_gntp
sass-rails (~> 3.2.3)
+ shoulda-matchers
uglifier (>= 1.0.3)
+ zeus
View
20 Guardfile
@@ -0,0 +1,20 @@
+guard 'rspec', :zeus => true do
+ watch(%r{^spec/.+_spec\.rb$})
+ watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
+ watch('spec/spec_helper.rb') { "spec" }
+
+ # Rails example
+ watch(%r{^app/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
+ watch(%r{^app/(.*)(\.erb|\.haml)$}) { |m| "spec/#{m[1]}#{m[2]}_spec.rb" }
+ # watch(%r{^app/controllers/(.+)_(controller)\.rb$}) { |m| ["spec/routing/#{m[1]}_routing_spec.rb", "spec/#{m[2]}s/#{m[1]}_#{m[2]}_spec.rb", "spec/acceptance/#{m[1]}_spec.rb"] }
+ watch(%r{^spec/support/(.+)\.rb$}) { "spec" }
+ watch('config/routes.rb') { "spec/routing" }
+ # watch('app/controllers/application_controller.rb') { "spec/controllers" }
+
+ # Capybara features specs
+ watch(%r{^app/views/(.+)/.*\.(erb|haml)$}) { |m| "spec/features/#{m[1]}_spec.rb" }
+
+ # Turnip features and steps
+ # watch(%r{^spec/acceptance/(.+)\.feature$})
+ # watch(%r{^spec/acceptance/steps/(.+)_steps\.rb$}) { |m| Dir[File.join("**/#{m[1]}.feature")][0] || 'spec/acceptance' }
+end
View
14 TESTS_README.md
@@ -0,0 +1,14 @@
+# Ipo Web Tests
+
+There are a couple of steps required to run the different specs for Ipo WEbas described below:
+
+
+## Acceptance Tests
+
+In order to run acceptance tests (those that test the web perspective) also known as feature tests, you should install **PhantomJS**. On the poltergeist gem README there are some basic instructions on how to do so ( https://github.com/jonleighton/poltergeist ). If you have HomeBrew installed on your mac then it is as easy as running `brew install phantomjs`
+
+## Running Tests
+
+You can run the tests by executing either `rake spec` or `guard start`. Rake spec is the traditional way of executing the test suite, and guard start is a autotest runner that runs tests as you modify your code (useful for active development). Either way works.
+
+Before running `guard start` you must run `zeus start`.
View
11 custom_plan.rb
@@ -0,0 +1,11 @@
+require 'zeus/rails'
+
+class CustomPlan < Zeus::Rails
+
+ # def my_custom_command
+ # # see https://github.com/burke/zeus/blob/master/docs/ruby/modifying.md
+ # end
+
+end
+
+Zeus.plan = CustomPlan.new
View
4 spec/features/features_helper.rb
@@ -0,0 +1,4 @@
+require 'spec_helper'
+
+# Put your feature spec helpers inside spec/features/support
+Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
View
41 spec/features/support/devise.rb
@@ -0,0 +1,41 @@
+include Devise::TestHelpers
+
+include Warden::Test::Helpers
+Warden.test_mode!
+
+# Will run the given code as the user passed in
+def as_user(user=nil, &block)
+ current_login = user.login || Factory.create(:user)
+ as_login(:user, current_login, &block)
+end
+
+def as_admin(admin=nil, &block)
+ current_login = admin.login || Factory.create(:admin)
+ as_login(:admin, current_login)
+end
+
+def as_login(scope = :user, login=nil, &block)
+ if request.present?
+ sign_in(login)
+ else
+ Rails.logger.info "as_login login_as #{login}"
+ login_as(login, :scope => scope, :run_callbacks => false)
+ end
+ block.call if block.present?
+ return self
+end
+
+def as_visitor(user=nil, &block)
+ current_login = user.login || Factory.stub(:user)
+ if request.present?
+ sign_out(current_login)
+ else
+ logout(:user)
+ end
+ block.call if block.present?
+ return self
+end
+
+RSpec.configure do |config|
+ config.after(:each) { Warden.test_reset! }
+end
View
9 spec/features/support/helpers.rb
@@ -0,0 +1,9 @@
+module HelperMethods
+ def wait_up_to(secs = 2, &block)
+ temp = Capybara.default_wait_time
+ Capybara.default_wait_time = secs
+ block.call
+ Capybara.default_wait_time = temp
+ end
+end
+RSpec.configuration.include HelperMethods, :type => :feature
View
52 spec/spec_helper.rb
@@ -0,0 +1,52 @@
+# This file is copied to spec/ when you run 'rails generate rspec:install'
+ENV["RAILS_ENV"] = 'test'
+require File.expand_path("../../config/environment", __FILE__)
+require 'rspec/rails'
+# require 'rspec/autorun'
+
+# Requires supporting ruby files with custom matchers and macros, etc,
+# in spec/support/ and its subdirectories.
+Dir[Rails.root.join("./spec/support/**/*.rb")].each {|f| require f}
+
+RSpec.configure do |config|
+ # ## Mock Framework
+ #
+ # If you prefer to use mocha, flexmock or RR, uncomment the appropriate line:
+ #
+ # config.mock_with :mocha
+ # config.mock_with :flexmock
+ config.mock_with :rr
+
+ # Remove this line if you're not using ActiveRecord or ActiveRecord fixtures
+ config.fixture_path = "#{::Rails.root}/spec/fixtures"
+
+ # If you're not using ActiveRecord, or you'd prefer not to run each of your
+ # examples within a transaction, remove the following line or assign false
+ # instead of true.
+ config.use_transactional_fixtures = false
+
+ # If true, the base class of anonymous controllers will be inferred
+ # automatically. This will be the default behavior in future versions of
+ # rspec-rails.
+ config.infer_base_class_for_anonymous_controllers = false
+
+ # Run specs in random order to surface order dependencies. If you find an
+ # order dependency and want to debug it, you can fix the order by providing
+ # the seed, which is printed after each run.
+ # --seed 1234
+ config.order = "random"
+
+ # Database cleaner
+ config.before(:suite) do
+ DatabaseCleaner.strategy = :truncation
+ DatabaseCleaner.clean_with(:truncation)
+ end
+
+ config.before(:each) do
+ DatabaseCleaner.start
+ end
+
+ config.after(:each) do
+ DatabaseCleaner.clean
+ end
+end
View
16 spec/support/capybara.rb
@@ -0,0 +1,16 @@
+require 'capybara/poltergeist'
+Capybara.register_driver :poltergeist_debug do |app|
+ Capybara::Poltergeist::Driver.new(app, :inspector => true)
+end
+Capybara.javascript_driver = :poltergeist
+Capybara.always_include_port = true
+
+module CapybaraHelpers
+ def url_for_subdomain subdomain="www", path="/"
+ port = Capybara.server_port.blank? ? '' : (":" + Capybara.server_port)
+ "http://#{subdomain}.lvh.me#{port}#{path}"
+ end
+end
+RSpec.configuration.include CapybaraHelpers, :type => :feature
+RSpec.configuration.include CapybaraHelpers, :type => :routing
+RSpec.configuration.include CapybaraHelpers, :type => :request
View
5 spec/support/matchers/capybara.rb
@@ -0,0 +1,5 @@
+RSpec::Matchers.define :have_following_content do |*expected_contents|
+ match do |actual|
+ expected_contents.all?{|content| actual.has_content? content}
+ end
+end
View
10 spec/support/shared.rb
@@ -0,0 +1,10 @@
+
+
+# ---- SHARED EXAMPLES ---- #
+share_examples_for "a model" do
+ it { should be_invalid } # Because of email validation etc
+ context "when built with a default complete factory" do
+ subject { FactoryGirl.create(described_class.name.underscore.to_sym) }
+ it { should be_valid }
+ end
+end
View
8 spec/views/application.html.erb_spec.rb
@@ -0,0 +1,8 @@
+require 'spec_helper'
+
+describe "layouts/application" do
+ it "displays default rails page" do
+ render
+ expect(rendered).to have_content "IpoWeb"
+ end
+end
View
22 zeus.json
@@ -0,0 +1,22 @@
+{
+ "command": "ruby -rubygems -r./custom_plan -eZeus.go",
+
+ "plan": {
+ "boot": {
+ "default_bundle": {
+ "development_environment": {
+ "prerake": {"rake": []},
+ "runner": ["r"],
+ "console": ["c"],
+ "server": ["s"],
+ "generate": ["g"],
+ "destroy": ["d"],
+ "dbconsole": []
+ },
+ "test_environment": {
+ "test_helper": {"test": ["rspec"]}
+ }
+ }
+ }
+ }
+}
Please sign in to comment.
Something went wrong with that request. Please try again.