Commit 6707217

mo khan <mo@mokhan.ca>
2014-11-10 05:04:33
convert specs from old should to expect style.
1 parent a991dce
spec/controllers/application_controller_spec.rb
@@ -15,25 +15,25 @@ describe ApplicationController do
     before { get :index, {}, user_session_id: user_session.id }
 
     it "lets you continue to do whatever the heck you were trying to do" do
-      response.status.should == 200
+      expect(response.status).to eql(200)
     end
 
     it "loads the current user" do
-      assigns(:current_user).should == user
+      expect(assigns(:current_user)).to eql(user)
     end
   end
 
   context "when not signed in" do
     it "boots you out when their is no session_id" do
       get :index
-      response.should redirect_to(new_session_path)
+      expect(response).to redirect_to(new_session_path)
     end
 
     it "boots you out when the session id is not known" do
-      Session.stub(:find).with(100).and_raise(ActiveRecord::RecordNotFound)
+      allow(Session).to receive(:find).with(100).and_raise(ActiveRecord::RecordNotFound)
 
       get :index, {}, user_session_id: 100
-      response.should redirect_to(new_session_path)
+      expect(response).to redirect_to(new_session_path)
     end
   end
 end
spec/controllers/sessions_controller_spec.rb
@@ -4,7 +4,7 @@ describe SessionsController do
   describe "#new" do
     it "loads the login page" do
       get :new
-      response.should be_ok
+      expect(response).to be_ok
     end
   end
 
@@ -12,24 +12,24 @@ describe SessionsController do
     let(:user) { double(id: 1, authenticate: false) }
 
     before :each do
-      User.stub(:find_by).with(email: 'email@example.com').and_return(user)
-      User.stub(:find_by).with(email: 'unknown@example.com').and_return(nil)
-      user.stub(:authenticate).with('password').and_return(true)
+      allow(User).to receive(:find_by).with(email: 'email@example.com').and_return(user)
+      allow(User).to receive(:find_by).with(email: 'unknown@example.com').and_return(nil)
+      allow(user).to receive(:authenticate).with('password').and_return(true)
     end
 
     context "when the email and password is incorrect" do
       it "displays an error" do
         post :create, email: 'email@example.com', password: 'wrong'
-        flash[:error].should == I18n.translate(:invalid_credentials)
-        response.should render_template(:new)
+        expect(flash[:error]).to eql(I18n.translate(:invalid_credentials))
+        expect(response).to render_template(:new)
       end
     end
 
     context "when the email is not known" do
       it "displays an error" do
         post :create, email: 'unknown@example.com'
-        flash[:error].should == I18n.translate(:invalid_credentials)
-        response.should render_template(:new)
+        expect(flash[:error]).to eql(I18n.translate(:invalid_credentials))
+        expect(response).to render_template(:new)
       end
     end
 
@@ -39,14 +39,14 @@ describe SessionsController do
       end
 
       it "redirects to the dashboard" do
-        response.should redirect_to(root_path(anchor: ''))
+        expect(response).to redirect_to(root_path(anchor: ''))
       end
 
       it "creates a new session" do
-        session[:user_session_id].should_not be_nil
+        expect(session[:user_session_id]).to_not be_nil
         last_session = Session.last
-        session[:user_session_id].should == last_session.id
-        last_session.ip_address.should == "0.0.0.0"
+        expect(session[:user_session_id]).to eql(last_session.id)
+        expect(last_session.ip_address).to eql("0.0.0.0")
       end
     end
   end
@@ -56,8 +56,8 @@ describe SessionsController do
 
     it "removes the current session" do
       delete :destroy, { id: 'mine' }, { user_session_id: user_session.id }
-      session[:user_session_id].should be_nil
-      response.should redirect_to(new_session_path)
+      expect(session[:user_session_id]).to be_nil
+      expect(response).to redirect_to(new_session_path)
     end
   end
 end
spec/models/session_spec.rb
@@ -5,8 +5,8 @@ describe Session do
     it "creates a new session" do
       Session.create!(user_id: 1, ip_address: '127.0.0.1')
       session = Session.last
-      session.user_id.should == 1
-      session.ip_address.should == "127.0.0.1"
+      expect(session.user_id).to eql(1)
+      expect(session.ip_address).to eql("127.0.0.1")
     end
   end
 end
spec/models/user_spec.rb
@@ -4,7 +4,7 @@ describe User do
   context "#save" do
     it "can be saved" do
       User.create!(email: 'mo@mokhan.ca', password: 'password', password_confirmation: 'password')
-      User.count.should == 1
+      expect(User.count).to eql(1)
     end
   end
 
@@ -12,11 +12,11 @@ describe User do
     let(:user) { User.create!(email: 'blah@example.com', password: 'password', password_confirmation: 'password') }
 
     it "returns true when the password is correct" do
-      user.authenticate('password').should be_truthy
+      expect(user.authenticate('password')).to be_truthy
     end
 
     it "returns false when the password is incorrect" do
-      user.authenticate('wrong').should be_falsey
+      expect(user.authenticate('wrong')).to be_falsey
     end
   end
 end
spec/routing/root_routing_spec.rb
@@ -1,7 +1,7 @@
 require "rails_helper"
 
 describe '/' do
-  it "should route to the login page" do
+  it "routes to the login page" do
     expect(get: '/').to route_to(controller: 'dashboard', action: 'index')
   end
 end
spec/spec_helper.rb
@@ -40,7 +40,6 @@ RSpec.configure do |config|
 
 # The settings below are suggested to provide a good initial experience
 # with RSpec, but feel free to customize to your heart's content.
-=begin
   # These two settings work together to allow you to limit a spec run
   # to individual examples or groups you care about by tagging them with
   # `:focus` metadata. When nothing is tagged with `:focus`, all examples
@@ -53,7 +52,7 @@ RSpec.configure do |config|
   #   - http://myronmars.to/n/dev-blog/2012/06/rspecs-new-expectation-syntax
   #   - http://teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
   #   - http://myronmars.to/n/dev-blog/2014/05/notable-changes-in-rspec-3#new__config_option_to_disable_rspeccore_monkey_patching
-  config.disable_monkey_patching!
+  #config.disable_monkey_patching!
 
   # Many RSpec users commonly either run the entire suite or an individual
   # file, and it's useful to allow more verbose output when running an
@@ -81,5 +80,4 @@ RSpec.configure do |config|
   # test failures related to randomization by passing the same `--seed` value
   # as the one that triggered the failure.
   Kernel.srand config.seed
-=end
 end