Skip to content

Commit d75e024

Browse files
authored
Merge pull request #1973 from NicholasBHubbard/improve-cpan-tests
Upgrades to cpan_spec.rb
2 parents 4faa7ca + 9d80956 commit d75e024

File tree

2 files changed

+51
-12
lines changed

2 files changed

+51
-12
lines changed

spec/fpm/package/cpan_spec.rb

Lines changed: 48 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,9 @@
66
have_cpanm = program_exists?("cpanm")
77
if !have_cpanm
88
Cabin::Channel.get("rspec") \
9-
.warn("Skipping CPAN#input tests because 'cpanm' isn't in your PATH")
9+
.warn("Skipping CPAN tests because 'cpanm' isn't in your PATH")
1010
end
1111

12-
is_travis = ENV["TRAVIS_OS_NAME"] && !ENV["TRAVIS_OS_NAME"].empty?
13-
1412
describe FPM::Package::CPAN do
1513
before do
1614
skip("Missing cpanm program") unless have_cpanm
@@ -22,24 +20,60 @@
2220
subject.cleanup
2321
end
2422

23+
it "should prepend package name prefix" do
24+
subject.attributes[:cpan_package_name_prefix] = "prefix"
25+
insist { subject.instance_eval { fix_name("Foo::Bar") } } == "prefix-Foo-Bar"
26+
end
27+
28+
it "should wrap name in perl()" do
29+
insist { subject.instance_eval { cap_name("Foo::Bar") } } == "perl(Foo::Bar)"
30+
end
31+
32+
it "should return successful HTTP resonse" do
33+
response = subject.instance_eval { httpfetch("https://fastapi.metacpan.org/v1/module/File::Temp") }
34+
insist { response.class } == Net::HTTPOK
35+
end
36+
37+
it "should return successful HTTP resonse" do
38+
response = subject.instance_eval {httppost(
39+
"https://fastapi.metacpan.org/v1/release/_search",
40+
"{\"fields\":[\"download_url\"],\"filter\":{\"term\":{\"name\":\"File-Temp-0.2310\"}}}"
41+
)}
42+
insist { response.class } == Net::HTTPOK
43+
end
44+
45+
it "should return metadata hash" do
46+
metadata = subject.instance_eval { search("File::Temp") }
47+
insist { metadata.class } == Hash
48+
insist { metadata["name"] } == "Temp.pm"
49+
insist { metadata["distribution"] } == "File-Temp"
50+
end
51+
52+
it "should download precise version" do
53+
metadata = subject.instance_eval { search("Set::Tiny") }
54+
insist { File.basename(subject.instance_eval { download(metadata, "0.01") }) } == "Set-Tiny-0.01.tar.gz"
55+
end
56+
2557
it "should package Digest::MD5" do
26-
pending("Disabled on travis-ci because it always fails, and there is no way to debug it?") if is_travis
58+
# Set the version explicitly because we default to installing the newest
59+
# version, and a new version could be released that breaks the test.
60+
subject.instance_variable_set(:@version, "2.58");
2761

2862
# Disable testing because we don't really need to run the cpan tests. The
2963
# goal is to see the parsed result (name, module description, etc)
3064
# Additionally, it fails on my workstation when cpan_test? is enabled due
3165
# to not finding `Test.pm`, and it seems like a flakey test if we keep this
3266
# enabled.
3367
subject.attributes[:cpan_test?] = false
68+
3469
subject.input("Digest::MD5")
3570
insist { subject.name } == "perl-Digest-MD5"
3671
insist { subject.description } == "Perl interface to the MD-5 algorithm"
3772
insist { subject.vendor } == "Gisle Aas <gisle@activestate.com>"
38-
# TODO(sissel): Check dependencies
73+
insist { subject.dependencies.sort } == ["perl >= 5.006", "perl(Digest::base) >= 1.00", "perl(XSLoader)"]
3974
end
4075

4176
it "should unpack tarball containing ./ leading paths" do
42-
pending("Disabled on travis-ci because it always fails, and there is no way to debug it?") if is_travis
4377

4478
Dir.mktmpdir do |tmpdir|
4579
# Create tarball containing a file './foo/bar.txt'
@@ -55,29 +89,31 @@
5589
end
5690

5791
it "should package File::Spec" do
58-
pending("Disabled on travis-ci because it always fails, and there is no way to debug it?") if is_travis
92+
subject.instance_variable_set(:@version, "3.75");
93+
subject.attributes[:cpan_test?] = false
94+
5995
subject.input("File::Spec")
6096

6197
# the File::Spec module comes from the PathTools CPAN distribution
6298
insist { subject.name } == "perl-PathTools"
6399
end
64100

65101
it "should package Class::Data::Inheritable" do
66-
pending("Disabled on travis-ci because it always fails, and there is no way to debug it?") if is_travis
67-
68102
# Class::Data::Inheritable version 0.08 has a blank author field in its
69103
# META.yml file.
70104
subject.instance_variable_set(:@version, "0.08");
105+
106+
subject.attributes[:cpan_test?] = false
107+
71108
subject.input("Class::Data::Inheritable")
72109
insist { subject.vendor } == "No Vendor Or Author Provided"
73110
end
74111

75112
context "given a distribution without a META.* file" do
76113
it "should package IPC::Session" do
77-
pending("Disabled on travis-ci because it always fails, and there is no way to debug it?") if is_travis
78-
79-
# IPC::Session fails 'make test'
114+
subject.instance_variable_set(:@version, "0.05");
80115
subject.attributes[:cpan_test?] = false
116+
# IPC::Session fails 'make test'
81117
subject.input("IPC::Session")
82118
end
83119
end

spec/spec_setup.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
require "tempfile" # stdlib
66
require "fileutils" # stdlib
77
require "date" # stdlib
8+
require "net/http" # stdlib
9+
require "json" # stdlib
10+
require "yaml" # stdlib
811

912
# put "lib" in RUBYLIB
1013
$: << File.join(File.dirname(File.dirname(__FILE__)), "lib")

0 commit comments

Comments
 (0)