mirror of
https://github.com/discourse/discourse.git
synced 2025-05-26 04:33:38 +08:00
DEV: Avoid instance variables in specs
Small followup of https://github.com/discourse/discourse/pull/27705
This commit is contained in:

committed by
Loïc Guitaut

parent
797f659eed
commit
b0480dd34e
@ -1,19 +1,23 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
RSpec.describe Onebox::Engine::GithubBlobOnebox do
|
||||
let(:raw_uri) do
|
||||
"https://raw.githubusercontent.com/discourse/onebox/master/lib/onebox/engine/github_blob_onebox.rb"
|
||||
end
|
||||
|
||||
before do
|
||||
@link =
|
||||
"https://github.com/discourse/onebox/blob/master/lib/onebox/engine/github_blob_onebox.rb"
|
||||
@uri = URI.parse(@link)
|
||||
@raw_uri =
|
||||
"https://raw.githubusercontent.com/discourse/onebox/master/lib/onebox/engine/github_blob_onebox.rb"
|
||||
stub_request(:get, @raw_uri).to_return(
|
||||
stub_request(:get, raw_uri).to_return(
|
||||
status: 200,
|
||||
body: onebox_response(described_class.onebox_name),
|
||||
)
|
||||
end
|
||||
|
||||
include_context "with engines"
|
||||
include_context "with engines" do
|
||||
let(:link) do
|
||||
"https://github.com/discourse/onebox/blob/master/lib/onebox/engine/github_blob_onebox.rb"
|
||||
end
|
||||
let(:uri) { URI.parse(link) }
|
||||
end
|
||||
it_behaves_like "an engine"
|
||||
|
||||
describe "#to_html" do
|
||||
@ -27,15 +31,15 @@ RSpec.describe Onebox::Engine::GithubBlobOnebox do
|
||||
|
||||
it "does not include blob contents if it is binary" do
|
||||
# stub_request if the response must be binary (ASCII-8BIT)
|
||||
uri = mock("object")
|
||||
uri.stubs(:open).returns(File.open("#{Rails.root}/spec/fixtures/pdf/small.pdf", "rb"))
|
||||
URI.stubs(:parse).with(@link).returns(@uri)
|
||||
uri_mock = mock("object")
|
||||
uri_mock.stubs(:open).returns(File.open("#{Rails.root}/spec/fixtures/pdf/small.pdf", "rb"))
|
||||
URI.stubs(:parse).with(link).returns(uri)
|
||||
URI
|
||||
.stubs(:parse)
|
||||
.with(
|
||||
"https://raw.githubusercontent.com/discourse/onebox/master/lib/onebox/engine/github_blob_onebox.rb",
|
||||
)
|
||||
.returns(uri)
|
||||
.returns(uri_mock)
|
||||
|
||||
expect(html).not_to include("/Pages")
|
||||
expect(html).to include("This file is binary.")
|
||||
@ -46,7 +50,7 @@ RSpec.describe Onebox::Engine::GithubBlobOnebox do
|
||||
|
||||
it "sends it as part of the request" do
|
||||
html
|
||||
expect(WebMock).to have_requested(:get, @raw_uri).with(
|
||||
expect(WebMock).to have_requested(:get, raw_uri).with(
|
||||
headers: {
|
||||
"Authorization" => "Bearer #{SiteSetting.github_onebox_access_token}",
|
||||
},
|
||||
|
Reference in New Issue
Block a user