Skip to content

Commit

Permalink
Updated specs to rspec 2.14
Browse files Browse the repository at this point in the history
  • Loading branch information
steveyken committed Aug 13, 2013
1 parent da75a34 commit 229d713
Show file tree
Hide file tree
Showing 23 changed files with 180 additions and 170 deletions.
11 changes: 11 additions & 0 deletions custom_plan.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
require 'zeus/rails'

class CustomPlan < Zeus::Rails

# def my_custom_command
# # see https://github.com/burke/zeus/blob/master/docs/ruby/modifying.md
# end

end

Zeus.plan = CustomPlan.new
2 changes: 1 addition & 1 deletion spec/controllers/admin/users_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@

xhr :delete, :destroy, :id => @user.id
flash[:warning].should_not == nil
lambda { User.find(@user) }.should_not raise_error(ActiveRecord::RecordNotFound)
expect { User.find(@user) }.not_to raise_error()
response.should render_template("admin/users/destroy")
end
end
Expand Down
4 changes: 2 additions & 2 deletions spec/controllers/applications_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

it "should return [6, 9] when related is 'campaigns/7'" do
controller.stub(:controller_name).and_return('opportunities')
campaign = mock(Campaign, :opportunities => [mock(:id => 6), mock(:id => 9)])
campaign = double(Campaign, :opportunities => [double(:id => 6), double(:id => 9)])
Campaign.should_receive(:find_by_id).with('7').and_return(campaign)
controller.send(:auto_complete_ids_to_exclude, 'campaigns/7').sort.should == [6, 9]
end
Expand All @@ -35,7 +35,7 @@

it "should return [] when related object association is not found" do
controller.stub(:controller_name).and_return('not_a_method_that_exists')
campaign = mock(Campaign)
campaign = double(Campaign)
Campaign.should_receive(:find_by_id).with('7').and_return(campaign)
controller.send(:auto_complete_ids_to_exclude, 'campaigns/7').should == []
end
Expand Down
2 changes: 1 addition & 1 deletion spec/controllers/authentications_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
describe "POST authentications" do
before(:each) do
@login = { :username => "user", :password => "pass", :remember_me => "0" }
@authentication = mock(Authentication, @login)
@authentication = double(Authentication, @login)
end

describe "successful authentication " do
Expand Down
4 changes: 2 additions & 2 deletions spec/controllers/entities/accounts_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ def get_data_for_sidebar

describe "with mime type of JSON" do
it "should render all accounts as json" do
@controller.should_receive(:get_accounts).and_return(accounts = mock("Array of Accounts"))
@controller.should_receive(:get_accounts).and_return(accounts = double("Array of Accounts"))
accounts.should_receive(:to_json).and_return("generated JSON")

request.env["HTTP_ACCEPT"] = "application/json"
Expand All @@ -107,7 +107,7 @@ def get_data_for_sidebar

describe "with mime type of XML" do
it "should render all accounts as xml" do
@controller.should_receive(:get_accounts).and_return(accounts = mock("Array of Accounts"))
@controller.should_receive(:get_accounts).and_return(accounts = double("Array of Accounts"))
accounts.should_receive(:to_xml).and_return("generated XML")

request.env["HTTP_ACCEPT"] = "application/xml"
Expand Down
4 changes: 2 additions & 2 deletions spec/controllers/entities/contacts_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@

describe "with mime type of JSON" do
it "should render all contacts as JSON" do
@controller.should_receive(:get_contacts).and_return(contacts = mock("Array of Contacts"))
@controller.should_receive(:get_contacts).and_return(contacts = double("Array of Contacts"))
contacts.should_receive(:to_json).and_return("generated JSON")

request.env["HTTP_ACCEPT"] = "application/json"
Expand All @@ -81,7 +81,7 @@

describe "with mime type of XML" do
it "should render all contacts as xml" do
@controller.should_receive(:get_contacts).and_return(contacts = mock("Array of Contacts"))
@controller.should_receive(:get_contacts).and_return(contacts = double("Array of Contacts"))
contacts.should_receive(:to_xml).and_return("generated XML")

request.env["HTTP_ACCEPT"] = "application/xml"
Expand Down
4 changes: 2 additions & 2 deletions spec/controllers/entities/leads_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@

describe "with mime type of JSON" do
it "should render all leads as JSON" do
@controller.should_receive(:get_leads).and_return(leads = mock("Array of Leads"))
@controller.should_receive(:get_leads).and_return(leads = double("Array of Leads"))
leads.should_receive(:to_json).and_return("generated JSON")

request.env["HTTP_ACCEPT"] = "application/json"
Expand All @@ -106,7 +106,7 @@

describe "with mime type of XML" do
it "should render all leads as xml" do
@controller.should_receive(:get_leads).and_return(leads = mock("Array of Leads"))
@controller.should_receive(:get_leads).and_return(leads = double("Array of Leads"))
leads.should_receive(:to_xml).and_return("generated XML")

request.env["HTTP_ACCEPT"] = "application/xml"
Expand Down
6 changes: 3 additions & 3 deletions spec/controllers/entities/opportunities_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ def get_data_for_sidebar

describe "with mime type of JSON" do
it "should render all opportunities as JSON" do
@controller.should_receive(:get_opportunities).and_return(opportunities = mock("Array of Opportunities"))
@controller.should_receive(:get_opportunities).and_return(opportunities = double("Array of Opportunities"))
opportunities.should_receive(:to_json).and_return("generated JSON")

request.env["HTTP_ACCEPT"] = "application/json"
Expand All @@ -110,7 +110,7 @@ def get_data_for_sidebar

describe "with mime type of JSON" do
it "should render all opportunities as JSON" do
@controller.should_receive(:get_opportunities).and_return(opportunities = mock("Array of Opportunities"))
@controller.should_receive(:get_opportunities).and_return(opportunities = double("Array of Opportunities"))
opportunities.should_receive(:to_json).and_return("generated JSON")

request.env["HTTP_ACCEPT"] = "application/json"
Expand All @@ -121,7 +121,7 @@ def get_data_for_sidebar

describe "with mime type of XML" do
it "should render all opportunities as xml" do
@controller.should_receive(:get_opportunities).and_return(opportunities = mock("Array of Opportunities"))
@controller.should_receive(:get_opportunities).and_return(opportunities = double("Array of Opportunities"))
opportunities.should_receive(:to_xml).and_return("generated XML")

request.env["HTTP_ACCEPT"] = "application/xml"
Expand Down
4 changes: 2 additions & 2 deletions spec/controllers/home_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,8 @@
describe "activity_user" do

before(:each) do
@user = mock(User, :id => 1, :is_a? => true)
@cur_user = mock(User)
@user = double(User, :id => 1, :is_a? => true)
@cur_user = double(User)
end

it "should find a user by email" do
Expand Down
4 changes: 2 additions & 2 deletions spec/controllers/tasks_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ def produce_tasks(user, view)
TASK_STATUSES.each do |view|

it "should render the requested task as JSON for #{view} view" do
Task.stub_chain(:tracked_by, :find).and_return(task = mock("Task"))
Task.stub_chain(:tracked_by, :find).and_return(task = double("Task"))
task.should_receive(:to_json).and_return("generated JSON")

request.env["HTTP_ACCEPT"] = "application/json"
Expand All @@ -129,7 +129,7 @@ def produce_tasks(user, view)
end

it "should render the requested task as xml for #{view} view" do
Task.stub_chain(:tracked_by, :find).and_return(task = mock("Task"))
Task.stub_chain(:tracked_by, :find).and_return(task = double("Task"))
task.should_receive(:to_xml).and_return("generated XML")

request.env["HTTP_ACCEPT"] = "application/xml"
Expand Down
4 changes: 2 additions & 2 deletions spec/controllers/users_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
end

it "should render the requested user as JSON" do
User.should_receive(:find).and_return(user = mock("User"))
User.should_receive(:find).and_return(user = double("User"))
user.should_receive(:to_json).and_return("generated JSON")

get :show, :id => 42
Expand All @@ -56,7 +56,7 @@
end

it "should render the requested user as XML" do
User.should_receive(:find).and_return(user = mock("User"))
User.should_receive(:find).and_return(user = double("User"))
user.should_receive(:to_xml).and_return("generated XML")

get :show, :id => 42
Expand Down
58 changes: 29 additions & 29 deletions spec/lib/fields_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,82 +21,82 @@ class Bar
it do
Foo.new.should respond_to(:field_groups)
end

it do
Foo.should respond_to(:serialize_custom_fields!)
end

it do
Foo.should respond_to(:fields)
end

it "calling has_fields should invoke serialize_custom_fields!" do
Bar.should_receive(:serialize_custom_fields!)
Bar.has_fields
end

describe "field_groups" do

it "should call FieldGroup" do
ActiveRecord::Base.connection.should_receive(:table_exists?).with('field_groups').and_return(true)
dummy_scope = mock
dummy_scope = double
dummy_scope.should_receive(:order).with(:position)
FieldGroup.should_receive(:where).and_return(dummy_scope)
Foo.new.field_groups
end

it "should not call FieldGroup if table doesn't exist (migrations not yet run)" do
ActiveRecord::Base.connection.should_receive(:table_exists?).with('field_groups').and_return(false)
Foo.new.field_groups.should == []
end

end

describe "fields" do

before(:each) do
@f1 = mock(Field)
@f2 = mock(Field)
@f3 = mock(Field)
@field_groups = [mock(FieldGroup, :fields => [@f1, @f2]), mock(FieldGroup, :fields => [@f3])]
@f1 = double(Field)
@f2 = double(Field)
@f3 = double(Field)
@field_groups = [double(FieldGroup, :fields => [@f1, @f2]), double(FieldGroup, :fields => [@f3])]
end

it "should convert field_groups into a flattened list of fields" do
Foo.should_receive(:field_groups).and_return(@field_groups)
Foo.fields.should == [@f1, @f2, @f3]
end

end

describe "serialize_custom_fields!" do

before(:each) do
@f1 = mock(Field, :as => 'check_boxes', :name => 'field1')
@f2 = mock(Field, :as => 'date', :name => 'field2')
@f1 = double(Field, :as => 'check_boxes', :name => 'field1')
@f2 = double(Field, :as => 'date', :name => 'field2')
end

it "should serialize checkbox fields as Array" do
Foo.stub(:serialized_attributes).and_return( {:field1 => @f1, :field2 => @f2} )
Foo.should_receive(:fields).and_return([@f1, @f2])
Foo.should_receive(:serialize).with(:field1, Array)
Foo.serialize_custom_fields!
end

end

it "should validate custom fields" do
foo = Foo.new
foo.should_receive(:custom_fields_validator)
foo.should be_valid
end

describe "custom_fields_validator" do

before(:each) do
@f1 = mock(Field)
@field_groups = [ mock(FieldGroup, :fields => [@f1]) ]
@f1 = double(Field)
@field_groups = [ double(FieldGroup, :fields => [@f1]) ]
end

it "should call custom_validator on each custom field" do
foo = Foo.new
@f1.should_receive(:custom_validator).with(foo)
Expand All @@ -105,5 +105,5 @@ class Bar
end

end

end
8 changes: 4 additions & 4 deletions spec/lib/mail_processor/base_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
describe "Discarding a message" do
before(:each) do
mock_connect
@uid = mock
@uid = double
@crawler.send(:connect!)
end

Expand All @@ -90,7 +90,7 @@
describe "Archiving a message" do
before(:each) do
mock_connect
@uid = mock
@uid = double
@crawler.send(:connect!)
end

Expand All @@ -112,7 +112,7 @@
#------------------------------------------------------------------------------
describe "Validating email" do
before(:each) do
@email = mock
@email = double
end

it "should be valid email if its contents type is text/plain" do
Expand All @@ -130,7 +130,7 @@
describe "Finding email sender among users" do
before(:each) do
@from = [ "[email protected]", "[email protected]" ]
@email = mock
@email = double
@email.stub(:from).and_return(@from)
end

Expand Down
2 changes: 1 addition & 1 deletion spec/models/entities/opportunity_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@

it "should be possible to create opportunity with the same name" do
first = FactoryGirl.create(:opportunity, :name => "Hello", :user => current_user)
lambda { FactoryGirl.create(:opportunity, :name => "Hello", :user => current_user) }.should_not raise_error(ActiveRecord::RecordInvalid)
expect { FactoryGirl.create(:opportunity, :name => "Hello", :user => current_user) }.to_not raise_error()
end

it "have a default stage" do
Expand Down
Loading

0 comments on commit 229d713

Please sign in to comment.