diff --git a/.rspec b/.rspec new file mode 100644 index 000000000..4e1e0d2f7 --- /dev/null +++ b/.rspec @@ -0,0 +1 @@ +--color diff --git a/Gemfile b/Gemfile index 7cceb7aee..b494c5bc4 100644 --- a/Gemfile +++ b/Gemfile @@ -40,6 +40,12 @@ gem 'jquery-rails' # To use debugger # gem 'debugger' -# growstuff additions +# GROWSTUFF ADDITIONS BELOW HERE + +# user signup/login/etc gem 'devise' -gem 'rspec' + +# for testing +gem 'rspec-rails' +gem 'webrat' + diff --git a/Gemfile.lock b/Gemfile.lock index f356b9eb5..84cc991b5 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -61,6 +61,7 @@ GEM treetop (~> 1.4.8) mime-types (1.19) multi_json (1.3.6) + nokogiri (1.5.5) orm_adapter (0.4.0) polyglot (0.3.3) rack (1.4.1) @@ -96,6 +97,11 @@ GEM rspec-expectations (2.11.2) diff-lcs (~> 1.1.3) rspec-mocks (2.11.2) + rspec-rails (2.11.0) + actionpack (>= 3.0) + activesupport (>= 3.0) + railties (>= 3.0) + rspec (~> 2.11.0) sass (3.2.1) sass-rails (3.2.5) railties (~> 3.2.0) @@ -119,6 +125,10 @@ GEM multi_json (~> 1.3) warden (1.2.1) rack (>= 1.0) + webrat (0.7.3) + nokogiri (>= 1.2.0) + rack (>= 1.0) + rack-test (>= 0.5.3) PLATFORMS ruby @@ -129,8 +139,9 @@ DEPENDENCIES devise jquery-rails rails (= 3.2.8) - rspec + rspec-rails sass-rails (~> 3.2.3) sqlite3 therubyracer uglifier (>= 1.0.3) + webrat diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb new file mode 100644 index 000000000..88492529f --- /dev/null +++ b/spec/spec_helper.rb @@ -0,0 +1,39 @@ +# 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 = true + + # 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" + +end diff --git a/spec/support/devise.rb b/spec/support/devise.rb new file mode 100644 index 000000000..5d898b4d3 --- /dev/null +++ b/spec/support/devise.rb @@ -0,0 +1,4 @@ +RSpec.configure do |config| + config.include Devise::TestHelpers, :type => :controller + config.include Devise::TestHelpers, :type => :view +end diff --git a/spec/view/index_spec.rb b/spec/view/index_spec.rb new file mode 100644 index 000000000..a396c0bcb --- /dev/null +++ b/spec/view/index_spec.rb @@ -0,0 +1,17 @@ +require 'spec_helper' + +describe 'home/index.html.erb', :type => "view" do + context "when not logged in" do + + before(:each) do + view.stub(:user_signed_in).and_return(false) + view.stub(:current_user).and_return(nil) + end + + it 'shows the homepage' do + render + rendered.should contain 'Growstuff' + end + + end +end diff --git a/test/test_helper.rb b/test/test_helper.rb index 8bf1192ff..7a1aa565f 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -10,4 +10,8 @@ class ActiveSupport::TestCase fixtures :all # Add more helper methods to be used by all tests here... + + class ActionController::TestCase + include Devise::TestHelpers + end end