diff --git a/spec/components/archetype_spec.rb b/spec/components/archetype_spec.rb index b7124d24d3c..a4cffe853ec 100644 --- a/spec/components/archetype_spec.rb +++ b/spec/components/archetype_spec.rb @@ -8,11 +8,11 @@ describe Archetype do context 'default archetype' do it 'has an Archetype by default' do - Archetype.list.should be_present + expect(Archetype.list).to be_present end it 'has an id of default' do - Archetype.list.first.id.should == Archetype.default + expect(Archetype.list.first.id).to eq(Archetype.default) end context 'duplicate' do @@ -23,7 +23,7 @@ describe Archetype do end it 'does not add the same archetype twice' do - Archetype.list.size.should == @old_size + expect(Archetype.list.size).to eq(@old_size) end end @@ -35,8 +35,8 @@ describe Archetype do it 'has one more element' do @list = Archetype.list.dup Archetype.register('glados') - Archetype.list.size.should == @list.size + 1 - Archetype.list.find {|a| a.id == 'glados'}.should be_present + expect(Archetype.list.size).to eq(@list.size + 1) + expect(Archetype.list.find {|a| a.id == 'glados'}).to be_present end end diff --git a/spec/components/auth/default_current_user_provider_spec.rb b/spec/components/auth/default_current_user_provider_spec.rb index 153ac139551..b8cbd5fe9a7 100644 --- a/spec/components/auth/default_current_user_provider_spec.rb +++ b/spec/components/auth/default_current_user_provider_spec.rb @@ -18,7 +18,7 @@ describe Auth::DefaultCurrentUserProvider do it "finds a user for a correct per-user api key" do user = Fabricate(:user) ApiKey.create!(key: "hello", user_id: user.id, created_by_id: -1) - provider("/?api_key=hello").current_user.id.should == user.id + expect(provider("/?api_key=hello").current_user.id).to eq(user.id) end it "raises for a user pretending" do @@ -48,29 +48,29 @@ describe Auth::DefaultCurrentUserProvider do found_user = provider("/?api_key=hello&api_username=#{user.username.downcase}", "REMOTE_ADDR" => "100.0.0.22").current_user - found_user.id.should == user.id + expect(found_user.id).to eq(user.id) found_user = provider("/?api_key=hello&api_username=#{user.username.downcase}", "HTTP_X_FORWARDED_FOR" => "10.1.1.1, 100.0.0.22").current_user - found_user.id.should == user.id + expect(found_user.id).to eq(user.id) end it "finds a user for a correct system api key" do user = Fabricate(:user) ApiKey.create!(key: "hello", created_by_id: -1) - provider("/?api_key=hello&api_username=#{user.username.downcase}").current_user.id.should == user.id + expect(provider("/?api_key=hello&api_username=#{user.username.downcase}").current_user.id).to eq(user.id) end it "should not update last seen for message bus" do - provider("/message-bus/anything/goes", method: "POST").should_update_last_seen?.should == false - provider("/message-bus/anything/goes", method: "GET").should_update_last_seen?.should == false + expect(provider("/message-bus/anything/goes", method: "POST").should_update_last_seen?).to eq(false) + expect(provider("/message-bus/anything/goes", method: "GET").should_update_last_seen?).to eq(false) end it "should update last seen for others" do - provider("/topic/anything/goes", method: "POST").should_update_last_seen?.should == true - provider("/topic/anything/goes", method: "GET").should_update_last_seen?.should == true + expect(provider("/topic/anything/goes", method: "POST").should_update_last_seen?).to eq(true) + expect(provider("/topic/anything/goes", method: "GET").should_update_last_seen?).to eq(true) end end diff --git a/spec/components/auth/facebook_authenticator_spec.rb b/spec/components/auth/facebook_authenticator_spec.rb index 9ee4d303c47..70c14491b72 100644 --- a/spec/components/auth/facebook_authenticator_spec.rb +++ b/spec/components/auth/facebook_authenticator_spec.rb @@ -27,7 +27,7 @@ describe Auth::FacebookAuthenticator do result = authenticator.after_authenticate(hash) - result.user.id.should == user.id + expect(result.user.id).to eq(user.id) end it 'can create a proper result for non existing users' do @@ -49,8 +49,8 @@ describe Auth::FacebookAuthenticator do result = authenticator.after_authenticate(hash) - result.user.should == nil - result.extra_data[:name].should == "bob bob" + expect(result.user).to eq(nil) + expect(result.extra_data[:name]).to eq("bob bob") end end diff --git a/spec/components/auth/google_oauth2_authenticator_spec.rb b/spec/components/auth/google_oauth2_authenticator_spec.rb index bb481658c22..f14996e13cd 100644 --- a/spec/components/auth/google_oauth2_authenticator_spec.rb +++ b/spec/components/auth/google_oauth2_authenticator_spec.rb @@ -28,7 +28,7 @@ describe Auth::GoogleOAuth2Authenticator do result = authenticator.after_authenticate(hash) - result.user.id.should == user.id + expect(result.user.id).to eq(user.id) end it 'can create a proper result for non existing users' do @@ -50,8 +50,8 @@ describe Auth::GoogleOAuth2Authenticator do authenticator = described_class.new result = authenticator.after_authenticate(hash) - result.user.should == nil - result.extra_data[:name].should == "Jane Doe" + expect(result.user).to eq(nil) + expect(result.extra_data[:name]).to eq("Jane Doe") end end diff --git a/spec/components/auth/open_id_authenticator_spec.rb b/spec/components/auth/open_id_authenticator_spec.rb index df89c0748f0..78fdc00ad2e 100644 --- a/spec/components/auth/open_id_authenticator_spec.rb +++ b/spec/components/auth/open_id_authenticator_spec.rb @@ -14,12 +14,12 @@ describe Auth::OpenIdAuthenticator do user = Fabricate(:user) response = OpenStruct.new(identity_url: 'abc') result = auth.after_authenticate(info: {email: user.email}, extra: {response: response}) - result.user.should == user + expect(result.user).to eq(user) end it "raises an exception when email is missing" do auth = Auth::OpenIdAuthenticator.new("test", "id", trusted: true) response = OpenStruct.new(identity_url: 'abc') - -> { auth.after_authenticate(info: {}, extra: { response: response }) }.should raise_error(Discourse::InvalidParameters) + expect { auth.after_authenticate(info: {}, extra: { response: response }) }.to raise_error(Discourse::InvalidParameters) end end diff --git a/spec/components/avatar_lookup_spec.rb b/spec/components/avatar_lookup_spec.rb index 163e4a7124f..9285360061c 100644 --- a/spec/components/avatar_lookup_spec.rb +++ b/spec/components/avatar_lookup_spec.rb @@ -12,15 +12,15 @@ describe AvatarLookup do end it 'returns nil if user_id does not exists' do - @avatar_lookup[0].should == nil + expect(@avatar_lookup[0]).to eq(nil) end it 'returns nil if user_id is nil' do - @avatar_lookup[nil].should == nil + expect(@avatar_lookup[nil]).to eq(nil) end it 'returns user if user_id exists' do - @avatar_lookup[user.id].should eq(user) + expect(@avatar_lookup[user.id]).to eq(user) end end end diff --git a/spec/components/avatar_upload_service_spec.rb b/spec/components/avatar_upload_service_spec.rb index a003d263037..2be4ccc0ad8 100644 --- a/spec/components/avatar_upload_service_spec.rb +++ b/spec/components/avatar_upload_service_spec.rb @@ -16,19 +16,19 @@ describe AvatarUploadService do let(:avatar_file) { AvatarUploadService.new(file, :image) } it "should have a filesize" do - avatar_file.filesize.should > 0 + expect(avatar_file.filesize).to be > 0 end it "should have a filename" do - avatar_file.filename.should == "logo.png" + expect(avatar_file.filename).to eq("logo.png") end it "should have a file" do - avatar_file.file.should == file.tempfile + expect(avatar_file.file).to eq(file.tempfile) end it "should have a source as 'image'" do - avatar_file.source.should == :image + expect(avatar_file.source).to eq(:image) end end @@ -38,19 +38,19 @@ describe AvatarUploadService do before { FileHelper.stubs(:download).returns(logo) } it "should have a filesize" do - avatar_file.filesize.should > 0 + expect(avatar_file.filesize).to be > 0 end it "should have a filename" do - avatar_file.filename.should == "logo.png" + expect(avatar_file.filename).to eq("logo.png") end it "should have a file" do - avatar_file.file.should == logo + expect(avatar_file.file).to eq(logo) end it "should have a source as 'url'" do - avatar_file.source.should == :url + expect(avatar_file.source).to eq(:url) end end end diff --git a/spec/components/cache_spec.rb b/spec/components/cache_spec.rb index bbc1e842670..8479b507847 100644 --- a/spec/components/cache_spec.rb +++ b/spec/components/cache_spec.rb @@ -9,13 +9,13 @@ describe Cache do it "supports fixnum" do cache.write("num", 1) - cache.read("num").should == 1 + expect(cache.read("num")).to eq(1) end it "supports hash" do hash = {a: 1, b: [1,2,3]} cache.write("hash", hash) - cache.read("hash").should == hash + expect(cache.read("hash")).to eq(hash) end it "can be cleared" do @@ -23,7 +23,7 @@ describe Cache do cache.write("hello1", "world") cache.clear - cache.read("hello0").should == nil + expect(cache.read("hello0")).to eq(nil) end it "can delete by family" do @@ -32,8 +32,8 @@ describe Cache do cache.delete_by_family("my_family") - cache.fetch("key").should == nil - cache.fetch("key2").should == nil + expect(cache.fetch("key")).to eq(nil) + expect(cache.fetch("key2")).to eq(nil) end @@ -43,7 +43,7 @@ describe Cache do end cache.delete("key") - cache.fetch("key").should == nil + expect(cache.fetch("key")).to eq(nil) end #TODO yuck on this mock @@ -64,7 +64,7 @@ describe Cache do r = cache.fetch "key" do "bob" end - r.should == "bob" + expect(r).to eq("bob") end it "can fetch existing correctly" do @@ -73,6 +73,6 @@ describe Cache do r = cache.fetch "key" do "bob" end - r.should == "bill" + expect(r).to eq("bill") end end diff --git a/spec/components/category_list_spec.rb b/spec/components/category_list_spec.rb index 9d3f6df14ef..104173d3b91 100644 --- a/spec/components/category_list_spec.rb +++ b/spec/components/category_list_spec.rb @@ -15,9 +15,9 @@ describe CategoryList do cat.save # uncategorized + this - CategoryList.new(Guardian.new admin).categories.count.should == 2 - CategoryList.new(Guardian.new user).categories.count.should == 0 - CategoryList.new(Guardian.new nil).categories.count.should == 0 + expect(CategoryList.new(Guardian.new admin).categories.count).to eq(2) + expect(CategoryList.new(Guardian.new user).categories.count).to eq(0) + expect(CategoryList.new(Guardian.new nil).categories.count).to eq(0) end it "doesn't show topics that you can't view" do @@ -36,14 +36,14 @@ describe CategoryList do CategoryFeaturedTopic.feature_topics - CategoryList.new(Guardian.new(admin)).categories.find { |x| x.name == public_cat.name }.displayable_topics.count.should == 2 - CategoryList.new(Guardian.new(admin)).categories.find { |x| x.name == private_cat.name }.displayable_topics.count.should == 1 + expect(CategoryList.new(Guardian.new(admin)).categories.find { |x| x.name == public_cat.name }.displayable_topics.count).to eq(2) + expect(CategoryList.new(Guardian.new(admin)).categories.find { |x| x.name == private_cat.name }.displayable_topics.count).to eq(1) - CategoryList.new(Guardian.new(user)).categories.find { |x| x.name == public_cat.name }.displayable_topics.count.should == 1 - CategoryList.new(Guardian.new(user)).categories.find { |x| x.name == private_cat.name }.should == nil + expect(CategoryList.new(Guardian.new(user)).categories.find { |x| x.name == public_cat.name }.displayable_topics.count).to eq(1) + expect(CategoryList.new(Guardian.new(user)).categories.find { |x| x.name == private_cat.name }).to eq(nil) - CategoryList.new(Guardian.new(nil)).categories.find { |x| x.name == public_cat.name }.displayable_topics.count.should == 1 - CategoryList.new(Guardian.new(nil)).categories.find { |x| x.name == private_cat.name }.should == nil + expect(CategoryList.new(Guardian.new(nil)).categories.find { |x| x.name == public_cat.name }.displayable_topics.count).to eq(1) + expect(CategoryList.new(Guardian.new(nil)).categories.find { |x| x.name == private_cat.name }).to eq(nil) end end @@ -54,33 +54,33 @@ describe CategoryList do context "without a featured topic" do it "should not return empty categories" do - category_list.categories.should be_blank + expect(category_list.categories).to be_blank end it "returns empty categories for those who can create them" do SiteSetting.stubs(:allow_uncategorized_topics).returns(true) Guardian.any_instance.expects(:can_create?).with(Category).returns(true) - category_list.categories.should_not be_blank + expect(category_list.categories).not_to be_blank end it "returns empty categories with descriptions" do Fabricate(:category, description: 'The category description.') Guardian.any_instance.expects(:can_create?).with(Category).returns(false) - category_list.categories.should_not be_blank + expect(category_list.categories).not_to be_blank end it 'returns the empty category and a non-empty category for those who can create them' do SiteSetting.stubs(:allow_uncategorized_topics).returns(true) Fabricate(:topic, category: Fabricate(:category)) Guardian.any_instance.expects(:can_create?).with(Category).returns(true) - category_list.categories.size.should == 3 - category_list.categories.should include(topic_category) + expect(category_list.categories.size).to eq(3) + expect(category_list.categories).to include(topic_category) end it "doesn't return empty uncategorized category to admins if allow_uncategorized_topics is false" do SiteSetting.stubs(:allow_uncategorized_topics).returns(false) - CategoryList.new(Guardian.new(user)).categories.should be_empty - CategoryList.new(Guardian.new(admin)).categories.map(&:id).should_not include(SiteSetting.uncategorized_category_id) + expect(CategoryList.new(Guardian.new(user)).categories).to be_empty + expect(CategoryList.new(Guardian.new(admin)).categories.map(&:id)).not_to include(SiteSetting.uncategorized_category_id) end end @@ -90,15 +90,15 @@ describe CategoryList do let(:category) { category_list.categories.first } it "should return the category" do - category.should be_present + expect(category).to be_present end it "returns the correct category" do - category.id.should == topic_category.id + expect(category.id).to eq(topic_category.id) end it "should contain our topic" do - category.featured_topics.include?(topic).should == true + expect(category.featured_topics.include?(topic)).to eq(true) end end @@ -120,16 +120,16 @@ describe CategoryList do it "returns categories in specified order" do cat1, cat2 = Fabricate(:category, position: 1), Fabricate(:category, position: 0) - category_ids.should == [cat2.id, cat1.id] + expect(category_ids).to eq([cat2.id, cat1.id]) end it "handles duplicate position values" do cat1, cat2, cat3, cat4 = Fabricate(:category, position: 0), Fabricate(:category, position: 0), Fabricate(:category, position: nil), Fabricate(:category, position: 0) first_three = category_ids[0,3] # The order is not deterministic - first_three.should include(cat1.id) - first_three.should include(cat2.id) - first_three.should include(cat4.id) - category_ids[-1].should == cat3.id + expect(first_three).to include(cat1.id) + expect(first_three).to include(cat2.id) + expect(first_three).to include(cat4.id) + expect(category_ids[-1]).to eq(cat3.id) end end @@ -141,12 +141,12 @@ describe CategoryList do it "returns categories in order of activity" do cat1 = Fabricate(:category, position: 0, posts_week: 1, posts_month: 1, posts_year: 1) cat2 = Fabricate(:category, position: 1, posts_week: 2, posts_month: 1, posts_year: 1) - category_ids.should == [cat2.id, cat1.id] + expect(category_ids).to eq([cat2.id, cat1.id]) end it "returns categories in order of id when there's no activity" do cat1, cat2 = Fabricate(:category, position: 1), Fabricate(:category, position: 0) - category_ids.should == [cat1.id, cat2.id] + expect(category_ids).to eq([cat1.id, cat2.id]) end end end diff --git a/spec/components/common_passwords/common_passwords_spec.rb b/spec/components/common_passwords/common_passwords_spec.rb index a1002005806..f1213432810 100644 --- a/spec/components/common_passwords/common_passwords_spec.rb +++ b/spec/components/common_passwords/common_passwords_spec.rb @@ -4,7 +4,7 @@ require_dependency "common_passwords/common_passwords" describe CommonPasswords do it "the passwords file should exist" do - File.exists?(described_class::PASSWORD_FILE).should eq(true) + expect(File.exists?(described_class::PASSWORD_FILE)).to eq(true) end describe "#common_password?" do @@ -15,25 +15,25 @@ describe CommonPasswords do it "returns false if password isn't in the common passwords list" do described_class.stubs(:password_list).returns(stub_everything(:include? => false)) @password = 'uncommonPassword' - subject.should eq(false) + expect(subject).to eq(false) end it "returns false if password is nil" do described_class.expects(:password_list).never @password = nil - subject.should eq(false) + expect(subject).to eq(false) end it "returns false if password is blank" do described_class.expects(:password_list).never @password = "" - subject.should eq(false) + expect(subject).to eq(false) end it "returns true if password is in the common passwords list" do described_class.stubs(:password_list).returns(stub_everything(:include? => true)) @password = "password" - subject.should eq(true) + expect(subject).to eq(true) end end @@ -45,7 +45,7 @@ describe CommonPasswords do described_class.stubs(:redis).returns(mock_redis) described_class.expects(:load_passwords).returns(['password']) list = described_class.password_list - list.should respond_to(:include?) + expect(list).to respond_to(:include?) end it "doesn't load the passwords file if redis has it" do @@ -55,7 +55,7 @@ describe CommonPasswords do described_class.stubs(:redis).returns(mock_redis) described_class.expects(:load_passwords).never list = described_class.password_list - list.should respond_to(:include?) + expect(list).to respond_to(:include?) end it "loads the passwords file if redis has an empty list" do @@ -65,7 +65,7 @@ describe CommonPasswords do described_class.stubs(:redis).returns(mock_redis) described_class.expects(:load_passwords).returns(['password']) list = described_class.password_list - list.should respond_to(:include?) + expect(list).to respond_to(:include?) end end @@ -73,7 +73,7 @@ describe CommonPasswords do it "tolerates it" do described_class.stubs(:redis).returns(stub_everything(sismember: false, exists: false, scard: 0)) File.stubs(:readlines).with(described_class::PASSWORD_FILE).raises(Errno::ENOENT) - described_class.common_password?("password").should eq(false) + expect(described_class.common_password?("password")).to eq(false) end end end diff --git a/spec/components/composer_messages_finder_spec.rb b/spec/components/composer_messages_finder_spec.rb index fdca2b68303..2a48b11a54f 100644 --- a/spec/components/composer_messages_finder_spec.rb +++ b/spec/components/composer_messages_finder_spec.rb @@ -32,12 +32,12 @@ describe ComposerMessagesFinder do it "returns a message for a user who has not posted any topics" do user.expects(:created_topic_count).returns(9) - finder.check_education_message.should be_present + expect(finder.check_education_message).to be_present end it "returns no message when the user has posted enough topics" do user.expects(:created_topic_count).returns(10) - finder.check_education_message.should be_blank + expect(finder.check_education_message).to be_blank end end @@ -50,12 +50,12 @@ describe ComposerMessagesFinder do it "returns a message for a user who has not posted any topics" do user.expects(:post_count).returns(9) - finder.check_education_message.should be_present + expect(finder.check_education_message).to be_present end it "returns no message when the user has posted enough topics" do user.expects(:post_count).returns(10) - finder.check_education_message.should be_blank + expect(finder.check_education_message).to be_blank end end end @@ -68,12 +68,12 @@ describe ComposerMessagesFinder do it "has no message when `posted_too_much_in_topic?` is false" do user.expects(:posted_too_much_in_topic?).returns(false) - finder.check_new_user_many_replies.should be_blank + expect(finder.check_new_user_many_replies).to be_blank end it "has a message when a user has posted too much" do user.expects(:posted_too_much_in_topic?).returns(true) - finder.check_new_user_many_replies.should be_present + expect(finder.check_new_user_many_replies).to be_present end end @@ -87,27 +87,27 @@ describe ComposerMessagesFinder do let!(:message) { finder.check_avatar_notification } it "returns an avatar upgrade message" do - message.should be_present + expect(message).to be_present end it "creates a notified_about_avatar log" do - UserHistory.exists_for_user?(user, :notified_about_avatar).should == true + expect(UserHistory.exists_for_user?(user, :notified_about_avatar)).to eq(true) end end it "doesn't return notifications for new users" do user.trust_level = TrustLevel[0] - finder.check_avatar_notification.should be_blank + expect(finder.check_avatar_notification).to be_blank end it "doesn't return notifications for users who have custom avatars" do user.uploaded_avatar_id = 1 - finder.check_avatar_notification.should be_blank + expect(finder.check_avatar_notification).to be_blank end it "doesn't notify users who have been notified already" do UserHistory.create!(action: UserHistory.actions[:notified_about_avatar], target_user_id: user.id ) - finder.check_avatar_notification.should be_blank + expect(finder.check_avatar_notification).to be_blank end end @@ -127,11 +127,11 @@ describe ComposerMessagesFinder do it "does not give a message for new topics" do finder = ComposerMessagesFinder.new(user, composerAction: 'createTopic') - finder.check_sequential_replies.should be_blank + expect(finder.check_sequential_replies).to be_blank end it "does not give a message without a topic id" do - ComposerMessagesFinder.new(user, composerAction: 'reply').check_sequential_replies.should be_blank + expect(ComposerMessagesFinder.new(user, composerAction: 'reply').check_sequential_replies).to be_blank end context "reply" do @@ -140,39 +140,39 @@ describe ComposerMessagesFinder do it "does not give a message to users who are still in the 'education' phase" do user.stubs(:post_count).returns(9) - finder.check_sequential_replies.should be_blank + expect(finder.check_sequential_replies).to be_blank end it "doesn't notify a user it has already notified about sequential replies" do UserHistory.create!(action: UserHistory.actions[:notified_about_sequential_replies], target_user_id: user.id, topic_id: topic.id ) - finder.check_sequential_replies.should be_blank + expect(finder.check_sequential_replies).to be_blank end it "will notify you if it hasn't in the current topic" do UserHistory.create!(action: UserHistory.actions[:notified_about_sequential_replies], target_user_id: user.id, topic_id: topic.id+1 ) - finder.check_sequential_replies.should be_present + expect(finder.check_sequential_replies).to be_present end it "doesn't notify a user who has less than the `sequential_replies_threshold` threshold posts" do SiteSetting.stubs(:sequential_replies_threshold).returns(5) - finder.check_sequential_replies.should be_blank + expect(finder.check_sequential_replies).to be_blank end it "doesn't notify a user if another user posted" do Fabricate(:post, topic: topic, user: Fabricate(:user)) - finder.check_sequential_replies.should be_blank + expect(finder.check_sequential_replies).to be_blank end context "success" do let!(:message) { finder.check_sequential_replies } it "returns a message" do - message.should be_present + expect(message).to be_present end it "creates a notified_about_sequential_replies log" do - UserHistory.exists_for_user?(user, :notified_about_sequential_replies).should == true + expect(UserHistory.exists_for_user?(user, :notified_about_sequential_replies)).to eq(true) end end @@ -199,11 +199,11 @@ describe ComposerMessagesFinder do it "does not give a message for new topics" do finder = ComposerMessagesFinder.new(user, composerAction: 'createTopic') - finder.check_dominating_topic.should be_blank + expect(finder.check_dominating_topic).to be_blank end it "does not give a message without a topic id" do - ComposerMessagesFinder.new(user, composerAction: 'reply').check_dominating_topic.should be_blank + expect(ComposerMessagesFinder.new(user, composerAction: 'reply').check_dominating_topic).to be_blank end context "reply" do @@ -211,53 +211,53 @@ describe ComposerMessagesFinder do it "does not give a message to users who are still in the 'education' phase" do user.stubs(:post_count).returns(9) - finder.check_dominating_topic.should be_blank + expect(finder.check_dominating_topic).to be_blank end it "does not notify if the `summary_posts_required` has not been reached" do SiteSetting.stubs(:summary_posts_required).returns(100) - finder.check_dominating_topic.should be_blank + expect(finder.check_dominating_topic).to be_blank end it "doesn't notify a user it has already notified in this topic" do UserHistory.create!(action: UserHistory.actions[:notified_about_dominating_topic], topic_id: topic.id, target_user_id: user.id ) - finder.check_dominating_topic.should be_blank + expect(finder.check_dominating_topic).to be_blank end it "notifies a user if the topic is different" do UserHistory.create!(action: UserHistory.actions[:notified_about_dominating_topic], topic_id: topic.id+1, target_user_id: user.id ) - finder.check_dominating_topic.should be_present + expect(finder.check_dominating_topic).to be_present end it "doesn't notify a user if the topic has less than `summary_posts_required` posts" do SiteSetting.stubs(:summary_posts_required).returns(5) - finder.check_dominating_topic.should be_blank + expect(finder.check_dominating_topic).to be_blank end it "doesn't notify a user if they've posted less than the percentage" do SiteSetting.stubs(:dominating_topic_minimum_percent).returns(100) - finder.check_dominating_topic.should be_blank + expect(finder.check_dominating_topic).to be_blank end it "doesn't notify you if it's your own topic" do topic.update_column(:user_id, user.id) - finder.check_dominating_topic.should be_blank + expect(finder.check_dominating_topic).to be_blank end it "doesn't notify you in a private message" do topic.update_columns(category_id: nil, archetype: Archetype.private_message) - finder.check_dominating_topic.should be_blank + expect(finder.check_dominating_topic).to be_blank end context "success" do let!(:message) { finder.check_dominating_topic } it "returns a message" do - message.should be_present + expect(message).to be_present end it "creates a notified_about_dominating_topic log" do - UserHistory.exists_for_user?(user, :notified_about_dominating_topic).should == true + expect(UserHistory.exists_for_user?(user, :notified_about_dominating_topic)).to eq(true) end end @@ -270,8 +270,8 @@ describe ComposerMessagesFinder do let(:topic) { Fabricate(:topic) } it "does not give a message without a topic id" do - described_class.new(user, composerAction: 'createTopic').check_reviving_old_topic.should be_blank - described_class.new(user, composerAction: 'reply').check_reviving_old_topic.should be_blank + expect(described_class.new(user, composerAction: 'createTopic').check_reviving_old_topic).to be_blank + expect(described_class.new(user, composerAction: 'reply').check_reviving_old_topic).to be_blank end context "a reply" do @@ -282,12 +282,12 @@ describe ComposerMessagesFinder do it "does not notify if last post is recent" do topic = Fabricate(:topic, last_posted_at: 1.hour.ago) - described_class.new(user, composerAction: 'reply', topic_id: topic.id).check_reviving_old_topic.should be_blank + expect(described_class.new(user, composerAction: 'reply', topic_id: topic.id).check_reviving_old_topic).to be_blank end it "notifies if last post is old" do topic = Fabricate(:topic, last_posted_at: 181.days.ago) - described_class.new(user, composerAction: 'reply', topic_id: topic.id).check_reviving_old_topic.should_not be_blank + expect(described_class.new(user, composerAction: 'reply', topic_id: topic.id).check_reviving_old_topic).not_to be_blank end end @@ -298,12 +298,12 @@ describe ComposerMessagesFinder do it "does not notify if last post is new" do topic = Fabricate(:topic, last_posted_at: 1.hour.ago) - described_class.new(user, composerAction: 'reply', topic_id: topic.id).check_reviving_old_topic.should be_blank + expect(described_class.new(user, composerAction: 'reply', topic_id: topic.id).check_reviving_old_topic).to be_blank end it "does not notify if last post is old" do topic = Fabricate(:topic, last_posted_at: 365.days.ago) - described_class.new(user, composerAction: 'reply', topic_id: topic.id).check_reviving_old_topic.should be_blank + expect(described_class.new(user, composerAction: 'reply', topic_id: topic.id).check_reviving_old_topic).to be_blank end end end diff --git a/spec/components/concern/has_custom_fields_spec.rb b/spec/components/concern/has_custom_fields_spec.rb index 0b7cfb90bcb..9776762a6f9 100644 --- a/spec/components/concern/has_custom_fields_spec.rb +++ b/spec/components/concern/has_custom_fields_spec.rb @@ -31,7 +31,7 @@ describe HasCustomFields do it "simple modification of custom fields" do test_item = CustomFieldsTestItem.new - test_item.custom_fields["a"].should == nil + expect(test_item.custom_fields["a"]).to eq(nil) test_item.custom_fields["bob"] = "marley" test_item.custom_fields["jack"] = "black" @@ -40,8 +40,8 @@ describe HasCustomFields do test_item = CustomFieldsTestItem.find(test_item.id) - test_item.custom_fields["bob"].should == "marley" - test_item.custom_fields["jack"].should == "black" + expect(test_item.custom_fields["bob"]).to eq("marley") + expect(test_item.custom_fields["jack"]).to eq("black") test_item.custom_fields.delete("bob") test_item.custom_fields["jack"] = "jill" @@ -49,42 +49,42 @@ describe HasCustomFields do test_item.save test_item = CustomFieldsTestItem.find(test_item.id) - test_item.custom_fields.should == {"jack" => "jill"} + expect(test_item.custom_fields).to eq({"jack" => "jill"}) end it "casts integers to string without error" do test_item = CustomFieldsTestItem.new - test_item.custom_fields["a"].should == nil + expect(test_item.custom_fields["a"]).to eq(nil) test_item.custom_fields["a"] = 0 - test_item.custom_fields["a"].should == 0 + expect(test_item.custom_fields["a"]).to eq(0) test_item.save # should be casted right after saving - test_item.custom_fields["a"].should == "0" + expect(test_item.custom_fields["a"]).to eq("0") test_item = CustomFieldsTestItem.find(test_item.id) - test_item.custom_fields["a"].should == "0" + expect(test_item.custom_fields["a"]).to eq("0") end it "reload loads from database" do test_item = CustomFieldsTestItem.new test_item.custom_fields["a"] = 0 - test_item.custom_fields["a"].should == 0 + expect(test_item.custom_fields["a"]).to eq(0) test_item.save # should be casted right after saving - test_item.custom_fields["a"].should == "0" + expect(test_item.custom_fields["a"]).to eq("0") CustomFieldsTestItem.exec_sql("UPDATE custom_fields_test_item_custom_fields SET value='1' WHERE custom_fields_test_item_id=? AND name='a'", test_item.id) # still the same, did not load - test_item.custom_fields["a"].should == "0" + expect(test_item.custom_fields["a"]).to eq("0") # refresh loads from database - test_item.reload.custom_fields["a"].should == "1" - test_item.custom_fields["a"].should == "1" + expect(test_item.reload.custom_fields["a"]).to eq("1") + expect(test_item.custom_fields["a"]).to eq("1") end it "double save actually saves" do @@ -97,7 +97,7 @@ describe HasCustomFields do test_item.save db_item = CustomFieldsTestItem.find(test_item.id) - db_item.custom_fields.should == {"a" => "b", "c" => "d"} + expect(db_item.custom_fields).to eq({"a" => "b", "c" => "d"}) end @@ -109,14 +109,14 @@ describe HasCustomFields do test_item.save db_item = CustomFieldsTestItem.find(test_item.id) - db_item.custom_fields.should == {"a" => ["b", "c", "d"]} + expect(db_item.custom_fields).to eq({"a" => ["b", "c", "d"]}) db_item.custom_fields.update('a' => ['c', 'd']) db_item.save - db_item.custom_fields.should == {"a" => ["c", "d"]} + expect(db_item.custom_fields).to eq({"a" => ["c", "d"]}) db_item.custom_fields.delete('a') - db_item.custom_fields.should == {} + expect(db_item.custom_fields).to eq({}) end @@ -125,10 +125,10 @@ describe HasCustomFields do test_item = CustomFieldsTestItem.new test_item.custom_fields = {"a" => ["b", 10, "d"]} test_item.save - test_item.custom_fields.should == {"a" => ["b", "10", "d"]} + expect(test_item.custom_fields).to eq({"a" => ["b", "10", "d"]}) db_item = CustomFieldsTestItem.find(test_item.id) - db_item.custom_fields.should == {"a" => ["b", "10", "d"]} + expect(db_item.custom_fields).to eq({"a" => ["b", "10", "d"]}) end @@ -141,13 +141,13 @@ describe HasCustomFields do test_item.save test_item.reload - test_item.custom_fields.should == {"bool" => true, "int" => 1} + expect(test_item.custom_fields).to eq({"bool" => true, "int" => 1}) end it "simple modifications don't interfere" do test_item = CustomFieldsTestItem.new - test_item.custom_fields["a"].should == nil + expect(test_item.custom_fields["a"]).to eq(nil) test_item.custom_fields["bob"] = "marley" test_item.custom_fields["jack"] = "black" @@ -155,7 +155,7 @@ describe HasCustomFields do test_item2 = CustomFieldsTestItem.new - test_item2.custom_fields["x"].should == nil + expect(test_item2.custom_fields["x"]).to eq(nil) test_item2.custom_fields["sixto"] = "rodriguez" test_item2.custom_fields["de"] = "la playa" @@ -164,8 +164,8 @@ describe HasCustomFields do test_item = CustomFieldsTestItem.find(test_item.id) test_item2 = CustomFieldsTestItem.find(test_item2.id) - test_item.custom_fields.should == {"jack" => "black", "bob" => "marley"} - test_item2.custom_fields.should == {"sixto" => "rodriguez", "de" => "la playa"} + expect(test_item.custom_fields).to eq({"jack" => "black", "bob" => "marley"}) + expect(test_item2.custom_fields).to eq({"sixto" => "rodriguez", "de" => "la playa"}) end it "supports bulk retrieval with a list of ids" do @@ -178,10 +178,10 @@ describe HasCustomFields do item2.save fields = CustomFieldsTestItem.custom_fields_for_ids([item1.id, item2.id], ['a', 'e']) - fields.should be_present - fields[item1.id]['a'].should =~ ['b', 'c', 'd'] - fields[item1.id]['not_whitelisted'].should be_blank - fields[item2.id]['e'].should == 'hallo' + expect(fields).to be_present + expect(fields[item1.id]['a']).to match_array(['b', 'c', 'd']) + expect(fields[item1.id]['not_whitelisted']).to be_blank + expect(fields[item2.id]['e']).to eq('hallo') end end end diff --git a/spec/components/concern/positionable_spec.rb b/spec/components/concern/positionable_spec.rb index da5ae19a6c5..4e4b6d490ac 100644 --- a/spec/components/concern/positionable_spec.rb +++ b/spec/components/concern/positionable_spec.rb @@ -28,24 +28,24 @@ describe Positionable do Topic.exec_sql("insert into test_items(id,position) values(#{i}, #{i})") end - positions.should == [0,1,2,3,4] + expect(positions).to eq([0,1,2,3,4]) TestItem.find(3).move_to(0) - positions.should == [3,0,1,2,4] - TestItem.pluck(:position).sort.should == [0,1,2,3,4] + expect(positions).to eq([3,0,1,2,4]) + expect(TestItem.pluck(:position).sort).to eq([0,1,2,3,4]) TestItem.find(3).move_to(1) - positions.should == [0,3,1,2,4] + expect(positions).to eq([0,3,1,2,4]) # this is somewhat odd, but when there is no such position, not much we can do TestItem.find(1).move_to(5) - positions.should == [0,3,2,4,1] + expect(positions).to eq([0,3,2,4,1]) - TestItem.pluck(:position).sort.should == [0,1,2,3,4] + expect(TestItem.pluck(:position).sort).to eq([0,1,2,3,4]) item = TestItem.new item.id = 7 item.save - item.position.should == 5 + expect(item.position).to eq(5) end end end diff --git a/spec/components/content_buffer_spec.rb b/spec/components/content_buffer_spec.rb index 43c265b2ade..8e6299896b1 100644 --- a/spec/components/content_buffer_spec.rb +++ b/spec/components/content_buffer_spec.rb @@ -6,24 +6,24 @@ describe ContentBuffer do it "handles deletion across lines properly" do c = ContentBuffer.new("a\nbc\nc") c.apply_transform!(start: {row: 0, col: 0}, finish: {col: 1, row: 1}, operation: :delete) - c.to_s.should == "c\nc" + expect(c.to_s).to eq("c\nc") end it "handles deletion inside lines properly" do c = ContentBuffer.new("hello world") c.apply_transform!(start: {row: 0, col: 1}, finish: {col: 4, row: 0}, operation: :delete) - c.to_s.should == "ho world" + expect(c.to_s).to eq("ho world") end it "handles inserts inside lines properly" do c = ContentBuffer.new("hello!") c.apply_transform!(start: {row: 0, col: 5}, operation: :insert, text: " world") - c.to_s.should == "hello world!" + expect(c.to_s).to eq("hello world!") end it "handles multiline inserts" do c = ContentBuffer.new("hello!") c.apply_transform!(start: {row: 0, col: 5}, operation: :insert, text: "\nworld") - c.to_s.should == "hello\nworld!" + expect(c.to_s).to eq("hello\nworld!") end end diff --git a/spec/components/cooked_post_processor_spec.rb b/spec/components/cooked_post_processor_spec.rb index ae90bf35697..6b5ff79f41c 100644 --- a/spec/components/cooked_post_processor_spec.rb +++ b/spec/components/cooked_post_processor_spec.rb @@ -49,10 +49,10 @@ describe CookedPostProcessor do it "works" do # adds the width from the image sizes provided when no dimension is provided - cpp.html.should =~ /src="http:\/\/foo.bar\/image.png" width="111" height="222"/ + expect(cpp.html).to match(/src="http:\/\/foo.bar\/image.png" width="111" height="222"/) # adds the width from the image sizes provided - cpp.html.should =~ /src="http:\/\/domain.com\/picture.jpg" width="50" height="42"/ - cpp.should be_dirty + expect(cpp.html).to match(/src="http:\/\/domain.com\/picture.jpg" width="50" height="42"/) + expect(cpp).to be_dirty end end @@ -65,8 +65,8 @@ describe CookedPostProcessor do it "adds the width and height to images that don't have them" do FastImage.expects(:size).returns([123, 456]) cpp.post_process_images - cpp.html.should =~ /width="123" height="456"/ - cpp.should be_dirty + expect(cpp.html).to match(/width="123" height="456"/) + expect(cpp).to be_dirty end end @@ -90,10 +90,10 @@ describe CookedPostProcessor do it "generates overlay information" do cpp.post_process_images - cpp.html.should match_html '