Permalink
Browse files

Add testing frameworks to project

Added RSpec and Cucumber for unit and integration/acceptance testing, respectively.  Added a few test cases, to ensure all was working, but the app is untested at the moment.  Test cases will be added for existing functionality as time goes on.  Any new commits, ensure tests are added and all tests pass.

Additional testing gems used:
- Capybara
- Guard (Rspec and Cucumber)
- FactoryGirl
- DatabaseCleaner
  • Loading branch information...
1 parent 8d3ac08 commit 039db3dcbfc7878ba27586af6733b85dc8167721 @jnraine committed Jan 1, 2012
View
1 .rspec
@@ -0,0 +1 @@
+--colour
View
21 Gemfile
@@ -1,22 +1,33 @@
# Edit this Gemfile to bundle your application's dependencies.
source 'http://gemcutter.org'
-
gem "rails", "3.0.10"
gem "sqlite3-ruby", :require => "sqlite3"
-gem 'will_paginate', '~> 3.0' # version added for rails 3 compatibility
+gem 'will_paginate', '~> 3.0'
gem "nokogiri"
gem "paperclip"
gem "client_side_validations"
gem "whenever"
gem "plist"
gem "cancan"
gem "highline"
-gem "newrelic_rpm"
+gem "newrelic_rpm", :group => :production
group :development do
- gem "ruby-debug19" , :require => "ruby-debug"
- gem "rails-erd"
gem "textmate_backtracer"
+end
+
+group :test, :development do
gem "pry-rails"
+ gem "rspec-rails", "~> 2.6"
+ gem "capybara"
+ gem "launchy"
+ gem "guard-rspec"
+ gem "guard-cucumber"
+end
+
+group :test do
+ gem 'cucumber-rails'
+ gem "factory_girl_rails"
+ gem 'database_cleaner'
end
View
@@ -28,21 +28,58 @@ GEM
activemodel (= 3.0.10)
activesupport (= 3.0.10)
activesupport (3.0.10)
- archive-tar-minitar (0.5.2)
+ addressable (2.2.6)
arel (2.0.10)
builder (2.1.2)
cancan (1.6.5)
+ 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.2.4)
+ ffi (~> 1.0.6)
chronic (0.6.4)
client_side_validations (3.1.0)
cocaine (0.2.0)
coderay (0.9.8)
- columnize (0.3.4)
+ cucumber (1.1.4)
+ builder (>= 2.1.2)
+ diff-lcs (>= 1.1.2)
+ gherkin (~> 2.7.1)
+ json (>= 1.4.6)
+ term-ansicolor (>= 1.0.6)
+ cucumber-rails (1.2.1)
+ capybara (>= 1.1.2)
+ cucumber (>= 1.1.3)
+ nokogiri (>= 1.5.0)
+ database_cleaner (0.7.0)
+ diff-lcs (1.1.3)
erubis (2.6.6)
abstract (>= 1.0.0)
+ factory_girl (2.3.2)
+ activesupport
+ factory_girl_rails (1.4.0)
+ factory_girl (~> 2.3.0)
+ railties (>= 3.0.0)
+ ffi (1.0.11)
+ gherkin (2.7.1)
+ json (>= 1.4.6)
+ guard (0.9.4)
+ ffi (>= 0.5.0)
+ thor (~> 0.14.6)
+ guard-cucumber (0.7.4)
+ cucumber (>= 0.10)
+ guard (>= 0.8.3)
+ guard-rspec (0.5.10)
+ guard (>= 0.8.4)
highline (1.6.2)
i18n (0.5.0)
- linecache19 (0.5.12)
- ruby_core_source (>= 0.1.4)
+ json (1.6.4)
+ launchy (2.0.5)
+ addressable (~> 2.2.6)
mail (2.2.19)
activesupport (>= 2.3.6)
i18n (>= 0.4.0)
@@ -51,6 +88,7 @@ GEM
method_source (0.6.7)
ruby_parser (>= 2.3.1)
mime-types (1.16)
+ multi_json (1.0.4)
newrelic_rpm (3.2.0)
nokogiri (1.5.0)
paperclip (2.4.1)
@@ -84,10 +122,6 @@ GEM
activesupport (= 3.0.10)
bundler (~> 1.0)
railties (= 3.0.10)
- rails-erd (0.4.5)
- activerecord (~> 3.0)
- activesupport (~> 3.0)
- ruby-graphviz (~> 0.9.18)
railties (3.0.10)
actionpack (= 3.0.10)
activesupport (= 3.0.10)
@@ -96,24 +130,33 @@ GEM
thor (~> 0.14.4)
rake (0.9.2.2)
rdoc (3.9.4)
- ruby-debug-base19 (0.11.25)
- columnize (>= 0.3.1)
- linecache19 (>= 0.5.11)
- ruby_core_source (>= 0.1.4)
- ruby-debug19 (0.11.6)
- columnize (>= 0.3.1)
- linecache19 (>= 0.5.11)
- ruby-debug-base19 (>= 0.11.19)
- ruby-graphviz (0.9.21)
- ruby_core_source (0.1.5)
- archive-tar-minitar (>= 0.5.2)
+ rspec (2.7.0)
+ rspec-core (~> 2.7.0)
+ rspec-expectations (~> 2.7.0)
+ rspec-mocks (~> 2.7.0)
+ rspec-core (2.7.1)
+ rspec-expectations (2.7.0)
+ diff-lcs (~> 1.1.2)
+ rspec-mocks (2.7.0)
+ rspec-rails (2.7.0)
+ actionpack (~> 3.0)
+ activesupport (~> 3.0)
+ railties (~> 3.0)
+ rspec (~> 2.7.0)
ruby_parser (2.3.1)
sexp_processor (~> 3.0)
+ rubyzip (0.9.5)
+ selenium-webdriver (2.15.0)
+ childprocess (>= 0.2.1)
+ ffi (~> 1.0.9)
+ multi_json (~> 1.0.4)
+ rubyzip
sexp_processor (3.0.9)
slop (2.1.0)
sqlite3 (1.3.4)
sqlite3-ruby (1.3.3)
sqlite3 (>= 1.3.3)
+ term-ansicolor (1.0.7)
textmate_backtracer (1.0.0)
thor (0.14.6)
treetop (1.4.10)
@@ -124,23 +167,31 @@ GEM
activesupport (>= 2.3.4)
chronic (~> 0.6.3)
will_paginate (3.0.0)
+ xpath (0.1.4)
+ nokogiri (~> 1.3)
yard (0.7.4)
PLATFORMS
ruby
DEPENDENCIES
cancan
+ capybara
client_side_validations
+ cucumber-rails
+ database_cleaner
+ factory_girl_rails
+ guard-cucumber
+ guard-rspec
highline
+ launchy
newrelic_rpm
nokogiri
paperclip
plist
pry-rails
rails (= 3.0.10)
- rails-erd
- ruby-debug19
+ rspec-rails (~> 2.6)
sqlite3-ruby
textmate_backtracer
whenever
View
@@ -0,0 +1,28 @@
+# A sample Guardfile
+# More info at https://github.com/guard/guard#readme
+
+guard 'rspec', :version => 2 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 request specs
+ watch(%r{^app/views/(.+)/.*\.(erb|haml)$}) { |m| "spec/requests/#{m[1]}_spec.rb" }
+ # FactoryGirl
+ watch(%r{^spec/factories/.+\.rb$}) { "spec" }
+end
+
+
+guard 'cucumber' do
+ watch(%r{^features/.+\.feature$})
+ watch(%r{^features/support/.+$}) { 'features' }
+ watch(%r{^features/step_definitions/(.+)_steps\.rb$}) { |m| Dir[File.join("**/#{m[1]}.feature")][0] || 'features' }
+ watch(%r{^spec/factories/.+\.rb$}) { "features" }
+end
View
@@ -0,0 +1,8 @@
+<%
+rerun = File.file?('rerun.txt') ? IO.read('rerun.txt') : ""
+rerun_opts = rerun.to_s.strip.empty? ? "--format #{ENV['CUCUMBER_FORMAT'] || 'progress'} features" : "--format #{ENV['CUCUMBER_FORMAT'] || 'pretty'} #{rerun}"
+std_opts = "--format #{ENV['CUCUMBER_FORMAT'] || 'pretty'} --strict --tags ~@wip"
+%>
+default: <%= std_opts %> features
+wip: --tags @wip:3 --wip features
+rerun: <%= rerun_opts %> --format rerun --out rerun.txt --strict --tags ~@wip
@@ -26,4 +26,7 @@
# This is necessary if your schema can't be completely dumped by the schema dumper,
# like if you have constraints or database-specific column types
# config.active_record.schema_format = :sql
+
+ # Send deprecation warnings to STDERR
+ config.active_support.deprecation = :stderr
end
View
@@ -17,7 +17,7 @@
match 'checkin/:id' => 'computers#checkin', :via => :post
# Make munki-client-friendly URLs
- match ':id.plist', :controller => 'computers', :action => 'show', :format => 'manifest', :id => /[A-Za-z0-9_\-\.%:]+/
+ match ':id.plist', :controller => 'computers', :action => 'show', :format => 'manifest', :id => /[A-Za-z0-9_\-\.%:]+/, :as => "computer_manifest"
match 'computers/:id.plist', :controller => 'computers', :action => 'show', :format => 'manifest', :id => /[A-Za-z0-9_\-\.%:]+/
match 'catalogs/:unit_id-:environment_name.plist' => 'catalogs#show', :format => 'plist'
@@ -0,0 +1,10 @@
+Feature: Munki client API
+
+A munki client uses this application to retrieve software updates.
+
+ Background:
+ Given a munki client
+
+ Scenario: Primary manifest
+ When the client requests its primary manifest
+ Then the client is given a valid manifest
@@ -0,0 +1,11 @@
+Given /^a munki client$/ do
+ @client = Factory.create(:computer)
+end
+
+When /^the client requests its primary manifest$/ do
+ visit computer_manifest_path(@client.mac_address)
+end
+
+Then /^the client is given a valid manifest$/ do
+ page.has_content? "managed_installs"
+end
View
@@ -0,0 +1,56 @@
+# IMPORTANT: This file is generated by cucumber-rails - edit at your own peril.
+# It is recommended to regenerate this file in the future when you upgrade to a
+# newer version of cucumber-rails. Consider adding your own code to a new file
+# instead of editing this one. Cucumber will automatically load all features/**/*.rb
+# files.
+
+require 'cucumber/rails'
+
+# Capybara defaults to XPath selectors rather than Webrat's default of CSS3. In
+# order to ease the transition to Capybara we set the default here. If you'd
+# prefer to use XPath just remove this line and adjust any selectors in your
+# steps to use the XPath syntax.
+Capybara.default_selector = :css
+
+# By default, any exception happening in your Rails application will bubble up
+# to Cucumber so that your scenario will fail. This is a different from how
+# your application behaves in the production environment, where an error page will
+# be rendered instead.
+#
+# Sometimes we want to override this default behaviour and allow Rails to rescue
+# exceptions and display an error page (just like when the app is running in production).
+# Typical scenarios where you want to do this is when you test your error pages.
+# There are two ways to allow Rails to rescue exceptions:
+#
+# 1) Tag your scenario (or feature) with @allow-rescue
+#
+# 2) Set the value below to true. Beware that doing this globally is not
+# recommended as it will mask a lot of errors for you!
+#
+ActionController::Base.allow_rescue = false
+
+# Remove/comment out the lines below if your app doesn't have a database.
+# For some databases (like MongoDB and CouchDB) you may need to use :truncation instead.
+begin
+ DatabaseCleaner.strategy = :transaction
+rescue NameError
+ raise "You need to add database_cleaner to your Gemfile (in the :test group) if you wish to use it."
+end
+
+# You may also want to configure DatabaseCleaner to use different strategies for certain features and scenarios.
+# See the DatabaseCleaner documentation for details. Example:
+#
+# Before('@no-txn,@selenium,@culerity,@celerity,@javascript') do
+# DatabaseCleaner.strategy = :truncation, {:except => %w[widgets]}
+# end
+#
+# Before('~@no-txn', '~@selenium', '~@culerity', '~@celerity', '~@javascript') do
+# DatabaseCleaner.strategy = :transaction
+# end
+#
+
+# Possible values are :truncation and :transaction
+# The :transaction strategy is faster, but might give you threading problems.
+# See https://github.com/cucumber/cucumber-rails/blob/master/features/choose_javascript_database_strategy.feature
+Cucumber::Rails::Database.javascript_strategy = :truncation
+
Oops, something went wrong.

0 comments on commit 039db3d

Please sign in to comment.