From b3452990030674c2e805634bd3408d1202fd0ba1 Mon Sep 17 00:00:00 2001 From: Vitor Bittencourt Date: Sun, 19 Apr 2015 00:59:17 -0300 Subject: [PATCH] Fixing some specs --- Gemfile | 1 + Gemfile.lock | 5 +++++ config/environments/development.rb | 2 ++ config/environments/test.rb | 1 + spec/requests/admin/dashboard_spec.rb | 20 +++++++++++-------- spec/spec_helper.rb | 11 ++-------- spec/support/spec_support.rb | 1 + spec/views/admin/sites/edit.html.erb_spec.rb | 7 +++---- spec/views/admin/sites/index.html.erb_spec.rb | 8 ++++---- spec/views/admin/sites/new.html.erb_spec.rb | 7 +++---- spec/views/admin/sites/show.html.erb_spec.rb | 2 +- 11 files changed, 35 insertions(+), 30 deletions(-) diff --git a/Gemfile b/Gemfile index fcf57abd..f28d4d9f 100644 --- a/Gemfile +++ b/Gemfile @@ -45,6 +45,7 @@ end group :development, :test do gem 'pry' gem 'rspec-rails', '~> 3.0.0' + gem 'rspec-activemodel-mocks' # for compatibility gem 'capybara', '~> 2.2.0', :require => false gem 'capybara-webkit', :require => false gem 'database_cleaner', :require => false diff --git a/Gemfile.lock b/Gemfile.lock index 9c0c3d0c..e84a8c27 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -144,6 +144,10 @@ GEM ffi (>= 0.5.0) responders (1.1.2) railties (>= 3.2, < 4.2) + rspec-activemodel-mocks (1.0.1) + activemodel (>= 3.0) + activesupport (>= 3.0) + rspec-mocks (>= 2.99, < 4.0) rspec-core (3.0.4) rspec-support (~> 3.0.0) rspec-expectations (3.0.4) @@ -219,6 +223,7 @@ DEPENDENCIES pry rack rails (~> 4.0.0) + rspec-activemodel-mocks rspec-rails (~> 3.0.0) sass-rails schema_plus diff --git a/config/environments/development.rb b/config/environments/development.rb index 0255d3f7..000648ad 100644 --- a/config/environments/development.rb +++ b/config/environments/development.rb @@ -28,4 +28,6 @@ # Raise exception on mass assignment protection for Active Record models #config.active_record.mass_assignment_sanitizer = :strict + + Rails.application.routes.default_url_options = { :host => 'localhost' } end diff --git a/config/environments/test.rb b/config/environments/test.rb index e29e3d55..b0317645 100644 --- a/config/environments/test.rb +++ b/config/environments/test.rb @@ -36,6 +36,7 @@ # Print deprecation notices to the stderr config.active_support.deprecation = :stderr + Rails.application.routes.default_url_options = { :host => 'test.host' } # Raise exception on mass assignment protection for Active Record models #config.active_record.mass_assignment_sanitizer = :strict end diff --git a/spec/requests/admin/dashboard_spec.rb b/spec/requests/admin/dashboard_spec.rb index 7bba5fe4..1dc30867 100644 --- a/spec/requests/admin/dashboard_spec.rb +++ b/spec/requests/admin/dashboard_spec.rb @@ -7,19 +7,23 @@ visit root_path page.should have_content("Let's setup an administrator account first!") end - + it "offers to setup a site if the logged in user doesn't have any" do - login(admin) visit root_path page.should have_content("Let's get started!") page.should have_content("So you want to embed comments on a bunch of web pages.") end - - it "redirects to the sites page if the user is logged in, there are administrators and the current user has sites" do - FactoryGirl.create(:site1, :user => admin) - login(admin) - visit root_path - current_url.should == admin_sites_url + + context 'when logged in as an admin' do + before do |example| + FactoryGirl.create(:site1, :user => admin) + login(admin) + end + + it "redirects to the sites page if the user is logged in, there are administrators and the current user has sites" do + visit root_path + current_url.should == admin_sites_url + end end end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 53c3d976..6e6a2548 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -28,16 +28,9 @@ config.include Devise::TestHelpers, :type => :view config.include Capybara::DSL config.include Rails.application.routes.url_helpers - - # == 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 + config.mock_with :rspec - + config.before(:each) do DatabaseCleaner.start end diff --git a/spec/support/spec_support.rb b/spec/support/spec_support.rb index 7f5cdcd5..a0f238ee 100644 --- a/spec/support/spec_support.rb +++ b/spec/support/spec_support.rb @@ -1,5 +1,6 @@ module SpecSupport def login(user) + binding.pry if example.metadata[:type] == :request visit("/test/login?user_id=#{user.id}") page.should have_content("ok") diff --git a/spec/views/admin/sites/edit.html.erb_spec.rb b/spec/views/admin/sites/edit.html.erb_spec.rb index 7768d03b..546940e9 100644 --- a/spec/views/admin/sites/edit.html.erb_spec.rb +++ b/spec/views/admin/sites/edit.html.erb_spec.rb @@ -1,11 +1,10 @@ require File.expand_path(File.dirname(__FILE__) + "/../../../spec_helper") -describe "admin/sites/edit.html.erb" do - before(:each) do - @site = assign(:site, stub_model(Site)) - end +describe "admin/sites/edit.html.erb", type: :view do it "renders the edit site form" do + @site = assign(:site, stub_model(Site)) + render # Run the generator again with the --webrat flag if you want to use webrat matchers diff --git a/spec/views/admin/sites/index.html.erb_spec.rb b/spec/views/admin/sites/index.html.erb_spec.rb index a28bc64b..aec36116 100644 --- a/spec/views/admin/sites/index.html.erb_spec.rb +++ b/spec/views/admin/sites/index.html.erb_spec.rb @@ -1,15 +1,15 @@ require File.expand_path(File.dirname(__FILE__) + "/../../../spec_helper") -describe "admin/sites/index.html.erb" do +describe "admin/sites/index.html.erb", type: :view do before(:each) do sign_in(kotori) + end + + it "renders a list of sites" do assign(:sites, [ FactoryGirl.create(:site1, :user => kotori), FactoryGirl.create(:site2, :user => kotori) ]) - end - - it "renders a list of sites" do render end end diff --git a/spec/views/admin/sites/new.html.erb_spec.rb b/spec/views/admin/sites/new.html.erb_spec.rb index aca79e29..1de806c6 100644 --- a/spec/views/admin/sites/new.html.erb_spec.rb +++ b/spec/views/admin/sites/new.html.erb_spec.rb @@ -1,11 +1,10 @@ require File.expand_path(File.dirname(__FILE__) + "/../../../spec_helper") -describe "admin/sites/new.html.erb" do - before(:each) do - assign(:site, stub_model(Site).as_new_record) - end +describe "admin/sites/new.html.erb", type: :view do it "renders new site form" do + assign(:site, stub_model(Site).as_new_record) + render # Run the generator again with the --webrat flag if you want to use webrat matchers diff --git a/spec/views/admin/sites/show.html.erb_spec.rb b/spec/views/admin/sites/show.html.erb_spec.rb index ae0e341f..6ff434b7 100644 --- a/spec/views/admin/sites/show.html.erb_spec.rb +++ b/spec/views/admin/sites/show.html.erb_spec.rb @@ -1,6 +1,6 @@ require File.expand_path(File.dirname(__FILE__) + "/../../../spec_helper") -describe "admin/sites/show.html.erb" do +describe "admin/sites/show.html.erb", type: :view do before(:each) do sign_in(kotori) @site = assign(:site, FactoryGirl.create(:site1, :user => kotori))