From 5dc44046e1fee83dc899bd27051e0ac51c750ffa Mon Sep 17 00:00:00 2001 From: Nina R Date: Sun, 29 Jan 2012 23:57:52 -0800 Subject: [PATCH] added capybara, guard and create part of the user flow integration test --- .gitignore | 3 ++ Gemfile | 10 +++--- Gemfile.lock | 12 ++++++++ Guardfile | 19 ++++++++++++ spec/factories.rb | 4 +++ spec/requests/users_spec.rb | 61 +++++++++++++++++++++++++++++++++++++ spec/spec_helper.rb | 11 ++++++- 7 files changed, 115 insertions(+), 5 deletions(-) create mode 100644 Guardfile create mode 100644 spec/factories.rb create mode 100644 spec/requests/users_spec.rb diff --git a/.gitignore b/.gitignore index eb3489a98..d79801ea2 100644 --- a/.gitignore +++ b/.gitignore @@ -13,3 +13,6 @@ # Ignore all logfiles and tempfiles. /log/*.log /tmp + +# Ignore Rubymine created folder +.idea diff --git a/Gemfile b/Gemfile index b580eb952..f6d25f483 100644 --- a/Gemfile +++ b/Gemfile @@ -30,9 +30,11 @@ gem 'jquery-rails' # To use debugger # gem 'ruby-debug19', :require => 'ruby-debug' -group :development, :test do - gem 'rspec-rails' +gem 'rspec-rails', :group => [:development, :test] +group :test do + gem "factory_girl_rails" gem 'capybara' - gem 'launchy' - gem 'database_cleaner' + gem "guard-rspec" + gem "launchy" + gem "database_cleaner" end diff --git a/Gemfile.lock b/Gemfile.lock index 6f9cea577..08939f6a0 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -58,7 +58,17 @@ GEM erubis (2.7.0) execjs (1.2.13) multi_json (~> 1.0) + factory_girl (2.5.0) + activesupport + factory_girl_rails (1.6.0) + factory_girl (~> 2.5.0) + railties (>= 3.0.0) ffi (1.0.11) + guard (1.0.0) + ffi (>= 0.5.0) + thor (~> 0.14.6) + guard-rspec (0.6.0) + guard (>= 0.10.0) hike (1.2.1) i18n (0.6.0) jquery-rails (1.0.19) @@ -155,6 +165,8 @@ DEPENDENCIES coffee-rails (~> 3.1.1) database_cleaner devise + factory_girl_rails + guard-rspec jquery-rails launchy rails (= 3.1.3) diff --git a/Guardfile b/Guardfile new file mode 100644 index 000000000..f4b0e6870 --- /dev/null +++ b/Guardfile @@ -0,0 +1,19 @@ +# 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" } +end + diff --git a/spec/factories.rb b/spec/factories.rb new file mode 100644 index 000000000..829b83f17 --- /dev/null +++ b/spec/factories.rb @@ -0,0 +1,4 @@ +Factory.define :user do |f| + f.sequence(:email) { |n| "example0#{n}@example.com"} + f.password "test123" +end \ No newline at end of file diff --git a/spec/requests/users_spec.rb b/spec/requests/users_spec.rb new file mode 100644 index 000000000..c1a450a9a --- /dev/null +++ b/spec/requests/users_spec.rb @@ -0,0 +1,61 @@ +require 'spec_helper' + +describe "existing user", :js => true do + + before(:each) do + @user = Factory(:user) + @user.confirm! + + @event = Factory(:event) + + end + + it "should signin and edit his/her settings" do + visit new_user_session_path + + fill_in "Email", :with => @user.email + fill_in "Password", :with => @user.password + click_button "Sign in" + + page.should have_content("Signed in successfully") + + page.should have_content("Become Volunteer") + + click_link "Become A Volunteer" + + page.should have_content("specify your skills") + + check("Coordinating") + check("Teaching") + check("TAing") + check("Mentoring") + check("Childcaring") + check("Writing") + page.should have_content("Evangelizing") + page.should have_content("Other") + + click_button "Submit" + + page.should have_content("Thanks for submitting your skills") + + @user.skills.should == ["Coordinating", "Teaching", "TAing", "Mentoring", "Hacking", "Designing", "Childcaring", "Writing"] + + page.should have_content("Update your skills") + + click_link "Update your skills" + + page.should have_content("specify your skills") + + uncheck("Hacking") + uncheck("Designing") + + click_button "Submit" + + page.should have_content("Thanks for submitting your skills") + + @user.skills.should == ["Coordinating", "Teaching", "TAing", "Mentoring", "Childcaring", "Writing"] + + + end + +end \ No newline at end of file diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index ba8698277..00ee7c523 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -2,7 +2,6 @@ ENV["RAILS_ENV"] ||= 'test' require File.expand_path("../../config/environment", __FILE__) require 'rspec/rails' -require 'rspec/autorun' require 'capybara/rspec' # Requires supporting ruby files with custom matchers and macros, etc, @@ -10,6 +9,11 @@ Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f} RSpec.configure do |config| + + #Uncomment if need to write tests using devise helpers + #config.include Devise::TestHelpers, :type => :controller + #config.extend ControllerMacros, :type => :controller + # ## Mock Framework # # If you prefer to use mocha, flexmock or RR, uncomment the appropriate line: @@ -35,6 +39,11 @@ DatabaseCleaner.clean end + config.mock_with :rspec + #config.use_transactional_fixtures = true + + Rails.application.routes.default_url_options[:host] = 'localhost:3000' + # If true, the base class of anonymous controllers will be inferred # automatically. This will be the default behavior in future versions of # rspec-rails.