From 8fc341323414e1b79aa60332453a878135f1d1bf Mon Sep 17 00:00:00 2001 From: Cody Cutrer Date: Tue, 25 Jul 2017 16:06:35 -0600 Subject: [PATCH] spec: mocha => rspec-mocks for helpers Change-Id: I1666114ca3fca4346d1c4faddf59d59f4355e391 Reviewed-on: https://gerrit.instructure.com/120502 Tested-by: Jenkins Reviewed-by: Rob Orton Product-Review: Cody Cutrer QA-Review: Cody Cutrer --- spec/helpers/application_helper_spec.rb | 76 +++++++++---------- spec/helpers/attachment_helper_spec.rb | 4 +- spec/helpers/avatar_helper_spec.rb | 8 +- spec/helpers/collaborations_helper_spec.rb | 54 ++++++------- .../context_external_tools_helper_spec.rb | 4 +- spec/helpers/context_modules_helper_spec.rb | 22 +++--- spec/helpers/courses_helper_spec.rb | 12 +-- spec/helpers/login/canvas_helper_spec.rb | 4 +- spec/helpers/quizzes_helper_spec.rb | 54 ++++++------- spec/helpers/section_tab_helper_spec.rb | 8 +- spec/helpers/syllabus_helper_spec.rb | 4 +- 11 files changed, 125 insertions(+), 125 deletions(-) diff --git a/spec/helpers/application_helper_spec.rb b/spec/helpers/application_helper_spec.rb index 49cdae4ba4687..bf734912941bd 100644 --- a/spec/helpers/application_helper_spec.rb +++ b/spec/helpers/application_helper_spec.rb @@ -103,17 +103,17 @@ describe '#context_sensitive_datetime_title' do it "produces a string showing the local time and the course time" do - context = stub(time_zone: ActiveSupport::TimeZone["America/Denver"]) + context = double(time_zone: ActiveSupport::TimeZone["America/Denver"]) expect(context_sensitive_datetime_title(Time.now, context)).to eq "data-tooltip data-html-tooltip-title=\"Local: Mar 13 at 1:12am
Course: Mar 13 at 3:12am\"" end it "only prints the text if just_text option passed" do - context = stub(time_zone: ActiveSupport::TimeZone["America/Denver"]) + context = double(time_zone: ActiveSupport::TimeZone["America/Denver"]) expect(context_sensitive_datetime_title(Time.now, context, just_text: true)).to eq "Local: Mar 13 at 1:12am
Course: Mar 13 at 3:12am" end it "uses the simple title if theres no timezone difference" do - context = stub(time_zone: ActiveSupport::TimeZone["America/Anchorage"]) + context = double(time_zone: ActiveSupport::TimeZone["America/Anchorage"]) expect(context_sensitive_datetime_title(Time.now, context, just_text: true)).to eq "Mar 13 at 1:12am" expect(context_sensitive_datetime_title(Time.now, context)).to eq "data-tooltip data-html-tooltip-title=\"Mar 13 at 1:12am\"" end @@ -124,14 +124,14 @@ it 'crosses date boundaries appropriately' do Timecop.freeze(Time.utc(2013,3,13,7,12)) do - context = stub(time_zone: ActiveSupport::TimeZone["America/Denver"]) + context = double(time_zone: ActiveSupport::TimeZone["America/Denver"]) expect(context_sensitive_datetime_title(Time.now, context)).to eq "data-tooltip data-html-tooltip-title=\"Local: Mar 12 at 11:12pm
Course: Mar 13 at 1:12am\"" end end end describe '#friendly_datetime' do - let(:context) { stub(time_zone: ActiveSupport::TimeZone["America/Denver"]) } + let(:context) { double(time_zone: ActiveSupport::TimeZone["America/Denver"]) } it 'spits out a friendly time tag' do tag = friendly_datetime(Time.now) @@ -229,21 +229,21 @@ def set_up_subaccounts context "with no custom css" do it "should be empty" do - helper.stubs(:active_brand_config).returns(nil) + allow(helper).to receive(:active_brand_config).and_return(nil) expect(helper.include_account_css).to be_nil end end context "with custom css" do it "should include account css" do - helper.stubs(:active_brand_config).returns BrandConfig.create!(css_overrides: 'https://example.com/path/to/overrides.css') + allow(helper).to receive(:active_brand_config).and_return BrandConfig.create!(css_overrides: 'https://example.com/path/to/overrides.css') output = helper.include_account_css expect(output).to have_tag 'link' expect(output).to match %r{https://example.com/path/to/overrides.css} end it "should include site_admin css even if there is no active brand" do - helper.stubs(:active_brand_config).returns nil + allow(helper).to receive(:active_brand_config).and_return nil Account.site_admin.create_brand_config!({ css_overrides: 'https://example.com/site_admin/account.css', js_overrides: 'https://example.com/site_admin/account.js' @@ -255,7 +255,7 @@ def set_up_subaccounts it "should not include anything if param is set to 0" do - helper.stubs(:active_brand_config).returns BrandConfig.create!(css_overrides: 'https://example.com/path/to/overrides.css') + allow(helper).to receive(:active_brand_config).and_return BrandConfig.create!(css_overrides: 'https://example.com/path/to/overrides.css') params[:global_includes] = '0' output = helper.include_account_css @@ -338,20 +338,20 @@ def set_up_subaccounts context "with no custom js" do it "should be empty" do - helper.stubs(:active_brand_config).returns(nil) + allow(helper).to receive(:active_brand_config).and_return(nil) expect(helper.include_account_js).to be_nil end end context "with custom js" do it "should include account javascript" do - helper.stubs(:active_brand_config).returns BrandConfig.create!(js_overrides: 'https://example.com/path/to/overrides.js') + allow(helper).to receive(:active_brand_config).and_return BrandConfig.create!(js_overrides: 'https://example.com/path/to/overrides.js') output = helper.include_account_js expect(output).to have_tag 'script', text: %r{https:\\/\\/example.com\\/path\\/to\\/overrides.js} end it "should include site_admin javascript even if there is no active brand" do - helper.stubs(:active_brand_config).returns nil + allow(helper).to receive(:active_brand_config).and_return nil Account.site_admin.create_brand_config!({ css_overrides: 'https://example.com/site_admin/account.css', js_overrides: 'https://example.com/site_admin/account.js' @@ -529,7 +529,7 @@ def set_up_subaccounts tool = @course.context_external_tools.new(:name => "bob", :consumer_key => "test", :shared_secret => "secret", :url => "http://example.com") tool.editor_button = {:url => "http://example.com", :icon_url => "http://example.com", :canvas_icon_class => 'icon-commons'} tool.save! - controller.stubs(:group_external_tool_path).returns('http://dummy') + allow(controller).to receive(:group_external_tool_path).and_return('http://dummy') @context = @course expect(editor_buttons).to eq([{:name=>"bob", :id=>tool.id, :url=>"http://example.com", :icon_url=>"http://example.com", :canvas_icon_class => 'icon-commons', :width=>800, :height=>400}]) @@ -555,7 +555,7 @@ def set_up_subaccounts describe "UI path checking" do describe "#active_path?" do context "when the request path is the course show page" do - let(:request){ stub('request', :fullpath => '/courses/2')} + let(:request){ double('request', :fullpath => '/courses/2')} it "returns true for paths that match" do expect(active_path?('/courses')).to be_truthy @@ -571,11 +571,11 @@ def set_up_subaccounts end context "when the request path is the account external tools path" do - let(:request){ stub('request', :fullpath => '/accounts/2/external_tools/27')} + let(:request){ double('request', :fullpath => '/accounts/2/external_tools/27')} before :each do @context = Account.default - controller.stubs(:controller_name).returns('external_tools') + allow(controller).to receive(:controller_name).and_return('external_tools') end it "it doesn't return true for '/accounts'" do @@ -584,11 +584,11 @@ def set_up_subaccounts end context "when the request path is the course external tools path" do - let(:request){ stub('request', :fullpath => '/courses/2/external_tools/27')} + let(:request){ double('request', :fullpath => '/courses/2/external_tools/27')} before :each do @context = Account.default.courses.create! - controller.stubs(:controller_name).returns('external_tools') + allow(controller).to receive(:controller_name).and_return('external_tools') end it "returns true for '/courses'" do @@ -619,14 +619,14 @@ def set_up_subaccounts end it "returns 'K12 Theme' by default for a k12 school" do - helper.stubs(:k12?).returns(true) - BrandConfig.stubs(:k12_config) + allow(helper).to receive(:k12?).and_return(true) + allow(BrandConfig).to receive(:k12_config) expect(helper.send(:active_brand_config)).to eq BrandConfig.k12_config end it "returns 'K12 Theme' if a k12 school has chosen 'canvas default' in Theme Editor" do - helper.stubs(:k12?).returns(true) - BrandConfig.stubs(:k12_config) + allow(helper).to receive(:k12?).and_return(true) + allow(BrandConfig).to receive(:k12_config) # this is what happens if you pick "Canvas Default" from the theme picker session[:brand_config_md5] = false @@ -639,27 +639,27 @@ def set_up_subaccounts describe "include_head_js" do before do - helper.stubs(:js_bundles).returns([[:some_bundle], [:some_plugin_bundle, :some_plugin], [:another_bundle, nil]]) + allow(helper).to receive(:js_bundles).and_return([[:some_bundle], [:some_plugin_bundle, :some_plugin], [:another_bundle, nil]]) end it "creates the correct javascript tags" do - helper.stubs(:js_env).returns({ + allow(helper).to receive(:js_env).and_return({ BIGEASY_LOCALE: 'nb_NO', MOMENT_LOCALE: 'nb', TIMEZONE: 'America/La_Paz', CONTEXT_TIMEZONE: 'America/Denver' }) base_url = helper.use_optimized_js? ? 'dist/webpack-production' : 'dist/webpack-dev' - Canvas::Cdn::RevManifest.stubs(:webpack_url_for).with(base_url + '/vendor.js').returns('vendor_url') - Canvas::Cdn::RevManifest.stubs(:revved_url_for).with('timezone/America/La_Paz.js').returns('La_Paz_url') - Canvas::Cdn::RevManifest.stubs(:revved_url_for).with('timezone/America/Denver.js').returns('Denver_url') - Canvas::Cdn::RevManifest.stubs(:revved_url_for).with('timezone/nb_NO.js').returns('nb_NO_url') - Canvas::Cdn::RevManifest.stubs(:webpack_url_for).with(base_url + '/moment/locale/nb.js').returns('nb_url') - Canvas::Cdn::RevManifest.stubs(:webpack_url_for).with(base_url + '/appBootstrap.js').returns('app_bootstrap_url') - Canvas::Cdn::RevManifest.stubs(:webpack_url_for).with(base_url + '/common.js').returns('common_url') - Canvas::Cdn::RevManifest.stubs(:webpack_url_for).with(base_url + '/some_bundle.js').returns('some_bundle_url') - Canvas::Cdn::RevManifest.stubs(:webpack_url_for).with(base_url + '/some_plugin-some_plugin_bundle.js').returns('plugin_url') - Canvas::Cdn::RevManifest.stubs(:webpack_url_for).with(base_url + '/another_bundle.js').returns('another_bundle_url') + allow(Canvas::Cdn::RevManifest).to receive(:webpack_url_for).with(base_url + '/vendor.js').and_return('vendor_url') + allow(Canvas::Cdn::RevManifest).to receive(:revved_url_for).with('timezone/America/La_Paz.js').and_return('La_Paz_url') + allow(Canvas::Cdn::RevManifest).to receive(:revved_url_for).with('timezone/America/Denver.js').and_return('Denver_url') + allow(Canvas::Cdn::RevManifest).to receive(:revved_url_for).with('timezone/nb_NO.js').and_return('nb_NO_url') + allow(Canvas::Cdn::RevManifest).to receive(:webpack_url_for).with(base_url + '/moment/locale/nb.js').and_return('nb_url') + allow(Canvas::Cdn::RevManifest).to receive(:webpack_url_for).with(base_url + '/appBootstrap.js').and_return('app_bootstrap_url') + allow(Canvas::Cdn::RevManifest).to receive(:webpack_url_for).with(base_url + '/common.js').and_return('common_url') + allow(Canvas::Cdn::RevManifest).to receive(:webpack_url_for).with(base_url + '/some_bundle.js').and_return('some_bundle_url') + allow(Canvas::Cdn::RevManifest).to receive(:webpack_url_for).with(base_url + '/some_plugin-some_plugin_bundle.js').and_return('plugin_url') + allow(Canvas::Cdn::RevManifest).to receive(:webpack_url_for).with(base_url + '/another_bundle.js').and_return('another_bundle_url') expect(helper.include_head_js).to eq %{ @@ -678,13 +678,13 @@ def set_up_subaccounts describe "include_js_bundles" do before do - helper.stubs(:js_bundles).returns([[:some_bundle], [:some_plugin_bundle, :some_plugin], [:another_bundle, nil]]) + allow(helper).to receive(:js_bundles).and_return([[:some_bundle], [:some_plugin_bundle, :some_plugin], [:another_bundle, nil]]) end it "creates the correct javascript tags" do base_url = helper.use_optimized_js? ? 'dist/webpack-production' : 'dist/webpack-dev' - Canvas::Cdn::RevManifest.stubs(:webpack_url_for).with(base_url + '/some_bundle.js').returns('some_bundle_url') - Canvas::Cdn::RevManifest.stubs(:webpack_url_for).with(base_url + '/some_plugin-some_plugin_bundle.js').returns('plugin_url') - Canvas::Cdn::RevManifest.stubs(:webpack_url_for).with(base_url + '/another_bundle.js').returns('another_bundle_url') + allow(Canvas::Cdn::RevManifest).to receive(:webpack_url_for).with(base_url + '/some_bundle.js').and_return('some_bundle_url') + allow(Canvas::Cdn::RevManifest).to receive(:webpack_url_for).with(base_url + '/some_plugin-some_plugin_bundle.js').and_return('plugin_url') + allow(Canvas::Cdn::RevManifest).to receive(:webpack_url_for).with(base_url + '/another_bundle.js').and_return('another_bundle_url') expect(helper.include_js_bundles).to eq %{ diff --git a/spec/helpers/attachment_helper_spec.rb b/spec/helpers/attachment_helper_spec.rb index 09865dc74945e..f4ba1270c3c2e 100644 --- a/spec/helpers/attachment_helper_spec.rb +++ b/spec/helpers/attachment_helper_spec.rb @@ -29,7 +29,7 @@ it "should return a valid crocodoc session url" do @current_user = @student - @att.stubs(:crocodoc_available?).returns(true) + allow(@att).to receive(:crocodoc_available?).and_return(true) attrs = doc_preview_attributes(@att) expect(attrs).to match /crocodoc_session/ expect(attrs).to match /#{@current_user.id}/ @@ -38,7 +38,7 @@ it "should return a valid canvadoc session url" do @current_user = @student - @att.stubs(:canvadocable?).returns(true) + allow(@att).to receive(:canvadocable?).and_return(true) attrs = doc_preview_attributes(@att) expect(attrs).to match /canvadoc_session/ expect(attrs).to match /#{@current_user.id}/ diff --git a/spec/helpers/avatar_helper_spec.rb b/spec/helpers/avatar_helper_spec.rb index 4be83043611ef..793c9b0cd2b8d 100644 --- a/spec/helpers/avatar_helper_spec.rb +++ b/spec/helpers/avatar_helper_spec.rb @@ -34,12 +34,12 @@ def service_enabled?(type) describe ".avatar_image_attrs" do it "accepts a user id" do - self.expects(:avatar_url_for_user).with(user).returns("test_url") + expect(self).to receive(:avatar_url_for_user).with(user).and_return("test_url") expect(avatar_image_attrs(user.id)).to eq ["test_url", user.short_name] end it "accepts a user" do - self.expects(:avatar_url_for_user).with(user).returns("test_url") + expect(self).to receive(:avatar_url_for_user).with(user).and_return("test_url") expect(avatar_image_attrs(user)).to eq ["test_url", user.short_name] end @@ -48,7 +48,7 @@ def service_enabled?(type) end it "falls back to blank avatar when user's avatar has been reported during this session" do - self.expects(:session).at_least_once.returns({"reported_#{user.id}" => true}) + expect(self).to receive(:session).at_least(:once).and_return({"reported_#{user.id}" => true}) expect(avatar_image_attrs(user)).to eq ["/images/messages/avatar-50.png", ''] end @@ -69,7 +69,7 @@ def service_enabled?(type) end it "links to the context user's page when given a context_code" do - self.expects(:context_prefix).with('course_1').returns('/courses/1') + expect(self).to receive(:context_prefix).with('course_1').and_return('/courses/1') expect(avatar(user, context_code: "course_1")).to match("href=\"/courses/1/users/#{user.id}\"") end diff --git a/spec/helpers/collaborations_helper_spec.rb b/spec/helpers/collaborations_helper_spec.rb index 84a167bb4e9da..d49eea5f2ed98 100644 --- a/spec/helpers/collaborations_helper_spec.rb +++ b/spec/helpers/collaborations_helper_spec.rb @@ -20,25 +20,25 @@ describe CollaborationsHelper do - let(:user) { mock('user') } - let(:course) { Course.new(name: "my course").tap {|t| t.stubs(id: 1)} } - let(:collab) { mock('single collaboration').tap {|t| t.stubs(id: 1) } } + let(:user) { double('user') } + let(:course) { Course.new(name: "my course").tap {|t| allow(t).to receive_messages(id: 1)} } + let(:collab) { double('single collaboration').tap {|t| allow(t).to receive_messages(id: 1) } } describe "collaboration" do it 'renders the collaborations' do - helper.expects(:render).with('collaborations/collaboration', has_entries(collaboration: collab, user: user)) + expect(helper).to receive(:render).with('collaborations/collaboration', include(collaboration: collab, user: user)) helper.collaboration(collab, user, false) end it 'renders the google auth for google drive collaborations if the user does not have google docs authorized' do - collab.stubs(:is_a?).with(GoogleDocsCollaboration).returns(true) - helper.expects(:render).with('collaborations/auth_google_drive', collaboration: collab) + allow(collab).to receive(:is_a?).with(GoogleDocsCollaboration).and_return(true) + expect(helper).to receive(:render).with('collaborations/auth_google_drive', collaboration: collab) helper.collaboration(collab, user, false) end it 'constructs the data attributes' do - helper.expects(:render).with('collaborations/collaboration', has_entries( - data_attributes: has_entries({id: 1}) + expect(helper).to receive(:render).with('collaborations/collaboration', include( + data_attributes: include({id: 1}) )) helper.collaboration(collab, user, false) end @@ -46,13 +46,13 @@ it 'has the data-update-launch-url attribute if it is a ExternalToolCollaboration' do assign(:context, course) launch_url = 'http://example.com/test' - collab.stubs(:is_a?).returns false - collab.stubs(:is_a?).with(ExternalToolCollaboration).returns true - collab.stubs(:update_url).returns(launch_url) - helper.expects(:render).with('collaborations/collaboration', - has_entries( - data_attributes: has_entries( - update_launch_url: includes(CGI.escape(launch_url)), + allow(collab).to receive(:is_a?).and_return false + allow(collab).to receive(:is_a?).with(ExternalToolCollaboration).and_return true + allow(collab).to receive(:update_url).and_return(launch_url) + expect(helper).to receive(:render).with('collaborations/collaboration', + include( + data_attributes: include( + update_launch_url: include(CGI.escape(launch_url)), id: collab.id ) ) @@ -64,16 +64,16 @@ describe "#edit_button" do it 'returns the edit button if the user has permissions' do - collab.stubs(:grants_any_right?).returns(true) - helper.expects(:render).with('collaborations/edit_button', collaboration: collab) + allow(collab).to receive(:grants_any_right?).and_return(true) + expect(helper).to receive(:render).with('collaborations/edit_button', collaboration: collab) helper.edit_button(collab, user) end it "doesn't return the edit button for an ExternalToolCollaboration that don't have an edit url" do - collab.stubs(:is_a?).with(ExternalToolCollaboration).returns(true) - collab.stubs(:update_url).returns(nil) - collab.stubs(:grants_any_right?).returns(true) - helper.expects(:render).never + allow(collab).to receive(:is_a?).with(ExternalToolCollaboration).and_return(true) + allow(collab).to receive(:update_url).and_return(nil) + allow(collab).to receive(:grants_any_right?).and_return(true) + expect(helper).to receive(:render).never helper.edit_button(collab, user) end @@ -81,8 +81,8 @@ describe "#delete_button" do it 'returns the delete button if the user has permissions' do - collab.stubs(:grants_any_right?).returns(true) - helper.expects(:render).with('collaborations/delete_button', collaboration: collab) + allow(collab).to receive(:grants_any_right?).and_return(true) + expect(helper).to receive(:render).with('collaborations/delete_button', collaboration: collab) helper.delete_button(collab, user) end end @@ -90,14 +90,14 @@ describe "#collaboration_links" do it 'returns collaboration links if the user has permissions' do - collab.stubs(:grants_any_right?).returns(true) - helper.expects(:render).with('collaborations/collaboration_links', collaboration: collab, user: user) + allow(collab).to receive(:grants_any_right?).and_return(true) + expect(helper).to receive(:render).with('collaborations/collaboration_links', collaboration: collab, user: user) helper.collaboration_links(collab, user) end it "doesn't return collaboration links if the user doesn't have permission" do - collab.stubs(:grants_any_right?).returns(false) - helper.expects(:render).with('collaborations/collaboration_links', collaboration: collab, user: user).never + allow(collab).to receive(:grants_any_right?).and_return(false) + expect(helper).to receive(:render).with('collaborations/collaboration_links', collaboration: collab, user: user).never helper.collaboration_links(collab, user) end diff --git a/spec/helpers/context_external_tools_helper_spec.rb b/spec/helpers/context_external_tools_helper_spec.rb index 1ccd3ac796b39..b3bb2133e0553 100644 --- a/spec/helpers/context_external_tools_helper_spec.rb +++ b/spec/helpers/context_external_tools_helper_spec.rb @@ -108,8 +108,8 @@ def tool_settings(setting, include_class=false) before :each do @controller = DummyController.new - @controller.stubs(:external_tool_url).returns("http://stub.dev/tool_url") - # @controller.stubs(:request).returns(ActionDispatch::TestRequest.new) + allow(@controller).to receive(:external_tool_url).and_return("http://stub.dev/tool_url") + # allow(@controller).to receive(:request).and_return(ActionDispatch::TestRequest.new) # @controller.instance_variable_set(:@context, @course) end diff --git a/spec/helpers/context_modules_helper_spec.rb b/spec/helpers/context_modules_helper_spec.rb index c6c6c69b43f4c..f8bf860dcb219 100644 --- a/spec/helpers/context_modules_helper_spec.rb +++ b/spec/helpers/context_modules_helper_spec.rb @@ -77,7 +77,7 @@ before do @context = t_course - ConditionalRelease::Service.stubs(:rules_for).returns([ + allow(ConditionalRelease::Service).to receive(:rules_for).and_return([ { trigger_assignment: assg.id, locked: false, @@ -87,7 +87,7 @@ end it "should not set mastery_paths if cyoe is disabled" do - ConditionalRelease::Service.expects(:rules_for).never + expect(ConditionalRelease::Service).to receive(:rules_for).never module_data = process_module_data(t_module, true, false, @student, @session) item_data = module_data[:items_data][item.id] expect(item_data[:mastery_paths]).to be nil @@ -107,7 +107,7 @@ end it "should set show_cyoe_placeholder to true if no set has been selected and the rule is locked" do - ConditionalRelease::Service.stubs(:rules_for).returns([ + allow(ConditionalRelease::Service).to receive(:rules_for).and_return([ { trigger_assignment: assg.id, locked: true, @@ -127,7 +127,7 @@ end it "should set show_cyoe_placeholder to false if no set has been selected and no sets are available" do - ConditionalRelease::Service.stubs(:rules_for).returns([ + allow(ConditionalRelease::Service).to receive(:rules_for).and_return([ { trigger_assignment: assg.id, locked: false, @@ -141,7 +141,7 @@ end it "should set show_cyoe_placeholder to false if set has been selected for a cyoe trigger assignment module item" do - ConditionalRelease::Service.stubs(:rules_for).returns([ + allow(ConditionalRelease::Service).to receive(:rules_for).and_return([ { selected_set_id: 1, trigger_assignment: assg.id, @@ -158,13 +158,13 @@ describe "add_mastery_paths_to_cache_key" do before do - ConditionalRelease::Service.stubs(:enabled_in_context?).returns(true) - ConditionalRelease::Service.stubs(:rules_for).returns([1, 2, 3]) - ConditionalRelease::Service.stubs(:active_rules).returns([1, 2, 3]) + allow(ConditionalRelease::Service).to receive(:enabled_in_context?).and_return(true) + allow(ConditionalRelease::Service).to receive(:rules_for).and_return([1, 2, 3]) + allow(ConditionalRelease::Service).to receive(:active_rules).and_return([1, 2, 3]) end it "does not affect cache keys unless mastery paths enabled" do - ConditionalRelease::Service.stubs(:enabled_in_context?).returns(false) + allow(ConditionalRelease::Service).to receive(:enabled_in_context?).and_return(false) student_in_course(course: t_course, active_all: true) cache = add_mastery_paths_to_cache_key('foo', t_course, t_module, @student) expect(cache).to eq 'foo' @@ -183,7 +183,7 @@ s1 = student_in_course(course: t_course, active_all: true) s2 = student_in_course(course: t_course, active_all: true) cache1 = add_mastery_paths_to_cache_key('foo', t_course, t_module, s1.user) - ConditionalRelease::Service.stubs(:rules_for).returns([3, 2, 1]) + allow(ConditionalRelease::Service).to receive(:rules_for).and_return([3, 2, 1]) cache2 = add_mastery_paths_to_cache_key('foo', t_course, t_module, s2.user) expect(cache1).not_to eq cache2 end @@ -201,7 +201,7 @@ t1 = teacher_in_course(course: t_course) t2 = teacher_in_course(course: t_course) cache1 = add_mastery_paths_to_cache_key('foo', t_course, t_module, t1.user) - ConditionalRelease::Service.stubs(:active_rules).returns([3, 2, 1]) + allow(ConditionalRelease::Service).to receive(:active_rules).and_return([3, 2, 1]) cache2 = add_mastery_paths_to_cache_key('foo', t_course, t_module, t2.user) expect(cache1).not_to eq cache2 end diff --git a/spec/helpers/courses_helper_spec.rb b/spec/helpers/courses_helper_spec.rb index 1f61c8cee4b0a..28940cb3d3e27 100644 --- a/spec/helpers/courses_helper_spec.rb +++ b/spec/helpers/courses_helper_spec.rb @@ -52,17 +52,17 @@ end it "should return a no submission tooltip if there are no submissions" do - expects(:t).with('#courses.recent_event.no_submissions', 'no submissions').returns('no submissions') + expect(self).to receive(:t).with('#courses.recent_event.no_submissions', 'no submissions').and_return('no submissions') check_icon_data("no submissions", "Assignment", "icon-assignment") end it "should return a not submitted tooltip for a student if they have not made a submission" do - expects(:t).with('#courses.recent_event.not_submitted', 'not submitted').returns('not submitted') + expect(self).to receive(:t).with('#courses.recent_event.not_submitted', 'not submitted').and_return('not submitted') check_icon_data("not submitted", "Assignment", "icon-assignment", current_user: @student_one) end it "should return a nil tooltip for a student if the assignment does not expect a submission" do - expects(:t).with('#courses.recent_event.not_submitted', 'not submitted').returns('not submitted') + expect(self).to receive(:t).with('#courses.recent_event.not_submitted', 'not submitted').and_return('not submitted') check_icon_data(nil, "Assignment", "icon-assignment", current_user: @student_one, recent_event: @assignment2) end end @@ -80,7 +80,7 @@ end it "should return a needs grading tooltip if assignments have been submitted that aren't graded" do - expects(:t).with('#courses.recent_event.needs_grading', 'needs grading').returns('needs grading') + expect(self).to receive(:t).with('#courses.recent_event.needs_grading', 'needs grading').and_return('needs grading') @assignment.submit_homework(@student_one, { :submission_type => "online_text_entry", :body => "..." }) check_icon_data("needs grading", "Assignment", "icon-assignment") end @@ -100,14 +100,14 @@ end it "should return a no new submissions tooltip if some assignments have been submitted and graded" do - expects(:t).with('#courses.recent_event.no_new_submissions', 'no new submissions').returns('no new submissions') + expect(self).to receive(:t).with('#courses.recent_event.no_new_submissions', 'no new submissions').and_return('no new submissions') @assignment.submit_homework(@student_one, { :submission_type => "online_text_entry", :body => "xyz" }) @assignment.grade_student(@student_one, grade: 5, grader: @teacher) check_icon_data("no new submissions", "Assignment", "icon-assignment") end it "should return an all graded tooltip if all assignments are submitted and graded" do - expects(:t).with('#courses.recent_event.all_graded', 'all graded').returns('all graded') + expect(self).to receive(:t).with('#courses.recent_event.all_graded', 'all graded').and_return('all graded') [@student_one, @student_two].each do |student| @assignment.submit_homework(student, { :submission_type => "online_text_entry", :body => "bod" }) @assignment.grade_student(student, grade: 5, grader: @teacher) diff --git a/spec/helpers/login/canvas_helper_spec.rb b/spec/helpers/login/canvas_helper_spec.rb index e310d55c1b6fb..d3e9fe087b328 100644 --- a/spec/helpers/login/canvas_helper_spec.rb +++ b/spec/helpers/login/canvas_helper_spec.rb @@ -22,7 +22,7 @@ describe "#session_timeout_enabled" do context "when the sessions plugin is enabled" do before do - PluginSetting.expects(:settings_for_plugin).with('sessions').returns({"session_timeout" => 123}) + expect(PluginSetting).to receive(:settings_for_plugin).with('sessions').and_return({"session_timeout" => 123}) end it "returns true" do @@ -32,7 +32,7 @@ context "when the sessions plugin is disabled" do before do - PluginSetting.expects(:settings_for_plugin).with('sessions').returns(nil) + expect(PluginSetting).to receive(:settings_for_plugin).with('sessions').and_return(nil) end it "returns false" do diff --git a/spec/helpers/quizzes_helper_spec.rb b/spec/helpers/quizzes_helper_spec.rb index 0bf196dd8419f..dbed9a746ffc7 100644 --- a/spec/helpers/quizzes_helper_spec.rb +++ b/spec/helpers/quizzes_helper_spec.rb @@ -178,7 +178,7 @@ def can_publish(quiz); true; end @answer_list = [] @answers = [] - def user_content(stuff); stuff; end # mock #user_content + def user_content(stuff); stuff; end # double #user_content end it 'should extract the answers by blank' do @@ -249,7 +249,7 @@ def user_content(stuff); stuff; end # mock #user_content context "multiple_dropdowns_question" do before do - def user_content(stuff); stuff; end # mock #user_content + def user_content(stuff); stuff; end # double #user_content end it "should select the user's answer" do @@ -294,12 +294,12 @@ def user_content(stuff); stuff; end # mock #user_content describe "#quiz_edit_text" do it "returns correct string for survey" do - quiz = stub(:survey? => true) + quiz = double(:survey? => true) expect(quiz_edit_text(quiz)).to eq "Edit Survey" end it "returns correct string for quiz" do - quiz = stub(:survey? => false) + quiz = double(:survey? => false) expect(quiz_edit_text(quiz)).to eq "Edit Quiz" end end @@ -307,24 +307,24 @@ def user_content(stuff); stuff; end # mock #user_content describe "#quiz_delete_text" do it "returns correct string for survey" do - quiz = stub(:survey? => true) + quiz = double(:survey? => true) expect(quiz_delete_text(quiz)).to eq "Delete Survey" end it "returns correct string for quiz" do - quiz = stub(:survey? => false) + quiz = double(:survey? => false) expect(quiz_delete_text(quiz)).to eq "Delete Quiz" end end describe "#score_affected_by_regrade" do it "returns true if kept score differs from score before regrade" do - submission = stub(:score_before_regrade => 5, :kept_score => 10, :score => 5) + submission = double(:score_before_regrade => 5, :kept_score => 10, :score => 5) expect(score_affected_by_regrade?(submission)).to be_truthy end it "returns false if kept score equals score before regrade" do - submission = stub(:score_before_regrade => 5, :kept_score => 5, :score => 0) + submission = double(:score_before_regrade => 5, :kept_score => 5, :score => 0) expect(score_affected_by_regrade?(submission)).to be_falsey end end @@ -349,14 +349,14 @@ def user_content(stuff); stuff; end # mock #user_content describe "#render_show_correct_answers" do context "show_correct_answers is false" do it 'shows No' do - quiz = stub({show_correct_answers: false}) + quiz = double({show_correct_answers: false}) expect(render_show_correct_answers(quiz)).to eq "No" end end context "show_correct_answers is true, but nothing else is set" do it 'shows Immediately' do - quiz = stub({ + quiz = double({ show_correct_answers: true, show_correct_answers_at: nil, hide_correct_answers_at: nil, @@ -368,7 +368,7 @@ def user_content(stuff); stuff; end # mock #user_content context "show_correct_answers_last_attempt is true" do it 'shows After Last Attempt' do - quiz = stub({ + quiz = double({ show_correct_answers: true, show_correct_answers_at: nil, hide_correct_answers_at: nil, @@ -381,7 +381,7 @@ def user_content(stuff); stuff; end # mock #user_content context "show_correct_answers_at is set" do it 'shows date of ' do time = 1.day.from_now - quiz = stub({ + quiz = double({ show_correct_answers: true, show_correct_answers_at: time, hide_correct_answers_at: nil @@ -393,7 +393,7 @@ def user_content(stuff); stuff; end # mock #user_content context "hide_correct_answers_at is set" do it 'shows date of ' do time = 1.day.from_now - quiz = stub({ + quiz = double({ show_correct_answers: true, show_correct_answers_at: nil, hide_correct_answers_at: time, @@ -407,7 +407,7 @@ def user_content(stuff); stuff; end # mock #user_content time = 1.day.from_now time2 = 1.week.from_now - quiz = stub({ + quiz = double({ show_correct_answers: true, show_correct_answers_at: time, hide_correct_answers_at: time2, @@ -419,61 +419,61 @@ def user_content(stuff); stuff; end # mock #user_content describe '#render_correct_answer_protection' do it 'should provide a useful message when "last attempt"' do - quiz = stub({ + quiz = double({ show_correct_answers_last_attempt: true, }) - quiz_submission = stub(last_attempt_completed?: false) + quiz_submission = double(last_attempt_completed?: false) message = render_correct_answer_protection(quiz, quiz_submission) expect(message).to match /last attempt/ end it 'should provide a useful message when "no"' do - quiz = stub({ + quiz = double({ show_correct_answers_last_attempt: nil, show_correct_answers: false, show_correct_answers_at: nil, hide_correct_answers_at: nil }) - quiz_submission = stub(last_attempt_completed?: false) + quiz_submission = double(last_attempt_completed?: false) message = render_correct_answer_protection(quiz, quiz_submission) expect(message).to match /are hidden/ end it 'should provide nothing when "yes"' do - quiz = stub({ + quiz = double({ show_correct_answers_last_attempt: nil, show_correct_answers: true, show_correct_answers_at: nil, hide_correct_answers_at: nil }) - quiz_submission = stub(last_attempt_completed?: false) + quiz_submission = double(last_attempt_completed?: false) message = render_correct_answer_protection(quiz, quiz_submission) expect(message).to eq nil end it 'should provide a useful message, and an availability date, when "show at" is set' do - quiz = stub({ + quiz = double({ show_correct_answers_last_attempt: nil, show_correct_answers: true, show_correct_answers_at: 1.day.from_now, hide_correct_answers_at: nil }) - quiz_submission = stub(last_attempt_completed?: false) + quiz_submission = double(last_attempt_completed?: false) message = render_correct_answer_protection(quiz, quiz_submission) expect(message).to match /will be available/ end it 'should provide a useful message, and a date, when "hide at" is set' do - quiz = stub({ + quiz = double({ show_correct_answers_last_attempt: nil, show_correct_answers: true, show_correct_answers_at: nil, hide_correct_answers_at: 1.day.from_now }) - quiz_submission = stub(last_attempt_completed?: false) + quiz_submission = double(last_attempt_completed?: false) message = render_correct_answer_protection(quiz, quiz_submission) expect(message).to match /are available until/ @@ -486,7 +486,7 @@ def user_content(stuff); stuff; end # mock #user_content let(:quiz) { @quiz } before do - @quiz = stub(quiz_type: 'graded_survey') + @quiz = double(quiz_type: 'graded_survey') @user_answer = { correct: 'undefined', points: 5 } end @@ -499,14 +499,14 @@ def user_content(stuff); stuff; end # mock #user_content it "returns empty if quiz is practice quiz or assignment" do ['assignment', 'practice_quiz'].each do |quiz_type| - @quiz.expects(:quiz_type).returns quiz_type + expect(@quiz).to receive(:quiz_type).and_return quiz_type expect(point_value_for_input(user_answer, question)).to eq "" end end it "returns points possible for the question if (un)graded survey" do ['survey', 'graded_survey'].each do |quiz_type| - @quiz.expects(:quiz_type).returns quiz_type + expect(@quiz).to receive(:quiz_type).and_return quiz_type expect(point_value_for_input(user_answer, question)).to eq( question[:points_possible] ) diff --git a/spec/helpers/section_tab_helper_spec.rb b/spec/helpers/section_tab_helper_spec.rb index b0ca130505f80..701f0654fc266 100644 --- a/spec/helpers/section_tab_helper_spec.rb +++ b/spec/helpers/section_tab_helper_spec.rb @@ -48,7 +48,7 @@ class SectionTabHelperSpec let(:bad_tab) { { label: 'bad tab' } } before(:each) do tabs = Course.default_tabs + [bad_tab] - course.stubs(:tabs_available).returns(tabs) + allow(course).to receive(:tabs_available).and_return(tabs) end let(:available_section_tabs) do SectionTabHelperSpec::AvailableSectionTabs.new( @@ -67,7 +67,7 @@ class SectionTabHelperSpec context 'and tabs include TAB_CONFERENCES' do it 'should include TAB_CONFERENCES if WebConference.config' do - WebConference.stubs(:config).returns({}) + allow(WebConference).to receive(:config).and_return({}) expect(available_section_tabs.to_a.map do |tab| tab[:id] end).to include(Course::TAB_CONFERENCES) @@ -82,7 +82,7 @@ class SectionTabHelperSpec context 'and tabs include TAB_COLLABORATIONS' do it 'should include TAB_COLLABORATIONS if Collaboration.any_collaborations_configured?' do - Collaboration.stubs(:any_collaborations_configured?).returns(true) + allow(Collaboration).to receive(:any_collaborations_configured?).and_return(true) expect(available_section_tabs.to_a.map do |tab| tab[:id] end).to include(Course::TAB_COLLABORATIONS) @@ -96,7 +96,7 @@ class SectionTabHelperSpec it 'should not include TAB_COLLABORATIONS when new_collaborations feature flag has been enabled' do domain_root_account.set_feature_flag!(:new_collaborations, "on") - Collaboration.stubs(:any_collaborations_configured?).returns(true) + allow(Collaboration).to receive(:any_collaborations_configured?).and_return(true) expect(available_section_tabs.to_a.map { |tab| tab[:id] }).not_to include(Course::TAB_COLLABORATIONS) end end diff --git a/spec/helpers/syllabus_helper_spec.rb b/spec/helpers/syllabus_helper_spec.rb index 360db05cf5c5b..96b679c622681 100644 --- a/spec/helpers/syllabus_helper_spec.rb +++ b/spec/helpers/syllabus_helper_spec.rb @@ -33,7 +33,7 @@ end it 'sends two arguments to `pulic_user_content`' do - helper.expects(:public_user_content).with(@course.syllabus_body, @course).once + expect(helper).to receive(:public_user_content).with(@course.syllabus_body, @course).once helper.syllabus_user_content end end @@ -44,7 +44,7 @@ end it 'sends two arguments to `pulic_user_content`' do - helper.expects(:public_user_content).with(@course.syllabus_body, @course, nil, true).once + expect(helper).to receive(:public_user_content).with(@course.syllabus_body, @course, nil, true).once helper.syllabus_user_content end end