Add RSpec 4 compatibility (#17652)

* Remove outdated option

04078317ba

* Use the non-globally exposed RSpec syntax

https://github.com/rspec/rspec-core/pull/2803

* Use the non-globally exposed RSpec syntax, cont

https://github.com/rspec/rspec-core/pull/2803

* Comply to strict predicate matchers

See:
 - https://github.com/rspec/rspec-expectations/pull/1195
 - https://github.com/rspec/rspec-expectations/pull/1196
 - https://github.com/rspec/rspec-expectations/pull/1277
This commit is contained in:
Phil Pirozhkov
2022-07-28 05:27:38 +03:00
committed by GitHub
parent 72b24f3fb9
commit 493d437e79
736 changed files with 781 additions and 782 deletions

View File

@@ -1,6 +1,6 @@
# frozen_string_literal: true
describe Onebox::DomainChecker do
RSpec.describe Onebox::DomainChecker do
describe '.is_blocked?' do
before do
SiteSetting.blocked_onebox_domains = "api.cat.org|kitten.cloud"

View File

@@ -1,6 +1,6 @@
# frozen_string_literal: true
describe Onebox::Engine::AllowlistedGenericOnebox do
RSpec.describe Onebox::Engine::AllowlistedGenericOnebox do
describe ".===" do
it "matches any domain" do
expect(described_class === URI('http://foo.bar/resource')).to be(true)

View File

@@ -1,6 +1,6 @@
# frozen_string_literal: true
describe Onebox::Engine::AmazonOnebox do
RSpec.describe Onebox::Engine::AmazonOnebox do
context "regular amazon page" do
before do
@link = "https://www.amazon.com/Knit-Noro-Accessories-Colorful-Little/dp/193609620X"

View File

@@ -1,6 +1,6 @@
# frozen_string_literal: true
describe Onebox::Engine::AnimatedImageOnebox do
RSpec.describe Onebox::Engine::AnimatedImageOnebox do
let(:giphy) { "http://gph.is/15bRbWf" }
let(:direct_gif) { "https://media4.giphy.com/media/Zatyu5LBO2zCyhiAAs/giphy.gif" }
let(:tenor) { "https://tenor.com/bb3fQ.gif" }

View File

@@ -1,6 +1,6 @@
# frozen_string_literal: true
describe Onebox::Engine::AudioOnebox do
RSpec.describe Onebox::Engine::AudioOnebox do
it "supports ogg" do
expect(Onebox.preview('http://upload.wikimedia.org/wikipedia/commons/c/c8/Example.ogg').to_s).to match(/<audio/)
end

View File

@@ -1,6 +1,6 @@
# frozen_string_literal: true
describe Onebox::Engine::CloudAppOnebox do
RSpec.describe Onebox::Engine::CloudAppOnebox do
before do
stub_request(:get, "https://cl.ly/0m2a2u2k440O").to_return(status: 200, body: onebox_response("cloudapp-gif"))
stub_request(:get, "https://cl.ly/0T0c2J3S373X").to_return(status: 200, body: onebox_response("cloudapp-mp4"))

View File

@@ -1,6 +1,6 @@
# frozen_string_literal: true
describe Onebox::Engine::GfycatOnebox do
RSpec.describe Onebox::Engine::GfycatOnebox do
let(:link) { "https://gfycat.com/shrillnegativearrowana" }
let(:html) { described_class.new(link).to_html }
let(:placeholder_html) { described_class.new(link).placeholder_html }

View File

@@ -1,6 +1,6 @@
# frozen_string_literal: true
describe Onebox::Engine::GithubActionsOnebox do
RSpec.describe Onebox::Engine::GithubActionsOnebox do
describe "PR check run" do
before do
@link = "https://github.com/discourse/discourse/pull/13128/checks?check_run_id=2660861130"

View File

@@ -1,6 +1,6 @@
# frozen_string_literal: true
describe Onebox::Engine::GithubBlobOnebox do
RSpec.describe Onebox::Engine::GithubBlobOnebox do
before do
@link = "https://github.com/discourse/onebox/blob/master/lib/onebox/engine/github_blob_onebox.rb"
@uri = URI.parse(@link)

View File

@@ -1,6 +1,6 @@
# frozen_string_literal: true
describe Onebox::Engine::GithubCommitOnebox do
RSpec.describe Onebox::Engine::GithubCommitOnebox do
describe "regular commit url" do
before do
@link = "https://github.com/discourse/discourse/commit/803d023e2307309f8b776ab3b8b7e38ba91c0919"

View File

@@ -1,6 +1,6 @@
# frozen_string_literal: true
describe Onebox::Engine::GithubFolderOnebox do
RSpec.describe Onebox::Engine::GithubFolderOnebox do
context 'without fragments' do
before do
@link = "https://github.com/discourse/discourse/tree/main/spec/fixtures"

View File

@@ -1,6 +1,6 @@
# frozen_string_literal: true
describe Onebox::Engine::GithubGistOnebox do
RSpec.describe Onebox::Engine::GithubGistOnebox do
before do
@link = "https://gist.github.com/karreiro/208fdd59fc4b4c39283b"

View File

@@ -1,6 +1,6 @@
# frozen_string_literal: true
describe Onebox::Engine::GithubPullRequestOnebox do
RSpec.describe Onebox::Engine::GithubPullRequestOnebox do
before do
@link = "https://github.com/discourse/discourse/pull/1253/"
@uri = "https://api.github.com/repos/discourse/discourse/pulls/1253"

View File

@@ -1,6 +1,6 @@
# frozen_string_literal: true
describe Onebox::Engine::GitlabBlobOnebox do
RSpec.describe Onebox::Engine::GitlabBlobOnebox do
before do
@link = "https://gitlab.com/discourse/onebox/blob/master/lib/onebox/engine/gitlab_blob_onebox.rb"

View File

@@ -1,6 +1,6 @@
# frozen_string_literal: true
describe Onebox::Engine::GoogleDocsOnebox do
RSpec.describe Onebox::Engine::GoogleDocsOnebox do
before do
@link = "https://docs.google.com/document/d/DOC_KEY/pub"

View File

@@ -1,6 +1,6 @@
# frozen_string_literal: true
describe Onebox::Engine::GoogleDriveOnebox do
RSpec.describe Onebox::Engine::GoogleDriveOnebox do
let(:link) { "https://drive.google.com/file/d/1FgMt06wENEUfC6_-1tImXaNCH7vM9QsA/view" }
let(:html) { described_class.new(link).to_html }

View File

@@ -1,6 +1,6 @@
# frozen_string_literal: true
describe Onebox::Engine::GoogleMapsOnebox do
RSpec.describe Onebox::Engine::GoogleMapsOnebox do
URLS = {
short: {
test: "https://goo.gl/maps/rEG3D",

View File

@@ -1,6 +1,6 @@
# frozen_string_literal: true
describe Onebox::Engine::GooglePhotosOnebox do
RSpec.describe Onebox::Engine::GooglePhotosOnebox do
let(:link) { "https://photos.app.goo.gl/pXA7T8zBX4WZWVMT7" }
let(:html) { described_class.new(link).to_html }

View File

@@ -1,6 +1,6 @@
# frozen_string_literal: true
describe Onebox::Engine::GooglePlayAppOnebox do
RSpec.describe Onebox::Engine::GooglePlayAppOnebox do
before do
@link = "https://play.google.com/store/apps/details?id=com.hulu.plus&hl=en"

View File

@@ -1,6 +1,6 @@
# frozen_string_literal: true
describe Onebox::Engine::HackernewsOnebox do
RSpec.describe Onebox::Engine::HackernewsOnebox do
context "When oneboxing a comment" do
let(:link) { "https://news.ycombinator.com/item?id=30181167" }
let(:api_link) { "https://hacker-news.firebaseio.com/v0/item/30181167.json" }

View File

@@ -1,6 +1,6 @@
# frozen_string_literal: true
describe Onebox::Engine::HTML do
RSpec.describe Onebox::Engine::HTML do
before do
@link = "http://amazon.com"

View File

@@ -1,6 +1,6 @@
# frozen_string_literal: true
describe Onebox::Engine::ImageOnebox do
RSpec.describe Onebox::Engine::ImageOnebox do
it "supports png" do
expect(Onebox.preview('http://www.discourse.org/images/logo.png').to_s).to match(/<img/)
end

View File

@@ -1,6 +1,6 @@
# frozen_string_literal: true
describe Onebox::Engine::ImgurOnebox do
RSpec.describe Onebox::Engine::ImgurOnebox do
let(:link) { "https://imgur.com/gallery/Sdc0Klc" }
let(:imgur) { described_class.new(link) }
let(:html) { imgur.to_html }

View File

@@ -1,6 +1,6 @@
# frozen_string_literal: true
describe Onebox::Engine::InstagramOnebox do
RSpec.describe Onebox::Engine::InstagramOnebox do
let(:access_token) { 'abc123' }
let(:link) { "https://www.instagram.com/p/CARbvuYDm3Q" }
let(:onebox_options) { { allowed_iframe_regexes: Onebox::Engine.origins_to_regexes(["https://www.instagram.com"]) } }

View File

@@ -1,6 +1,6 @@
# frozen_string_literal: true
describe Onebox::Engine::JSON do
RSpec.describe Onebox::Engine::JSON do
before do
@link = "http://stackoverflow.com"
stub_request(:get, @link).to_return(status: 200, body: onebox_response("stackexchange-question"))

View File

@@ -1,6 +1,6 @@
# frozen_string_literal: true
describe Onebox::Engine::KalturaOnebox do
RSpec.describe Onebox::Engine::KalturaOnebox do
let(:link) { 'https://videos.kaltura.com/id/0_e2ea6ygt' }
before do

View File

@@ -1,6 +1,6 @@
# frozen_string_literal: true
describe Onebox::Engine::PdfOnebox do
RSpec.describe Onebox::Engine::PdfOnebox do
let(:link) { "https://acrobatusers.com/assets/uploads/public_downloads/2217/adobe-acrobat-xi-merge-pdf-files-tutorial-ue.pdf" }
let(:html) { described_class.new(link).to_html }

View File

@@ -1,6 +1,6 @@
# frozen_string_literal: true
describe Onebox::Engine::PubmedOnebox do
RSpec.describe Onebox::Engine::PubmedOnebox do
let(:link) { "http://www.ncbi.nlm.nih.gov/pubmed/7288891" }
let(:xml_link) { "http://www.ncbi.nlm.nih.gov/pubmed/7288891?report=xml&format=text" }
let(:html) { described_class.new(link).to_html }

View File

@@ -1,6 +1,6 @@
# frozen_string_literal: true
describe Onebox::Engine::RedditMediaOnebox do
RSpec.describe Onebox::Engine::RedditMediaOnebox do
let(:link) { "https://www.reddit.com/r/colors/comments/b4d5xm/literally_nothing_black_edition" }
let(:html) { described_class.new(link).to_html }

View File

@@ -1,6 +1,6 @@
# frozen_string_literal: true
describe Onebox::Engine::SlidesOnebox do
RSpec.describe Onebox::Engine::SlidesOnebox do
let(:link) { "http://slides.com/drksephy/ecmascript-2015" }
let(:html) { described_class.new(link).to_html }

View File

@@ -1,6 +1,6 @@
# frozen_string_literal: true
describe Onebox::Engine::StackExchangeOnebox do
RSpec.describe Onebox::Engine::StackExchangeOnebox do
describe 'domains' do
[
'stackoverflow.com', 'meta.stackoverflow.com',

View File

@@ -1,6 +1,6 @@
# frozen_string_literal: true
describe Onebox::Engine::StandardEmbed do
RSpec.describe Onebox::Engine::StandardEmbed do
let(:host_class) do
Class.new do
include Onebox::Engine::StandardEmbed

View File

@@ -1,6 +1,6 @@
# frozen_string_literal: true
describe Onebox::Engine::TrelloOnebox do
RSpec.describe Onebox::Engine::TrelloOnebox do
context "Boards" do
it "should onebox with SEF url corrrectly" do
expect(Onebox.preview('https://trello.com/b/nC8QJJoZ/trello-development-roadmap').to_s).to match('iframe src="https://trello.com/b/nC8QJJoZ.html"')

View File

@@ -1,6 +1,6 @@
# frozen_string_literal: true
describe Onebox::Engine::TwitchClipsOnebox do
RSpec.describe Onebox::Engine::TwitchClipsOnebox do
let(:hostname) { 'www.example.com' }
let(:options) { { hostname: hostname } }

View File

@@ -1,6 +1,6 @@
# frozen_string_literal: true
describe Onebox::Engine::TwitchStreamOnebox do
RSpec.describe Onebox::Engine::TwitchStreamOnebox do
let(:hostname) { 'www.example.com' }
let(:options) { { hostname: hostname } }

View File

@@ -1,6 +1,6 @@
# frozen_string_literal: true
describe Onebox::Engine::TwitchVideoOnebox do
RSpec.describe Onebox::Engine::TwitchVideoOnebox do
let(:hostname) { 'www.example.com' }
let(:options) { { hostname: hostname } }

View File

@@ -1,6 +1,6 @@
# frozen_string_literal: true
describe Onebox::Engine::TwitterStatusOnebox do
RSpec.describe Onebox::Engine::TwitterStatusOnebox do
shared_examples_for "#to_html" do
it "includes tweet" do
expect(html).to include(tweet_content)

View File

@@ -1,6 +1,6 @@
# frozen_string_literal: true
describe Onebox::Engine::TypeformOnebox do
RSpec.describe Onebox::Engine::TypeformOnebox do
it 'Appends the embed widget param when is missing' do
raw_preview = Onebox.preview('https://basvanleeuwen1.typeform.com/to/NzdRpx').to_s
query_params = get_query_params(raw_preview)

View File

@@ -1,6 +1,6 @@
# frozen_string_literal: true
describe Onebox::Engine::VideoOnebox do
RSpec.describe Onebox::Engine::VideoOnebox do
it "supports ogv" do
expect(Onebox.preview('http://upload.wikimedia.org/wikipedia/commons/3/37/STS-134_launch_2.ogv').to_s).to match(/<video/)
end

View File

@@ -1,6 +1,6 @@
# frozen_string_literal: true
describe Onebox::Engine::WikimediaOnebox do
RSpec.describe Onebox::Engine::WikimediaOnebox do
let(:link) { "https://commons.wikimedia.org/wiki/File:Stones_members_montage2.jpg" }
let(:api_link) { "https://en.wikipedia.org/w/api.php?action=query&titles=File:Stones_members_montage2.jpg&prop=imageinfo&iilimit=50&iiprop=timestamp|user|url&iiurlwidth=500&format=json" }
let(:html) { described_class.new(link).to_html }

View File

@@ -1,6 +1,6 @@
# frozen_string_literal: true
describe Onebox::Engine::WikipediaOnebox do
RSpec.describe Onebox::Engine::WikipediaOnebox do
before do
@link = "http://en.wikipedia.org/wiki/Billy_Jack"

View File

@@ -1,6 +1,6 @@
# frozen_string_literal: true
describe Onebox::Engine::WistiaOnebox do
RSpec.describe Onebox::Engine::WistiaOnebox do
before do
body = '{"version":"1.0","type":"video","html":"\u003ciframe src=\"https://fast.wistia.net/embed/iframe/26sk4lmiix\" title=\"Nice. Video\" allow=\"autoplay; fullscreen\" allowtransparency=\"true\" frameborder=\"0\" scrolling=\"no\" class=\"wistia_embed\" name=\"wistia_embed\" msallowfullscreen width=\"960\" height=\"540\"\u003e\u003c/iframe\u003e\n\u003cscript src=\"https://fast.wistia.net/assets/external/E-v1.js\" async\u003e\u003c/script\u003e","width":960,"height":540,"provider_name":"Wistia, Inc.","provider_url":"https://wistia.com","title":"Nice. ","thumbnail_url":"https://embed-ssl.wistia.com/deliveries/56cacb9a5d6ea04b1f29defaf4b55d1ec979e1b0.jpg?image_crop_resized=960x540","thumbnail_width":960,"thumbnail_height":540,"player_color":"f27398","duration":44.42}'

View File

@@ -1,6 +1,6 @@
# frozen_string_literal: true
describe Onebox::Engine::XkcdOnebox do
RSpec.describe Onebox::Engine::XkcdOnebox do
let(:link) { "https://xkcd.com/327/" }
let(:api_link) { "https://xkcd.com/327/info.0.json" }
let(:html) { described_class.new(link).to_html }

View File

@@ -1,6 +1,6 @@
# frozen_string_literal: true
describe Onebox::Engine::YoukuOnebox do
RSpec.describe Onebox::Engine::YoukuOnebox do
before do
stub_request(:get, 'http://v.youku.com/v_show/id_XNjM3MzAxNzc2.html')
.to_return(status: 200, body: onebox_response('youku'), headers: { content_type: 'text/html' })

View File

@@ -1,6 +1,6 @@
# frozen_string_literal: true
describe Onebox::Engine::YoutubeOnebox do
RSpec.describe Onebox::Engine::YoutubeOnebox do
before do
stub_request(:get, "https://www.youtube.com/watch?feature=player_embedded&v=21Lk4YiASMo").to_return(status: 200, body: onebox_response("youtube"))
stub_request(:get, "https://youtu.be/21Lk4YiASMo").to_return(status: 200, body: onebox_response("youtube"))

View File

@@ -1,6 +1,6 @@
# frozen_string_literal: true
describe Onebox::Engine do
RSpec.describe Onebox::Engine do
class OneboxEngineExample
include Onebox::Engine
@@ -88,7 +88,7 @@ describe Onebox::Engine do
end
end
describe ".onebox_name" do
RSpec.describe ".onebox_name" do
module ScopeForTemplateName
class TemplateNameOnebox
include Onebox::Engine

View File

@@ -2,7 +2,7 @@
require 'onebox/json_ld'
describe Onebox::JsonLd do
RSpec.describe Onebox::JsonLd do
it 'logs warning and returns an empty hash if received json is invalid' do
invalid_json = "{\"@type\":invalid-json}"
doc = Nokogiri::HTML("<script type=\"application/ld+json\">#{invalid_json}</script>")

View File

@@ -1,6 +1,6 @@
# frozen_string_literal: true
describe Onebox::Layout do
RSpec.describe Onebox::Layout do
let(:record) { {} }
let(:layout) { described_class.new("amazon", record) }
let(:html) { layout.to_html }

View File

@@ -10,7 +10,7 @@ class TestEngine
end
end
describe Onebox::Matcher do
RSpec.describe Onebox::Matcher do
let(:opts) { { allowed_iframe_regexes: [/.*/] } }
describe "oneboxed" do

View File

@@ -2,7 +2,7 @@
require 'onebox/movie'
describe Onebox::Movie do
RSpec.describe Onebox::Movie do
it 'returns a nil rating if there is no aggregateRating item in json_ld data' do
json_ld_data = json_ld_data_from_doc(
"<script type=\"application/ld+json\">{\"@type\":\"Movie\",\"someKey\":{}}</script>"

View File

@@ -2,7 +2,7 @@
require "onebox/oembed"
describe Onebox::Oembed do
RSpec.describe Onebox::Oembed do
it "excludes text tags" do
json = '{"text": "<iframe src=\'https://ifram.es/foo/bar\'></iframe>"}'
oembed = described_class.new(json)

View File

@@ -2,7 +2,7 @@
require "onebox/open_graph"
describe Onebox::OpenGraph do
RSpec.describe Onebox::OpenGraph do
it "excludes html tags in title" do
doc = Nokogiri::HTML('<html><title>Did&#8217; you &lt;b&gt;miss me&lt;/b&gt;? - Album on Imgur</title><meta name="og:description" content="Post with 7 votes and 151 views. Shared by vinothkannans. Did you &lt;b&gt;miss me&lt;/b&gt;?" /><meta property="og:image" content="https://i.imgur.com/j1CNCZY.gif?noredirect" /></html>')
og = described_class.new(doc)

View File

@@ -1,6 +1,6 @@
# frozen_string_literal: true
describe Onebox::Preview do
RSpec.describe Onebox::Preview do
before do
stub_request(:get, "https://www.amazon.com/product")
.to_return(status: 200, body: onebox_response("amazon"))

View File

@@ -1,6 +1,6 @@
# frozen_string_literal: true
describe Onebox::StatusCheck do
RSpec.describe Onebox::StatusCheck do
before do
stub_request(:get, "http://www.amazon.com/200-url").to_return(status: 200)
stub_request(:get, "http://www.amazon.com/201-url").to_return(status: 201)