From kde-commits Sat Oct 15 22:49:42 2016 From: Cornelius Schumacher Date: Sat, 15 Oct 2016 22:49:42 +0000 To: kde-commits Subject: [websites/inqlude] /: Extract test which needs online access Message-Id: X-MARC-Message: https://marc.info/?l=kde-commits&m=147657224716357 Git commit 7b22cec674822dcc264535312e9b3e540bc801ea by Cornelius Schumacher. Committed on 14/08/2016 at 14:36. Pushed by cschumac into branch 'master'. Extract test which needs online access The tests which reads the actual online inqlude data repo and checks the generation of the inqlude-all.json file is in the `online` sub directory now. All other tests don't access online resources anymore and can be run without network access. This speeds things up quite a bit and makes the tests more robust. M +6 -1 lib/cli.rb M +0 -2 lib/view.rb M +3 -2 spec/data/inqlude-all.json M +3 -2 spec/data/manifests/awesomelib/awesomelib.2013-09-08.manifest M +34 -31 spec/integration/cli_view_spec.rb A +64 -0 spec/online/cli_view_spec.rb A +5 -0 spec/online/spec_helper.rb M +1 -1 spec/unit/manifest_handler_spec.rb M +1 -1 spec/unit/manifest_spec.rb http://commits.kde.org/websites/inqlude/7b22cec674822dcc264535312e9b3e540bc= 801ea diff --git a/lib/cli.rb b/lib/cli.rb index 03580d2..fdd249e 100644 --- a/lib/cli.rb +++ b/lib/cli.rb @@ -90,18 +90,23 @@ actual domain." def view process_global_options options = + output_dir =3D options[:output_dir] + = if options[:manifest_dir] @@settings.manifest_path =3D options[:manifest_dir] end = manifest_handler =3D ManifestHandler.new(@@settings) + + puts "Creating web site in '#{output_dir}' from '#{manifest_handler.se= ttings.manifest_path}'" + manifest_handler.read_remote = view =3D View.new(manifest_handler) view.enable_disqus =3D options[:enable_disqus] view.enable_search =3D !options[:disable_search] view.templates =3D options[:templates] - view.create options[:output_dir] + view.create output_dir end = desc "show ", "Show library details" diff --git a/lib/view.rb b/lib/view.rb index adf3b7f..9f97403 100644 --- a/lib/view.rb +++ b/lib/view.rb @@ -24,8 +24,6 @@ class View end = def create output_dir - puts "Creating web site in '#{output_dir}' from '#{@manifest_handler.s= ettings.manifest_path}'" - = assert_dir output_dir = system "cp #{view_dir}/favicon.ico #{output_dir}" diff --git a/spec/data/inqlude-all.json b/spec/data/inqlude-all.json index 4dc8243..65818b6 100644 --- a/spec/data/inqlude-all.json +++ b/spec/data/inqlude-all.json @@ -11,7 +11,8 @@ ], "urls": { "homepage": "http://example.com", - "download": "http://example.com/download" + "download": "http://example.com/download", + "vcs": "http://example.com/git" }, "licenses": [ "LGPLv2.1+", @@ -125,4 +126,4 @@ "OS X" ] } -] \ No newline at end of file +] diff --git a/spec/data/manifests/awesomelib/awesomelib.2013-09-08.manifest = b/spec/data/manifests/awesomelib/awesomelib.2013-09-08.manifest index 670be43..d2bbfc7 100644 --- a/spec/data/manifests/awesomelib/awesomelib.2013-09-08.manifest +++ b/spec/data/manifests/awesomelib/awesomelib.2013-09-08.manifest @@ -10,7 +10,8 @@ ], "urls": { "homepage": "http://example.com", - "download": "http://example.com/download" + "download": "http://example.com/download", + "vcs": "http://example.com/git" }, "licenses": [ "LGPLv2.1+", @@ -28,4 +29,4 @@ "source": "ftp://example.com/download/awesomelib-0.2.0.tar.gz" }, "group": "kde-frameworks" -} \ No newline at end of file +} diff --git a/spec/integration/cli_view_spec.rb b/spec/integration/cli_view_= spec.rb index 8200f80..252f2d1 100644 --- a/spec/integration/cli_view_spec.rb +++ b/spec/integration/cli_view_spec.rb @@ -44,8 +44,15 @@ describe "Command line interface" do = context "inqlude-all.json" do before(:each) do + @manifest_dir =3D given_directory do + given_directory_from_data("awesomelib", from: "manifests/awesome= lib") + given_directory_from_data("newlib", from: "manifests/newlib") + end + @output_dir =3D given_directory - run_command(args: ["view", "--output-dir=3D#{@output_dir}"]) + + run_command(args: ["view", "--offline", "--manifest_dir=3D#{@mani= fest_dir}", + "--output-dir=3D#{@output_dir}"]) end = it "generates view" do @@ -63,6 +70,8 @@ describe "Command line interface" do parsed_data =3D JSON.parse(data); = settings =3D Settings.new + settings.manifest_path =3D @manifest_dir + settings.offline =3D true handler =3D ManifestHandler.new settings handler.read_remote = @@ -73,44 +82,38 @@ describe "Command line interface" do data =3D File.read(File.join(@output_dir, 'inqlude-all.json')) parsed_data =3D JSON.parse(data); for element in parsed_data do - if element["name"] =3D=3D "baloo" + if element["name"] =3D=3D "awesomelib" library =3D element break end end + = + expect(library).to be = settings =3D Settings.new handler =3D ManifestHandler.new settings + settings.manifest_path =3D @manifest_dir + settings.offline =3D true handler.read_remote - manifest =3D handler.library("baloo").latest_manifest - - (expect manifest.display_name).to eq library["display_name"] - (expect manifest.release_date).to eq library["release_date"] - (expect manifest.version).to eq library["version"] - (expect manifest.summary).to eq library["summary"] - (expect manifest.topics).to eq library["topics"] - - (expect manifest.urls.homepage).to eq library["urls"]["homepage"] - (expect manifest.urls.api_docs).to eq library["urls"]["api_docs"] - (expect manifest.urls.download).to eq library["urls"]["download"] - (expect manifest.urls.tutorial).to eq library["urls"]["tutorial"] - (expect manifest.urls.vcs).to eq library["urls"]["vcs"] - (expect manifest.urls.description_source).to eq library["urls"]["d= escription_source"] - (expect manifest.urls.announcement).to eq library["urls"]["announc= ement"] - (expect manifest.urls.mailing_list).to eq library["urls"]["mailing= _list"] - (expect manifest.urls.contact).to eq library["urls"]["contact"] - (expect manifest.urls.custom).to eq library["urls"]["custom"] - - (expect manifest.licenses).to eq library["licenses"] - (expect manifest.description).to eq library["description"] - (expect manifest.authors).to eq library["authors"] - (expect manifest.maturity).to eq library["maturity"] - - (expect manifest.packages.source).to eq library["packages"]["sourc= e"] - (expect manifest.packages.openSUSE).to eq library["packages"]["ope= nSUSE"] - (expect manifest.packages.windows).to eq library["packages"]["wind= ows"] - (expect manifest.packages.ubuntu).to eq library["packages"]["ubunt= u"] - (expect manifest.packages.osx).to eq library["packages"]["osx"] + + manifest =3D handler.library("awesomelib").latest_manifest + + (expect manifest.display_name).to eq "Awesomelib" + (expect manifest.release_date).to eq "2013-09-08" + (expect manifest.version).to eq "0.2.0" + (expect manifest.summary).to eq "Awesome library" + (expect manifest.topics).to eq ["API"] + + (expect manifest.urls.homepage).to eq "http://example.com" + (expect manifest.urls.download).to eq "http://example.com/download" + (expect manifest.urls.vcs).to eq "http://example.com/git" + + (expect manifest.licenses).to eq ["LGPLv2.1+", "Commercial"] + (expect manifest.description).to eq "This is an awesome library." + (expect manifest.authors).to eq ["Cornelius Schumacher "] + (expect manifest.maturity).to eq "stable" + + (expect manifest.packages.source).to eq "ftp://example.com/downloa= d/awesomelib-0.2.0.tar.gz" end end end diff --git a/spec/online/cli_view_spec.rb b/spec/online/cli_view_spec.rb new file mode 100644 index 0000000..40f1c1a --- /dev/null +++ b/spec/online/cli_view_spec.rb @@ -0,0 +1,64 @@ +require_relative "spec_helper" + +include CliTester + +describe "Command line interface" do + include GivenFilesystemSpecHelpers + + use_given_filesystem + + describe "view" do + before(:each) do + @output_dir =3D given_directory + run_command(args: ["view", "--output-dir=3D#{@output_dir}"]) + end + + it "generates inqlude-all.json from online data" do + data =3D File.read(File.join(@output_dir, 'inqlude-all.json')) + parsed_data =3D JSON.parse(data); + + settings =3D Settings.new + handler =3D ManifestHandler.new settings + handler.read_remote + + expect(handler.libraries.length).to eq parsed_data.length + + for element in parsed_data do + if element["name"] =3D=3D "baloo" + library =3D element + break + end + end + + manifest =3D handler.library("baloo").latest_manifest + + (expect manifest.display_name).to eq library["display_name"] + (expect manifest.release_date).to eq library["release_date"] + (expect manifest.version).to eq library["version"] + (expect manifest.summary).to eq library["summary"] + (expect manifest.topics).to eq library["topics"] + + (expect manifest.urls.homepage).to eq library["urls"]["homepage"] + (expect manifest.urls.api_docs).to eq library["urls"]["api_docs"] + (expect manifest.urls.download).to eq library["urls"]["download"] + (expect manifest.urls.tutorial).to eq library["urls"]["tutorial"] + (expect manifest.urls.vcs).to eq library["urls"]["vcs"] + (expect manifest.urls.description_source).to eq library["urls"]["des= cription_source"] + (expect manifest.urls.announcement).to eq library["urls"]["announcem= ent"] + (expect manifest.urls.mailing_list).to eq library["urls"]["mailing_l= ist"] + (expect manifest.urls.contact).to eq library["urls"]["contact"] + (expect manifest.urls.custom).to eq library["urls"]["custom"] + + (expect manifest.licenses).to eq library["licenses"] + (expect manifest.description).to eq library["description"] + (expect manifest.authors).to eq library["authors"] + (expect manifest.maturity).to eq library["maturity"] + + (expect manifest.packages.source).to eq library["packages"]["source"] + (expect manifest.packages.openSUSE).to eq library["packages"]["openS= USE"] + (expect manifest.packages.windows).to eq library["packages"]["window= s"] + (expect manifest.packages.ubuntu).to eq library["packages"]["ubuntu"] + (expect manifest.packages.osx).to eq library["packages"]["osx"] + end + end +end diff --git a/spec/online/spec_helper.rb b/spec/online/spec_helper.rb new file mode 100644 index 0000000..8d24c03 --- /dev/null +++ b/spec/online/spec_helper.rb @@ -0,0 +1,5 @@ +require "cli_tester" +require "given_filesystem/spec_helpers" +require "json" + +require_relative "../../lib/inqlude" diff --git a/spec/unit/manifest_handler_spec.rb b/spec/unit/manifest_handle= r_spec.rb index 627b6f6..6c20bc3 100644 --- a/spec/unit/manifest_handler_spec.rb +++ b/spec/unit/manifest_handler_spec.rb @@ -145,7 +145,7 @@ describe ManifestHandler do end = it "generates inqlude-all.json" do - expected_json =3D File.read(test_data_path("inqlude-all.json")) + expected_json =3D File.read(test_data_path("inqlude-all.json")).chomp expect(mh.generate_inqlude_all).to eq expected_json end end diff --git a/spec/unit/manifest_spec.rb b/spec/unit/manifest_spec.rb index ea88443..3356aed 100644 --- a/spec/unit/manifest_spec.rb +++ b/spec/unit/manifest_spec.rb @@ -68,7 +68,7 @@ describe Manifest do it "writes JSON for release manifest" do filename =3D File.join settings.manifest_path, awesomelib_manifest_file manifest =3D Manifest.parse_file filename - expect( manifest.to_json ).to eq File.read( filename ) + expect( manifest.to_json ).to eq File.read( filename ).chomp end = it "writes JSON for generic manifest" do