inqlude 0.7.0 → 0.7.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/CHANGELOG.md +23 -0
- data/{README → README.md} +0 -0
- data/TODO +24 -9
- data/accessing-inqlude-data.md +55 -0
- data/inqlude.gemspec +2 -1
- data/lib/cli.rb +36 -4
- data/lib/creator.rb +17 -32
- data/lib/distros/suse.rb +2 -2
- data/lib/downloader.rb +37 -0
- data/lib/exceptions.rb +2 -0
- data/lib/inqlude.rb +21 -15
- data/lib/json_object.rb +104 -0
- data/lib/kde_frameworks_creator.rb +14 -10
- data/lib/kde_frameworks_release.rb +14 -13
- data/lib/library.rb +4 -4
- data/lib/manifest.rb +165 -28
- data/lib/manifest_handler.rb +14 -16
- data/lib/verifier.rb +23 -48
- data/lib/version.rb +1 -1
- data/lib/view.rb +29 -26
- data/manifest-format.md +15 -0
- data/spec/data/inqlude-all-karchive.json +31 -0
- data/spec/data/inqlude-all.json +120 -0
- data/spec/data/invalid-schema.manifest +4 -0
- data/spec/data/karchive-release-5.4.manifest +29 -0
- data/spec/data/karchive-release.manifest +7 -7
- data/spec/data/karchive.readme +0 -6
- data/spec/data/newlib/newlib.manifest +11 -4
- data/spec/data/rendertest-generic.manifest +4 -1
- data/spec/integration/cli_create_spec.rb +24 -0
- data/spec/integration/cli_general_spec.rb +19 -0
- data/spec/integration/cli_get_involved_spec.rb +14 -0
- data/spec/integration/cli_help_spec.rb +21 -0
- data/spec/integration/cli_list_spec.rb +23 -0
- data/spec/integration/cli_verify_spec.rb +37 -0
- data/spec/integration/cli_view_spec.rb +28 -0
- data/spec/integration/spec_helper.rb +2 -0
- data/spec/{creator_spec.rb → unit/creator_spec.rb} +8 -41
- data/spec/unit/downloader_spec.rb +32 -0
- data/spec/unit/json_object_spec.rb +273 -0
- data/spec/{kde_frameworks_creator_spec.rb → unit/kde_frameworks_creator_spec.rb} +13 -14
- data/spec/{kde_frameworks_release_spec.rb → unit/kde_frameworks_release_spec.rb} +14 -10
- data/spec/{library_spec.rb → unit/library_spec.rb} +7 -7
- data/spec/{manifest_handler_spec.rb → unit/manifest_handler_spec.rb} +21 -17
- data/spec/unit/manifest_spec.rb +301 -0
- data/spec/{rpm_manifestizer_spec.rb → unit/rpm_manifestizer_spec.rb} +0 -0
- data/spec/{settings_spec.rb → unit/settings_spec.rb} +0 -0
- data/spec/{spec_helper.rb → unit/spec_helper.rb} +10 -12
- data/spec/{verifier_spec.rb → unit/verifier_spec.rb} +24 -15
- data/spec/{view_spec.rb → unit/view_spec.rb} +38 -7
- data/view/all.html.haml +4 -4
- data/view/commercial.html.haml +1 -1
- data/view/development.html.haml +3 -3
- data/view/get.html.haml +11 -2
- data/view/group.html.haml +4 -4
- data/view/index.html.haml +1 -1
- data/view/library.html.haml +8 -9
- data/view/unreleased.html.haml +1 -1
- data/yes_ship_it.conf +3 -0
- metadata +67 -51
- data/spec/manifest_spec.rb +0 -63
@@ -0,0 +1,29 @@
|
|
1
|
+
{
|
2
|
+
"$schema": "http://inqlude.org/schema/release-manifest-v1#",
|
3
|
+
"name": "karchive",
|
4
|
+
"display_name": "KArchive",
|
5
|
+
"release_date": "2014-11-06",
|
6
|
+
"version": "5.4.0",
|
7
|
+
"summary": "Reading, creating, and manipulating file archives",
|
8
|
+
"urls": {
|
9
|
+
"homepage": "https://projects.kde.org/projects/frameworks/karchive",
|
10
|
+
"download": "http://download.kde.org/stable/frameworks/5.4/",
|
11
|
+
"vcs": "https://projects.kde.org/projects/frameworks/karchive/repository",
|
12
|
+
"mailing_list": "https://mail.kde.org/mailman/listinfo/kde-frameworks-devel"
|
13
|
+
},
|
14
|
+
"licenses": [
|
15
|
+
"LGPLv2.1+"
|
16
|
+
],
|
17
|
+
"description": "KArchive provides classes for easy reading, creation and manipulation of\n\"archive\" formats like ZIP and TAR.\n\nIf also provides transparent compression and decompression of data, like the\nGZip format, via a subclass of QIODevice.",
|
18
|
+
"authors": [
|
19
|
+
"The KDE Community"
|
20
|
+
],
|
21
|
+
"maturity": "stable",
|
22
|
+
"platforms": [
|
23
|
+
"Linux"
|
24
|
+
],
|
25
|
+
"packages": {
|
26
|
+
"source": "http://download.kde.org/stable/frameworks/5.4/karchive-5.4.0.tar.xz"
|
27
|
+
},
|
28
|
+
"group": "kde-frameworks"
|
29
|
+
}
|
@@ -2,12 +2,14 @@
|
|
2
2
|
"$schema": "http://inqlude.org/schema/release-manifest-v1#",
|
3
3
|
"name": "karchive",
|
4
4
|
"display_name": "KArchive",
|
5
|
+
"release_date": "2014-07-07",
|
6
|
+
"version": "5.0.0",
|
5
7
|
"summary": "Reading, creating, and manipulating file archives",
|
6
8
|
"urls": {
|
7
9
|
"homepage": "https://projects.kde.org/projects/frameworks/karchive",
|
10
|
+
"download": "http://download.kde.org/stable/frameworks/5.0.0/",
|
8
11
|
"vcs": "https://projects.kde.org/projects/frameworks/karchive/repository",
|
9
|
-
"mailing_list": "https://mail.kde.org/mailman/listinfo/kde-frameworks-devel"
|
10
|
-
"download": "http://download.kde.org/stable/frameworks/5.0.0/"
|
12
|
+
"mailing_list": "https://mail.kde.org/mailman/listinfo/kde-frameworks-devel"
|
11
13
|
},
|
12
14
|
"licenses": [
|
13
15
|
"LGPLv2.1+"
|
@@ -16,14 +18,12 @@
|
|
16
18
|
"authors": [
|
17
19
|
"The KDE Community"
|
18
20
|
],
|
21
|
+
"maturity": "stable",
|
19
22
|
"platforms": [
|
20
23
|
"Linux"
|
21
24
|
],
|
22
|
-
"group": "kde-frameworks",
|
23
|
-
"maturity": "stable",
|
24
|
-
"release_date": "2014-07-07",
|
25
|
-
"version": "5.0.0",
|
26
25
|
"packages": {
|
27
26
|
"source": "http://download.kde.org/stable/frameworks/5.0.0/karchive-5.0.0.tar.xz"
|
28
|
-
}
|
27
|
+
},
|
28
|
+
"group": "kde-frameworks"
|
29
29
|
}
|
data/spec/data/karchive.readme
CHANGED
@@ -27,9 +27,3 @@ appropriate subclass of KArchive (eg: K7Zip for 7-Zip files). You may need to
|
|
27
27
|
combine this with usage of KCompressionDevice (see the API documentation for the
|
28
28
|
relevant KArchive subclass for details).
|
29
29
|
|
30
|
-
## Links
|
31
|
-
|
32
|
-
- Home page: <https://projects.kde.org/projects/frameworks/karchive>
|
33
|
-
- Mailing list: <https://mail.kde.org/mailman/listinfo/kde-frameworks-devel>
|
34
|
-
- IRC channel: #kde-devel on Freenode
|
35
|
-
- Git repository: <https://projects.kde.org/projects/frameworks/karchive/repository>
|
@@ -6,8 +6,15 @@
|
|
6
6
|
"homepage": "http://new.example.org",
|
7
7
|
"download": "http://new.example.org/download"
|
8
8
|
},
|
9
|
-
"licenses": [
|
9
|
+
"licenses": [
|
10
|
+
"GPLv3"
|
11
|
+
],
|
10
12
|
"description": "This is an awesome library. It's new.",
|
11
|
-
"authors": [
|
12
|
-
|
13
|
-
|
13
|
+
"authors": [
|
14
|
+
"Cornelius Schumacher <schumacher@kde.org>"
|
15
|
+
],
|
16
|
+
"platforms": [
|
17
|
+
"Linux",
|
18
|
+
"Windows"
|
19
|
+
]
|
20
|
+
}
|
@@ -5,7 +5,10 @@
|
|
5
5
|
"summary": "Test manifest for testing rendering",
|
6
6
|
"urls": {
|
7
7
|
"homepage": "https://example.org",
|
8
|
-
"vcs": "https://example.org/git"
|
8
|
+
"vcs": "https://example.org/git",
|
9
|
+
"custom": {
|
10
|
+
"Special": "http://special.example.org"
|
11
|
+
}
|
9
12
|
},
|
10
13
|
"licenses": [
|
11
14
|
"LGPLv2.1+"
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require_relative "spec_helper"
|
2
|
+
|
3
|
+
include CliTester
|
4
|
+
|
5
|
+
describe "Command line interface" do
|
6
|
+
include GivenFilesystemSpecHelpers
|
7
|
+
|
8
|
+
use_given_filesystem
|
9
|
+
|
10
|
+
describe "create" do
|
11
|
+
it "creates new manifest" do
|
12
|
+
|
13
|
+
dir = given_directory
|
14
|
+
|
15
|
+
result = run_command(args: ["create", "--offline",
|
16
|
+
"--manifest_dir=#{dir}", "newlib", "42.1", "2015-06-13"],
|
17
|
+
working_directory: dir)
|
18
|
+
expect(result).to exit_with_success("")
|
19
|
+
|
20
|
+
expect(File.exist?(File.join(dir, "newlib", "newlib.2015-06-13.manifest"))).
|
21
|
+
to be(true)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require_relative "spec_helper"
|
2
|
+
|
3
|
+
include CliTester
|
4
|
+
|
5
|
+
describe "Command line interface" do
|
6
|
+
describe "shows error" do
|
7
|
+
it "when command does not exist" do
|
8
|
+
expect(run_command(args: ["abc"])).to exit_with_success("", /abc/)
|
9
|
+
end
|
10
|
+
|
11
|
+
it "when global option does not exist" do
|
12
|
+
expect(run_command(args: ["--abc"])).to exit_with_success("", /--abc/)
|
13
|
+
end
|
14
|
+
|
15
|
+
it "when command option does not exist" do
|
16
|
+
expect(run_command(args: ["list", "--abc"])).to exit_with_success("", /--abc/)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require_relative "spec_helper"
|
2
|
+
|
3
|
+
include CliTester
|
4
|
+
|
5
|
+
describe "Command line interface" do
|
6
|
+
describe "get_involved" do
|
7
|
+
it "shows list of open issues" do
|
8
|
+
result = run_command(args: ["get_involved"])
|
9
|
+
expect(result.exit_code).to eq(0)
|
10
|
+
expect(result.stdout).to match("github.com/cornelius/inqlude/issues")
|
11
|
+
expect(result.stderr.empty?).to be(true)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require_relative "spec_helper"
|
2
|
+
|
3
|
+
include CliTester
|
4
|
+
|
5
|
+
describe "Command line interface" do
|
6
|
+
describe "help" do
|
7
|
+
it "shows general help" do
|
8
|
+
result = run_command
|
9
|
+
expect(result.exit_code).to eq(0)
|
10
|
+
expect(result.stdout).to match(/Commands:/)
|
11
|
+
expect(result.stderr.empty?).to be(true)
|
12
|
+
end
|
13
|
+
|
14
|
+
it "shows help for command" do
|
15
|
+
result = run_command(args: ["help", "list"])
|
16
|
+
expect(result.exit_code).to eq(0)
|
17
|
+
expect(result.stdout).to match("inqlude list")
|
18
|
+
expect(result.stderr.empty?).to be(true)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require_relative "spec_helper"
|
2
|
+
|
3
|
+
include CliTester
|
4
|
+
|
5
|
+
describe "Command line interface" do
|
6
|
+
include GivenFilesystemSpecHelpers
|
7
|
+
|
8
|
+
use_given_filesystem
|
9
|
+
|
10
|
+
describe "list" do
|
11
|
+
it "lists libraries" do
|
12
|
+
|
13
|
+
dir = given_directory do
|
14
|
+
given_directory_from_data("awesomelib")
|
15
|
+
given_directory_from_data("newlib")
|
16
|
+
end
|
17
|
+
|
18
|
+
result = run_command(args: ["list", "--remote", "--offline",
|
19
|
+
"--manifest_dir=#{dir}"])
|
20
|
+
expect(result).to exit_with_success("awesomelib (0.2.0)\nnewlib ()\n")
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require_relative "spec_helper"
|
2
|
+
|
3
|
+
include CliTester
|
4
|
+
|
5
|
+
describe "Command line interface" do
|
6
|
+
include GivenFilesystemSpecHelpers
|
7
|
+
|
8
|
+
use_given_filesystem(keep_files: true)
|
9
|
+
|
10
|
+
describe "verify" do
|
11
|
+
it "verifies single manifest" do
|
12
|
+
dir = given_directory do
|
13
|
+
given_directory_from_data("awesomelib")
|
14
|
+
end
|
15
|
+
|
16
|
+
result = run_command(args: ["verify",
|
17
|
+
File.join(dir, "awesomelib", "awesomelib.2013-09-08.manifest")])
|
18
|
+
expect(result).to exit_with_success("Verify manifest awesomelib.2013-09-08.manifest...ok\n")
|
19
|
+
end
|
20
|
+
|
21
|
+
it "verifies all manifests" do
|
22
|
+
dir = given_directory do
|
23
|
+
given_directory_from_data("awesomelib")
|
24
|
+
given_directory_from_data("newlib")
|
25
|
+
end
|
26
|
+
|
27
|
+
result = run_command(args: ["verify", "--offline", "--manifest_dir=#{dir}"])
|
28
|
+
expected_output = <<EOT
|
29
|
+
Verify manifest awesomelib.2013-09-08.manifest...ok
|
30
|
+
Verify manifest newlib.manifest...ok
|
31
|
+
|
32
|
+
2 manifests checked. 2 ok, 0 with error.
|
33
|
+
EOT
|
34
|
+
expect(result).to exit_with_success(expected_output)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require_relative "spec_helper"
|
2
|
+
|
3
|
+
include CliTester
|
4
|
+
|
5
|
+
describe "Command line interface" do
|
6
|
+
include GivenFilesystemSpecHelpers
|
7
|
+
|
8
|
+
use_given_filesystem
|
9
|
+
|
10
|
+
describe "view" do
|
11
|
+
it "generates view" do
|
12
|
+
dir = given_directory do
|
13
|
+
given_directory_from_data("awesomelib")
|
14
|
+
given_directory_from_data("newlib")
|
15
|
+
end
|
16
|
+
|
17
|
+
output_dir = given_directory
|
18
|
+
|
19
|
+
result = run_command(args: ["view", "--offline",
|
20
|
+
"--manifest_dir=#{dir}", "--output-dir=#{output_dir}"])
|
21
|
+
expect(result).to exit_with_success(/Creating web site/)
|
22
|
+
|
23
|
+
expect(File.exist?(File.join(output_dir, "index.html"))).to be(true)
|
24
|
+
expect(File.exist?(File.join(output_dir, "libraries", "awesomelib.html"))).to be(true)
|
25
|
+
expect(File.exist?(File.join(output_dir, "libraries", "newlib.html"))).to be(true)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -44,28 +44,12 @@ describe Creator do
|
|
44
44
|
|
45
45
|
expect(mh.libraries.count).to eq 1
|
46
46
|
m = mh.manifest "awesomelib"
|
47
|
-
expect(m
|
48
|
-
expect(m
|
49
|
-
expect(m
|
50
|
-
expect(m
|
47
|
+
expect(m.name).to eq "awesomelib"
|
48
|
+
expect(m.version).to eq "1.0"
|
49
|
+
expect(m.release_date).to eq "2013-10-01"
|
50
|
+
expect(m.summary).to eq "Awesome library"
|
51
51
|
|
52
52
|
expect(mh.manifests.count).to eq 2
|
53
|
-
mh.manifests.each do |manifest|
|
54
|
-
if manifest["schema_type"] == "generic"
|
55
|
-
if manifest["name"] == "commercial"
|
56
|
-
expect(manifest.keys.count).to eq 13
|
57
|
-
else
|
58
|
-
expect(manifest.keys.count).to eq 12
|
59
|
-
end
|
60
|
-
elsif manifest["schema_type"] == "proprietary-release"
|
61
|
-
expect(manifest.keys.count).to eq 15
|
62
|
-
else
|
63
|
-
expect(manifest.keys.count).to eq 17
|
64
|
-
end
|
65
|
-
end
|
66
|
-
|
67
|
-
m = JSON File.read(manifest_filename)
|
68
|
-
expect(m.keys.count).to eq 13
|
69
53
|
end
|
70
54
|
|
71
55
|
it "creates new manifest" do
|
@@ -82,21 +66,11 @@ describe Creator do
|
|
82
66
|
|
83
67
|
expect(File.exists?(manifest_filename)).to be true
|
84
68
|
|
85
|
-
|
86
|
-
mh.read_remote
|
69
|
+
m = Manifest.parse_file(manifest_filename)
|
87
70
|
|
88
|
-
expect(
|
89
|
-
m
|
90
|
-
expect(m
|
91
|
-
expect(m["version"]).to eq "edge"
|
92
|
-
expect(m["release_date"]).to eq "2013-09-01"
|
93
|
-
|
94
|
-
v = Verifier.new settings
|
95
|
-
result = v.verify m
|
96
|
-
if !result.valid?
|
97
|
-
result.print_result
|
98
|
-
end
|
99
|
-
expect(result.valid?).to be true
|
71
|
+
expect(m.name).to eq "newawesomelib"
|
72
|
+
expect(m.version).to eq "edge"
|
73
|
+
expect(m.release_date).to eq "2013-09-01"
|
100
74
|
end
|
101
75
|
|
102
76
|
it "creates new generic manifest" do
|
@@ -112,13 +86,6 @@ describe Creator do
|
|
112
86
|
c.create_generic
|
113
87
|
|
114
88
|
expect(File.exists?(manifest_filename)).to be true
|
115
|
-
|
116
|
-
v = Verifier.new settings
|
117
|
-
result = v.verify_file manifest_filename
|
118
|
-
if !result.valid?
|
119
|
-
result.print_result
|
120
|
-
end
|
121
|
-
expect(result.valid?).to be true
|
122
89
|
end
|
123
90
|
|
124
91
|
describe "#create_dir" do
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require File.expand_path('../spec_helper', __FILE__)
|
2
|
+
|
3
|
+
include GivenFilesystemSpecHelpers
|
4
|
+
|
5
|
+
describe Downloader do
|
6
|
+
|
7
|
+
use_given_filesystem
|
8
|
+
|
9
|
+
include_context "manifest_files"
|
10
|
+
|
11
|
+
it "downloads source tarball" do
|
12
|
+
mh = ManifestHandler.new(settings)
|
13
|
+
mh.read_remote
|
14
|
+
|
15
|
+
output = double
|
16
|
+
expect(output).to receive(:puts).at_least(:once)
|
17
|
+
|
18
|
+
downloader = Downloader.new(mh, output)
|
19
|
+
|
20
|
+
expect(downloader).to receive(:read_from_url).and_return("dummy tarball")
|
21
|
+
|
22
|
+
path = given_directory
|
23
|
+
|
24
|
+
downloader.download("awesomelib", path)
|
25
|
+
|
26
|
+
tarball_path = File.join(path, "awesomelib-0.2.0.tar.gz")
|
27
|
+
|
28
|
+
expect(File.exists?(tarball_path)).to be true
|
29
|
+
expect(File.read(tarball_path)).to eq "dummy tarball"
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
@@ -0,0 +1,273 @@
|
|
1
|
+
require_relative "spec_helper.rb"
|
2
|
+
|
3
|
+
class MyObject < JsonObject
|
4
|
+
attribute :name
|
5
|
+
attribute :version
|
6
|
+
|
7
|
+
attribute :licenses
|
8
|
+
|
9
|
+
attribute :urls do
|
10
|
+
attribute :homepage
|
11
|
+
attribute :download
|
12
|
+
end
|
13
|
+
|
14
|
+
attribute :custom
|
15
|
+
end
|
16
|
+
|
17
|
+
class MyDerivedObject < MyObject
|
18
|
+
end
|
19
|
+
|
20
|
+
class MyOtherObject < JsonObject
|
21
|
+
attribute :hello
|
22
|
+
end
|
23
|
+
|
24
|
+
describe JsonObject do
|
25
|
+
describe "construction" do
|
26
|
+
it "works when two JsonObjects are defined" do
|
27
|
+
object = MyOtherObject.new
|
28
|
+
|
29
|
+
object.hello = "world"
|
30
|
+
|
31
|
+
expect(object.hello).to eq "world"
|
32
|
+
end
|
33
|
+
|
34
|
+
it "defines internal classes" do
|
35
|
+
object = MyObject.new
|
36
|
+
|
37
|
+
expect(object.urls).to be_a MyObject::Urls
|
38
|
+
end
|
39
|
+
|
40
|
+
it "inherits keys from super class" do
|
41
|
+
expect(MyDerivedObject.all_keys).to include(:name)
|
42
|
+
end
|
43
|
+
|
44
|
+
it "can instantiate sub class" do
|
45
|
+
object = MyDerivedObject.new
|
46
|
+
|
47
|
+
object.name = "Sub Jason"
|
48
|
+
expect(object.name).to eq "Sub Jason"
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
describe "attributes" do
|
53
|
+
it "defines accessors" do
|
54
|
+
object = MyObject.new
|
55
|
+
|
56
|
+
object.name = "Jason"
|
57
|
+
expect(object.name).to eq "Jason"
|
58
|
+
|
59
|
+
object.version = "1.2.3"
|
60
|
+
expect(object.version).to eq "1.2.3"
|
61
|
+
|
62
|
+
object.licenses = ["GPLv2", "LGPLv2.1"]
|
63
|
+
expect(object.licenses).to eq ["GPLv2", "LGPLv2.1"]
|
64
|
+
|
65
|
+
object.urls.homepage = "http://example.com"
|
66
|
+
expect(object.urls.homepage).to eq "http://example.com"
|
67
|
+
end
|
68
|
+
|
69
|
+
it "returns validity of objects" do
|
70
|
+
object = MyObject.new
|
71
|
+
|
72
|
+
expect(object.valid?).to be false
|
73
|
+
expect(object.urls.valid?).to be false
|
74
|
+
|
75
|
+
object.name = "Jason"
|
76
|
+
|
77
|
+
expect(object.valid?).to be true
|
78
|
+
expect(object.urls.valid?).to be false
|
79
|
+
|
80
|
+
object.urls.homepage = "http://example.com"
|
81
|
+
|
82
|
+
expect(object.valid?).to be true
|
83
|
+
expect(object.urls.valid?).to be true
|
84
|
+
end
|
85
|
+
|
86
|
+
it "returns nil for unset attribute" do
|
87
|
+
json = <<EOT
|
88
|
+
{
|
89
|
+
"name": "Jason"
|
90
|
+
}
|
91
|
+
EOT
|
92
|
+
object = MyDerivedObject.new.from_json(json)
|
93
|
+
|
94
|
+
expect(object.name).to eq "Jason"
|
95
|
+
expect(object.version).to be nil
|
96
|
+
end
|
97
|
+
|
98
|
+
it "raises exception for non-existing attribute" do
|
99
|
+
object = MyObject.new
|
100
|
+
|
101
|
+
expect {
|
102
|
+
object.invalid_attribute
|
103
|
+
}.to raise_error(NoMethodError)
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
describe "JSON" do
|
108
|
+
before(:all) do
|
109
|
+
@json = <<EOT
|
110
|
+
{
|
111
|
+
"name": "Jason",
|
112
|
+
"version": "1.2.3",
|
113
|
+
"licenses": [
|
114
|
+
"GPLv2",
|
115
|
+
"LGPLv2.1"
|
116
|
+
],
|
117
|
+
"urls": {
|
118
|
+
"homepage": "http://example.com",
|
119
|
+
"download": "http://example.org/download"
|
120
|
+
}
|
121
|
+
}
|
122
|
+
EOT
|
123
|
+
@json.chomp!
|
124
|
+
end
|
125
|
+
|
126
|
+
describe "reads" do
|
127
|
+
it "from hash" do
|
128
|
+
hash = JSON(@json)
|
129
|
+
|
130
|
+
object = MyObject.new.from_hash(hash)
|
131
|
+
expect(object.class).to be MyObject
|
132
|
+
expect(object.name).to eq "Jason"
|
133
|
+
expect(object.urls.class).to eq MyObject::Urls
|
134
|
+
expect(object.urls.homepage).to eq "http://example.com"
|
135
|
+
end
|
136
|
+
|
137
|
+
it "from JSON" do
|
138
|
+
object = MyObject.new.from_json(@json)
|
139
|
+
|
140
|
+
expect(object.class).to be MyObject
|
141
|
+
expect(object.name).to eq "Jason"
|
142
|
+
expect(object.version).to eq "1.2.3"
|
143
|
+
expect(object.licenses).to eq ["GPLv2", "LGPLv2.1"]
|
144
|
+
expect(object.urls.homepage).to eq "http://example.com"
|
145
|
+
expect(object.urls.download).to eq "http://example.org/download"
|
146
|
+
end
|
147
|
+
|
148
|
+
it "skips schema id" do
|
149
|
+
json = <<EOT
|
150
|
+
{
|
151
|
+
"$schema": "abc:xyz",
|
152
|
+
"name": "Jason"
|
153
|
+
}
|
154
|
+
EOT
|
155
|
+
object = MyObject.new.from_json(json)
|
156
|
+
|
157
|
+
expect(object.name).to eq "Jason"
|
158
|
+
end
|
159
|
+
|
160
|
+
it "hashes as values" do
|
161
|
+
json = <<EOT
|
162
|
+
{
|
163
|
+
"$schema": "http://example.com/schema/myobject-v1#",
|
164
|
+
"name": "Jason",
|
165
|
+
"custom": {
|
166
|
+
"one": "1",
|
167
|
+
"two": "2"
|
168
|
+
}
|
169
|
+
}
|
170
|
+
EOT
|
171
|
+
object = MyObject.new.from_json(json)
|
172
|
+
|
173
|
+
expect(object.name).to eq "Jason"
|
174
|
+
expect(object.custom).to eq({ "one" => "1", "two" => "2" })
|
175
|
+
end
|
176
|
+
|
177
|
+
it "raises exception on unexpected attribute" do
|
178
|
+
json = <<EOT
|
179
|
+
{
|
180
|
+
"name": "Jason",
|
181
|
+
"invalid_attribute": "42"
|
182
|
+
}
|
183
|
+
EOT
|
184
|
+
object = MyObject.new
|
185
|
+
expect {
|
186
|
+
object.from_json(json)
|
187
|
+
}.to raise_error(NoMethodError)
|
188
|
+
end
|
189
|
+
end
|
190
|
+
|
191
|
+
describe "writes" do
|
192
|
+
it "to hash" do
|
193
|
+
object = MyObject.new
|
194
|
+
object.name = "Jason"
|
195
|
+
object.version = "1.2.3"
|
196
|
+
object.licenses = ["GPLv2", "LGPLv2.1"]
|
197
|
+
object.urls.homepage = "http://example.com"
|
198
|
+
object.urls.download = "http://example.org/download"
|
199
|
+
|
200
|
+
expected_hash = {
|
201
|
+
:name => "Jason",
|
202
|
+
:version => "1.2.3",
|
203
|
+
:licenses => ["GPLv2", "LGPLv2.1"],
|
204
|
+
:urls => {
|
205
|
+
:homepage => "http://example.com",
|
206
|
+
:download => "http://example.org/download"
|
207
|
+
}
|
208
|
+
}
|
209
|
+
|
210
|
+
expect(object.to_hash).to eq expected_hash
|
211
|
+
end
|
212
|
+
|
213
|
+
it "to JSON" do
|
214
|
+
expected_json = @json
|
215
|
+
|
216
|
+
object = MyObject.new
|
217
|
+
object.name = "Jason"
|
218
|
+
object.version = "1.2.3"
|
219
|
+
object.licenses = ["GPLv2", "LGPLv2.1"]
|
220
|
+
object.urls.homepage = "http://example.com"
|
221
|
+
object.urls.download = "http://example.org/download"
|
222
|
+
|
223
|
+
expect(object.to_json).to eq expected_json
|
224
|
+
end
|
225
|
+
|
226
|
+
it "only attributes which have a value" do
|
227
|
+
object = MyObject.new
|
228
|
+
object.name = "Jason"
|
229
|
+
|
230
|
+
expected_json = <<EOT
|
231
|
+
{
|
232
|
+
"name": "Jason"
|
233
|
+
}
|
234
|
+
EOT
|
235
|
+
expected_json.chomp!
|
236
|
+
|
237
|
+
expect(object.to_json).to eq expected_json
|
238
|
+
end
|
239
|
+
|
240
|
+
it "schema id" do
|
241
|
+
expected_json = <<EOT
|
242
|
+
{
|
243
|
+
"$schema": "http://example.com/schema/myobject-v1#",
|
244
|
+
"name": "Jason"
|
245
|
+
}
|
246
|
+
EOT
|
247
|
+
expected_json.chomp!
|
248
|
+
|
249
|
+
object = MyObject.new
|
250
|
+
object.schema_id = "http://example.com/schema/myobject-v1#"
|
251
|
+
object.name = "Jason"
|
252
|
+
|
253
|
+
expect(object.to_json).to eq expected_json
|
254
|
+
end
|
255
|
+
|
256
|
+
it "hashes as values" do
|
257
|
+
json = <<EOT
|
258
|
+
{
|
259
|
+
"name": "Jason",
|
260
|
+
"custom": {
|
261
|
+
"one": "1",
|
262
|
+
"two": "2"
|
263
|
+
}
|
264
|
+
}
|
265
|
+
EOT
|
266
|
+
|
267
|
+
object = MyObject.new.from_json(json)
|
268
|
+
|
269
|
+
expect(object.to_json).to eq json.chomp
|
270
|
+
end
|
271
|
+
end
|
272
|
+
end
|
273
|
+
end
|