mvnizer 0.9.0 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,94 +0,0 @@
1
- require 'spec_helper'
2
-
3
-
4
- module Mvnizer
5
- module Command
6
- describe SearchArtefact do
7
-
8
- subject { SearchArtefact.new }
9
- before { subject.out = StringIO.new }
10
-
11
- def httparty_response_mock(mock_response_content)
12
- request_object = HTTParty::Request.new Net::HTTP::Get, '/'
13
- response_object = Net::HTTPOK.new('1.1', 200, 'OK')
14
- response_object.stub(:body => mock_response_content)
15
- mock_response = HTTParty::Response.new(request_object, response_object, -> { mock_response_content })
16
- end
17
-
18
- def response_mock(klass)
19
- response = klass.new('', '', '')
20
- response.stub(:body)
21
- response
22
- end
23
-
24
- it "performs a search in the Maven repository" do
25
- options = { command:"search", name: "junit" }
26
- SearchArtefact.should_receive(:get).with("http://search.maven.org/solrsearch/select?q=junit&rows=5&wt=json")
27
-
28
- subject.run(options)
29
- end
30
-
31
- it "displays the coordinates of the found artefacts" do
32
- require 'json'
33
-
34
- mock_response_content = JSON.parse(<<JSON)
35
- {
36
- "response": {
37
- "numFound": "1",
38
- "docs": [
39
- {
40
- "g": "blah",
41
- "a": "blah",
42
- "latestVersion": "1.0",
43
- "p": "jar"
44
- }
45
- ]
46
- }
47
- }
48
- JSON
49
-
50
- mock_response = httparty_response_mock(mock_response_content)
51
- options = { command:"search", name: "junit" }
52
- SearchArtefact.should_receive(:get).and_return(mock_response)
53
-
54
- io = StringIO.new
55
- subject.out = io
56
-
57
- subject.run(options)
58
-
59
- io.string.should =~ Regexp.new("blah:blah:1.0:jar")
60
- end
61
-
62
-
63
- it "displays an informative message when no result is found" do
64
- mock_response_content = '{ "response": { "numFound": "0"} }'
65
- mock_response = httparty_response_mock(mock_response_content)
66
-
67
- options = { command:"search", name: "junit" }
68
- SearchArtefact.should_receive(:get).and_return(mock_response)
69
-
70
- io = StringIO.new
71
- subject.out = io
72
-
73
- subject.run(options)
74
-
75
- io.string.should match("No result found.")
76
- end
77
-
78
- it "displays an error message when something went wrong" do
79
- net_response = response_mock(Net::HTTPServerError)
80
- SearchArtefact.should_receive(:get).and_return(net_response)
81
-
82
- options = { command:"search", name: "junit" }
83
- io = StringIO.new
84
- subject.out = io
85
-
86
- lambda { subject.run(options) }.should raise_error(SystemExit)
87
-
88
- io.string.should match("Error during search: ")
89
- end
90
- end
91
- end
92
- end
93
-
94
-
@@ -1,28 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Mvnizer::Configuration do
4
- include Mvnizer::Configuration
5
- let (:conf_path) { File.join(File.dirname(__FILE__), '..', 'conf', 'default.yml') }
6
-
7
- it "loads configuration from default.yml" do
8
- YAML.should_receive(:load_file).with(be_same_path_as(conf_path)).and_return({ foo: "bar" })
9
-
10
- config = conf(Hash.new)
11
- config[:foo].should == "bar"
12
- end
13
-
14
- it "should replace default values" do
15
- YAML.should_receive(:load_file).with(be_same_path_as(conf_path)).and_return({ foo: "bar" })
16
-
17
- config = conf({ foo: "qux", baz: "buz" })
18
- config[:foo].should == "qux"
19
- config[:baz].should == "buz"
20
- end
21
-
22
- it "should symbolize configuration keys" do
23
- YAML.should_receive(:load_file).with(be_same_path_as(conf_path)).and_return({ "foo" => "bar" })
24
-
25
- config = conf(Hash.new)
26
- config[:foo].should == "bar"
27
- end
28
- end
@@ -1,92 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Mvnizer::CoordinateParser do
4
- subject { Mvnizer::CoordinateParser.new }
5
-
6
- describe "#parse" do
7
- it "can read the project name" do
8
- project = subject.parse("name")
9
- project.artifact_id.should == "name"
10
- end
11
-
12
- it "can read the group and artifact ids" do
13
- project = subject.parse("com.example:name")
14
- project.artifact_id.should == "name"
15
- project.group_id.should == "com.example"
16
- end
17
-
18
- it "can read the group and artifact ids and version and type" do
19
- project = subject.parse("com.example:name:1.0.0-rc2:war")
20
- project.artifact_id.should == "name"
21
- project.group_id.should == "com.example"
22
- project.version.should == "1.0.0-rc2"
23
- project.type.should == "war"
24
- end
25
-
26
- it "can read the group and artifact ids and version" do
27
- project = subject.parse("com.example:name:1.0.0-rc2")
28
- project.artifact_id.should == "name"
29
- project.group_id.should == "com.example"
30
- project.version.should == "1.0.0-rc2"
31
- end
32
-
33
- it "can read the artifact id and version" do
34
- project = subject.parse("name:1.0.0-SNAPSHOT")
35
- project.artifact_id.should == "name"
36
- project.version.should == "1.0.0-SNAPSHOT"
37
- end
38
-
39
- it "can read the artifact id and type" do
40
- project = subject.parse("name:jar")
41
- project.artifact_id.should == "name"
42
- project.type.should == "jar"
43
- end
44
-
45
- it "can read the artifact id, version and type" do
46
- project = subject.parse("name:1.0.0-rc2:war")
47
- project.artifact_id.should == "name"
48
- project.version.should == "1.0.0-rc2"
49
- project.type.should == "war"
50
- end
51
- end
52
-
53
- describe "#parse_scoped_coordinates" do
54
- it "can parse the scope" do
55
- project = subject.parse_scoped_coordinates("name:1.0.0-rc2:war:runtime")
56
- project.artifact_id.should == "name"
57
- project.scope.should == "runtime"
58
-
59
- project = subject.parse_scoped_coordinates("com.weblogism:name:1.0.0-rc2:jar:runtime")
60
- project.artifact_id.should == "name"
61
- project.scope.should == "runtime"
62
- end
63
-
64
- it "can parse the junit dependency" do
65
- project = subject.parse_scoped_coordinates("junit:junit:4.10:jar:test")
66
- project.group_id.should == "junit"
67
- project.artifact_id.should == "junit"
68
- project.version.should == "4.10"
69
- project.type.should == "jar"
70
- project.scope.should == "test"
71
- end
72
-
73
- it "can parse the java EE dependency" do
74
- project = subject.parse_scoped_coordinates("javax:javaee-web-api:6.0:jar:provided")
75
- project.group_id.should == "javax"
76
- project.artifact_id.should == "javaee-web-api"
77
- project.version.should == "6.0"
78
- project.type.should == "jar"
79
- project.scope.should == "provided"
80
-
81
- end
82
-
83
- it "can parse a dependency without scope" do
84
- project = subject.parse_scoped_coordinates("junit:junit:4.10:jar")
85
- project.group_id.should == "junit"
86
- project.artifact_id.should == "junit"
87
- project.version.should == "4.10"
88
- project.type.should == "jar"
89
- project.scope.should be_nil
90
- end
91
- end
92
- end
data/spec/dummy.txt.erb DELETED
@@ -1 +0,0 @@
1
- Test
data/spec/dummy_pom.xml DELETED
@@ -1,30 +0,0 @@
1
- <project xmlns="http://maven.apache.org/POM/4.0.0"
2
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3
- xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
4
- <modelVersion>4.0.0</modelVersion>
5
-
6
- <groupId>com.weblogism</groupId>
7
- <artifactIdd>dummy</artifactIdd>
8
- <version>1.0.0-SNAPSHOT</version>
9
-
10
- <properties>
11
- <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
12
- </properties>
13
-
14
- <dependencies>
15
- </dependencies>
16
-
17
- <build>
18
- <plugins>
19
- <plugin>
20
- <artifactId>maven-compiler-plugin</artifactId>
21
- <version>2.3.2</version>
22
- <configuration>
23
- <source>1.6</source>
24
- <target>1.6</target>
25
- </configuration>
26
- </plugin>
27
- </plugins>
28
- </build>
29
-
30
- </project>
data/spec/mvnize_spec.rb DELETED
@@ -1,100 +0,0 @@
1
- require 'spec_helper'
2
-
3
- module Mvnizer
4
- describe Mvnize do
5
-
6
- let (:project) { Project.new(nil, "quxbaz", nil, nil) }
7
- let (:new_project) { double("new_project") }
8
- let (:search) { double("search") }
9
-
10
- let(:coordinate_parser) { double("coordinate_parser") }
11
- subject { Mvnizer::Mvnize.new(coordinate_parser) }
12
-
13
- before { subject.out = StringIO.new }
14
-
15
- it "reads the configuration" do
16
- options = {name: "foobar", command: "new"}
17
- subject.should_receive(:conf).with(options).and_return(options)
18
-
19
- p = Mvnizer::Project.new("group", "foobar", "version", "jar")
20
- coordinate_parser.should_receive(:parse).and_return(project)
21
- Command::ProjectFactory.should_receive(:create).and_return(new_project)
22
- new_project.should_receive(:run)
23
-
24
- subject.run(options)
25
- end
26
-
27
- it "creates a project from the provided coordinates" do
28
- options = {name: "foobar", command: "new"}
29
-
30
- subject.should_receive(:conf).with(options).and_return(options)
31
-
32
- p = Mvnizer::Project.new("group", "foobar", "version", "jar")
33
- coordinate_parser.should_receive(:parse).with("foobar").and_return(p)
34
- Command::ProjectFactory.should_receive(:create).and_return(new_project)
35
- new_project.should_receive(:run)
36
-
37
- subject.run(options)
38
- end
39
-
40
- it "chooses what command to run depending on the options" do
41
- options = {name: "quxbaz", command: "new"}
42
-
43
- subject.should_receive(:conf).and_return(Hash.new)
44
-
45
- p = Mvnizer::Project.new("group", "foobar", "version", "pom")
46
- coordinate_parser.should_receive(:parse).and_return(p)
47
- Command::ProjectFactory.should_receive(:create).with("pom").and_return(new_project)
48
- new_project.should_receive(:run)
49
-
50
- subject.run(options)
51
- end
52
-
53
- it "throws an error when no name is given" do
54
- lambda { subject.run(Hash.new) }.should raise_error(ArgumentError, "Please give a name to the project.")
55
- end
56
-
57
- it "displays a success message when done" do
58
- subject.should_receive(:define_project).and_return(project)
59
- Command::ProjectFactory.should_receive(:create).and_return(new_project)
60
- new_project.should_receive(:run)
61
- # For some obscure reason, this does not work:
62
- # $stdout.should_receive(:write).with("Project created successfully.")
63
- # It fails properly when message is incorrect:
64
- # #<IO:0x774d4142> received :write with unexpected arguments
65
- # expected: ("success")
66
- # got: ("Project created successfully.")
67
- # But throws an error when the message is correct:
68
- # undefined method `write' for #<IO:fd 1>
69
- # So instead, I have to resort to adding an `out` instance variable in Mvnize:
70
- string_io = StringIO.new
71
- subject.out = string_io
72
-
73
- subject.run(name: "quxbaz", command: "new")
74
- string_io.string.should match(/success/i)
75
- end
76
-
77
- it "throws an error if the command to run is not valid" do
78
- lambda { subject.run(name: "quxbaz", command: "foobar") }.should raise_error(ArgumentError, "foobar is not a valid command.")
79
- end
80
-
81
- it "calls the search command when doing a search" do
82
- options = { command:"search", name: "junit" }
83
-
84
- Command::SearchArtefact.should_receive(:new).and_return(search)
85
- search.should_receive(:run).with(options)
86
-
87
- subject.run(options)
88
- end
89
-
90
- it "calls the add command when adding a dependency" do
91
- options = { command:"add", name: "junit" }
92
-
93
- Command::AddDependency.should_receive(:new).and_return(search)
94
- search.should_receive(:run).with(options)
95
-
96
- subject.run(options)
97
- end
98
-
99
- end
100
- end
data/spec/project_spec.rb DELETED
@@ -1,29 +0,0 @@
1
- require 'spec_helper'
2
-
3
- module Mvnizer
4
- describe Project do
5
-
6
- describe "#package_name" do
7
- it "returns the package name based on coordinates" do
8
- project = Project.new("foo", "bar", nil, nil)
9
- project.package_name.should == "foo.bar"
10
- end
11
-
12
- it "ignores nil group id" do
13
- project = Project.new(nil, "bar", nil, nil)
14
- project.package_name.should == "bar"
15
- end
16
-
17
- it "removes invalid characters in package name" do
18
- project = Project.new("f-oo", "b-ar", nil, nil)
19
- project.package_name.should == "foo.bar"
20
- end
21
-
22
- it "can have plugins" do
23
- project = Project.new("foo", "bar", nil, nil)
24
- project.add_plugin(Plugin.new("qux", "baz", nil, nil))
25
- project.plugins.size.should == 1
26
- end
27
- end
28
- end
29
- end
data/spec/spec_helper.rb DELETED
@@ -1,11 +0,0 @@
1
- $:.unshift File.join(File.dirname(__FILE__), '..', 'lib')
2
- require 'mvnizer'
3
- require 'rspec/mocks'
4
- require 'rspec/expectations'
5
- require 'fakefs/safe'
6
-
7
- RSpec::Matchers.define :be_same_path_as do |expected|
8
- match do |actual|
9
- Pathname.new(expected).cleanpath == Pathname.new(actual).cleanpath
10
- end
11
- end
@@ -1,66 +0,0 @@
1
- require 'spec_helper'
2
- require 'erb'
3
-
4
- module Mvnizer
5
- class Dummy
6
- include TaskHelper
7
- end
8
-
9
- describe TaskHelper do
10
- let (:binding) { double("binding") }
11
- let (:erb) { double("erb") }
12
- let (:file) { double("file") }
13
- subject { Dummy.new }
14
-
15
- describe "#create_dir" do
16
- it "creates a list of directories" do
17
- subject.create_dir("/tmp/blah/blah", "/tmp/foo/bar")
18
- Dir.exists?("/tmp/blah/blah").should be true
19
- Dir.exists?("/tmp/foo/bar").should be true
20
- end
21
- end
22
-
23
- describe "#generate_file" do
24
- it "generates a file from a template into a given directory" do
25
-
26
- # This checks ERB is called properly.
27
- ERB.should_receive(:new).and_return(erb)
28
- binding.should_receive(:get_binding)
29
- erb.should_receive(:result).and_return("Blah")
30
-
31
- # This checks that the template is being read
32
- File.should_receive(:open).with("dummy.txt.erb", "r").and_return(file)
33
- file.should_receive(:read)
34
-
35
- # This checks that the output is being written.
36
- f = double("output_file")
37
- File.should_receive(:open).with("foobar/dummy.txt", "w").and_yield(f)
38
- f.should_receive(:write).with("Blah")
39
-
40
- subject.generate_file("dummy.txt.erb", "foobar/dummy.txt", binding)
41
- end
42
-
43
- it "creates the output directory if it does not exist" do
44
- subject.should_receive(:create_dir).with("foo")
45
- File.should_receive(:open).at_least(1).times.and_return(file)
46
- file.should_receive(:read)
47
- subject.generate_file("dummy.txt.erb", "foo/dummy.txt", binding)
48
- end
49
- end
50
-
51
- describe "#add_dependency" do
52
- it "adds a new dependency to an existing pom file" do
53
- dependencies = ["org.apache.commons:commons-lang3:3.1:jar",
54
- "org.apache.commons:commons-collections:3.2.1:jar"]
55
-
56
- pom_location = File.join(File.dirname(__FILE__), "dummy_pom.xml")
57
- output = subject.add_dependency(dependencies, pom_location)
58
- output.should match("<groupId>org.apache.commons</groupId>")
59
- end
60
-
61
- it "throws an error if the pom cannot be found in the current directory" do
62
- lambda { subject.add_dependency(nil) }.should raise_error(FileNotFoundError, "The pom.xml file cannot be found.")
63
- end
64
- end
65
- end
66
- end