Skip to content

Instantly share code, notes, and snippets.

@cupakromer
Last active December 26, 2015 08:09
Show Gist options
  • Save cupakromer/7120458 to your computer and use it in GitHub Desktop.
Save cupakromer/7120458 to your computer and use it in GitHub Desktop.
Controller test with shared example
require 'spec_helper'
describe DashboardController do
include Factories::Godzilla
shared_examples "successfully gets the session cards" do
it "is successful" do
get :session_cards
expect(response).to be_success
end
it "renders no layout" do
get :session_cards
expect(response).to have_rendered layout: false
end
it "renders the card template" do
get :session_cards
expect(response).to have_rendered :session_cards
end
end
context "with no active sessions" do
before do
allow(DeviceSession).to receive(:active_by_company).and_return({})
end
has_behavior "successfully gets the session cards" do
it "assigns no company sessions" do
get :session_cards
expect(assigns(:company_sessions)).to eq Hash.new
end
end
end
context "with active sessions" do
let(:active) { double(Hash) }
before do
allow(DeviceSession).to receive(:active_by_company).and_return(active)
end
has_behavior "successfully gets the session cards" do
it "assigns no company sessions" do
get :session_cards
expect(assigns(:company_sessions)).to eq active
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment