Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reduce duplication of fixture SHAs in tests #15610

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,14 @@ Reek::Rake::Task.new do |t|
end

task 'everypolitician-data', [:path] do |_, args|
require 'everypolitician'
index = Everypolitician::Index.new(index_url: 't/fixtures/d8a4682f-countries.json')
legislature = index.countries.flat_map(&:legislatures).find do |l|
args[:path].start_with?("data/#{l.directory}")
end
fixture_path = Pathname.new(File.join('t/fixtures/everypolitician-data', args[:path]))
mkdir_p(fixture_path.dirname)
fixture_path.write(open("https://cdn.rawgit.com/everypolitician/everypolitician-data/#{args[:path]}").read)
fixture_path.write(open("https://cdn.rawgit.com/everypolitician/everypolitician-data/#{legislature.sha}/#{args[:path]}").read)
end

# Check for known vulnerabilities in Gemfile.lock
Expand Down
4 changes: 2 additions & 2 deletions t/everypolitician_extensions/membership_extension.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

describe 'MembershipExtensions' do
subject do
stub_popolo('3df153b', 'Austria/Nationalrat')
stub_popolo('Austria/Nationalrat')
index_at_known_sha.country('austria')
.legislature('nationalrat')
.popolo
Expand All @@ -31,7 +31,7 @@

describe 'MembershipExtensions -- memberships with no known groups or area names' do
subject do
stub_popolo('2b38667', 'Afghanistan/Wolesi_Jirga')
stub_popolo('Afghanistan/Wolesi_Jirga')
index_at_known_sha.country('afghanistan')
.legislature('wolesi-jirga')
.popolo
Expand Down
6 changes: 3 additions & 3 deletions t/page/house_wikidata.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,17 @@ def page_for(country, house)

describe 'HouseWikidata' do
let(:austria_page) do
stub_popolo('3df153b', 'Austria/Nationalrat')
stub_popolo('Austria/Nationalrat')
page_for('austria', 'nationalrat')
end

let(:alderney_page) do
stub_popolo('beb21e5', 'Alderney/States')
stub_popolo('Alderney/States')
page_for('alderney', 'states')
end

let(:uganda_page) do
stub_popolo('0cef4ab', 'Uganda/Parliament')
stub_popolo('Uganda/Parliament')
page_for('uganda', 'parliament')
end

Expand Down
4 changes: 2 additions & 2 deletions t/page/term_table.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
describe 'TermTable' do
describe 'Austria' do
subject do
stub_popolo('3df153b', 'Austria/Nationalrat')
stub_popolo('Austria/Nationalrat')
Page::TermTable.new(
term: index_at_known_sha.country('austria').legislature('nationalrat').term('25')
)
Expand Down Expand Up @@ -59,7 +59,7 @@
end

it 'returns an empty array when there is only a single group' do
stub_popolo('bd08b5e', 'North_Korea/National_Assembly')
stub_popolo('North_Korea/National_Assembly')
north_korea = Page::TermTable.new(
term: index_at_known_sha.country('north-korea').legislature('national-assembly').term('13')
)
Expand Down
6 changes: 3 additions & 3 deletions t/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,14 @@ def index_at_known_sha
end

def stub_everypolitician_data_request(path)
stub_request(:get, "https://cdn.rawgit.com/everypolitician/everypolitician-data/#{path}")
stub_request(:get, %r{https://cdn.rawgit.com/everypolitician/everypolitician-data/\w+/#{path}})
.to_return(body: File.read("t/fixtures/everypolitician-data/#{path}"))
rescue Errno::ENOENT => error
raise "#{error.message}\n\nTo download this fixture run the following\n\n\tbundle exec rake 'everypolitician-data[#{path}]'\n"
end

def stub_popolo(sha, legislature)
stub_everypolitician_data_request("#{sha}/data/#{legislature}/ep-popolo-v1.0.json")
def stub_popolo(legislature)
stub_everypolitician_data_request("data/#{legislature}/ep-popolo-v1.0.json")
end

def stub_github_api
Expand Down
4 changes: 2 additions & 2 deletions t/web/term_table/australia.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

describe 'Representatives' do
before do
stub_everypolitician_data_request('6139efe/data/Australia/Representatives/ep-popolo-v1.0.json')
stub_popolo('Australia/Representatives')
get '/australia/representatives/term-table/44.html'
end

Expand Down Expand Up @@ -51,7 +51,7 @@

describe 'Senate' do
before do
stub_everypolitician_data_request('f8dcbd9/data/Australia/Senate/ep-popolo-v1.0.json')
stub_popolo('Australia/Senate')
get '/australia/senate/term-table/44.html'
end

Expand Down
2 changes: 1 addition & 1 deletion t/web/term_table/bahamas.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
subject { Nokogiri::HTML(last_response.body) }

before do
stub_popolo('4da60b8', 'Bahamas/House_of_Assembly')
stub_popolo('Bahamas/House_of_Assembly')
get '/bahamas/house-of-assembly/term-table/2012.html'
end

Expand Down
2 changes: 1 addition & 1 deletion t/web/term_table/finland.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

describe 'Finland' do
before do
stub_everypolitician_data_request('ba4fa22/data/Finland/Eduskunta/ep-popolo-v1.0.json')
stub_popolo('Finland/Eduskunta')
get '/finland/eduskunta/term-table/35.html'
end

Expand Down
2 changes: 1 addition & 1 deletion t/web/term_table/malaysia.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

describe 'Per Country Tests' do
before do
stub_everypolitician_data_request('75b7651/data/Malaysia/Dewan_Rakyat/ep-popolo-v1.0.json')
stub_popolo('Malaysia/Dewan_Rakyat')
end

subject { Nokogiri::HTML(last_response.body) }
Expand Down
2 changes: 1 addition & 1 deletion t/web/term_table/ni.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

describe 'membership dates' do
before do
stub_everypolitician_data_request('1a17862/data/Northern_Ireland/Assembly/ep-popolo-v1.0.json')
stub_popolo('Northern_Ireland/Assembly')
get '/northern-ireland/assembly/term-table/3.html'
end

Expand Down
2 changes: 1 addition & 1 deletion t/web/term_table/nz.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

describe 'Per Country Tests' do
before do
stub_everypolitician_data_request('87859a2/data/New_Zealand/House/ep-popolo-v1.0.json')
stub_popolo('New_Zealand/House')
end

subject { Nokogiri::HTML(last_response.body) }
Expand Down
6 changes: 3 additions & 3 deletions t/web/term_table/party_groupings.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

describe 'only Independent' do
before do
stub_everypolitician_data_request('beb21e5/data/Alderney/States/ep-popolo-v1.0.json')
stub_popolo('Alderney/States')
get '/alderney/states/term-table/2014.html'
end

Expand All @@ -19,7 +19,7 @@

describe 'only Unknown' do
before do
stub_everypolitician_data_request('75b7651/data/Transnistria/Supreme_Council/ep-popolo-v1.0.json')
stub_popolo('Transnistria/Supreme_Council')
get '/transnistria/supreme-council/term-table/6.html'
end

Expand All @@ -30,7 +30,7 @@

describe 'regular section' do
before do
stub_everypolitician_data_request('f88ce37/data/Estonia/Riigikogu/ep-popolo-v1.0.json')
stub_popolo('Estonia/Riigikogu')
get '/estonia/riigikogu/term-table/13.html'
end
it 'should have party groupings' do
Expand Down
4 changes: 2 additions & 2 deletions t/web/term_table/seat_count.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

describe 'Estonia' do
before do
stub_everypolitician_data_request('f88ce37/data/Estonia/Riigikogu/ep-popolo-v1.0.json')
stub_popolo('Estonia/Riigikogu')
get '/estonia/riigikogu/term-table/13.html'
end

Expand All @@ -29,7 +29,7 @@

describe 'Historic Finland' do
before do
stub_everypolitician_data_request('ba4fa22/data/Finland/Eduskunta/ep-popolo-v1.0.json')
stub_popolo('Finland/Eduskunta')
get '/finland/eduskunta/term-table/35.html'
end

Expand Down
2 changes: 1 addition & 1 deletion t/web/wikidata.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

describe 'Croatia' do
before do
stub_popolo('6e39048', 'Croatia/Sabor')
stub_popolo('Croatia/Sabor')
get '/croatia/sabor/wikidata'
end

Expand Down