Commits

Meikel Brandmeyer committed f65e76f

Add basic tests for plugin and extension

  • Participants
  • Parent commits 71423db

Comments (0)

Files changed (3)

File build.gradle

     mavenCentral()
 }
 
+configurations {
+    deployerJars
+}
+
 dependencies {
     compile gradleApi()
     // Workaround for milestone4
     compile fileTree(dir: "${gradle.gradleHomeDir}/lib/plugins", include: '**/*.jar')
     groovy localGroovy()
-}
 
-configurations {
-    deployerJars
-}
+    testCompile 'org.spockframework:spock-core:0.6-groovy-1.8'
 
-dependencies {
     deployerJars 'org.apache.maven.wagon:wagon-http-lightweight:2.2'
 }
 

File src/test/groovy/clojuresque/ClojarsExtensionTest.groovy

+/*-
+ * Copyright 2013 © Meikel Brandmeyer.
+ * All rights reserved.
+ * 
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ * 
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ * 
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+package clojuresque
+
+import org.gradle.api.InvalidUserDataException
+import org.gradle.api.Project
+import org.gradle.api.tasks.Upload
+import org.gradle.testfixtures.ProjectBuilder
+
+import spock.lang.Specification
+
+public class ClojarsExtensionTest extends Specification {
+    def Project project = ProjectBuilder.builder().build()
+
+    def setup() {
+        project.apply plugin: ClojarsPlugin
+    }
+
+    def "extension is in sane state"() {
+        expect:
+        project.clojars.username == null
+        project.clojars.password == null
+        project.clojars.url      == null
+    }
+
+    def "deploy with empty user name fails"() {
+        when:
+        def upload = project.tasks.add(name: "upload", type: Upload)
+        project.clojars {
+            password = "password"
+            deploy(upload)
+        }
+
+        then:
+        thrown(InvalidUserDataException)
+    }
+
+    def "deploy with empty password fails"() {
+        when:
+        def upload = project.tasks.add(name: "upload", type: Upload)
+        project.clojars {
+            username = "user"
+            deploy(upload)
+        }
+
+        then:
+        thrown(InvalidUserDataException)
+    }
+
+    def "deploy with empty URL uses the default"() {
+        when:
+        def upload = project.tasks.add(name: "upload", type: Upload)
+        project.clojars {
+            username = "user"
+            password = "password"
+            deploy(upload)
+        }
+
+        then:
+        project.clojars.url != null
+        project.clojars.url.equals("https://clojars.org/repo")
+    }
+
+    def "deploy picks up properties"() {
+        when:
+        def upload = project.tasks.add(name: "upload", type: Upload)
+        project["clojuresque.clojars.username"] = "user"
+        project["clojuresque.clojars.password"] = "password"
+        project["clojuresque.clojars.url"]      = "https://clojars.org/repo"
+        project.clojars.deploy(upload)
+
+        then:
+        project.clojars.username != null
+        project.clojars.username.equals("user")
+        project.clojars.password != null
+        project.clojars.password.equals("password")
+        project.clojars.url      != null
+        project.clojars.url.equals("https://clojars.org/repo")
+    }
+
+    def "deploy configures pom"() {
+        when:
+        def upload = project.tasks.add(name: "upload", type: Upload)
+        project.clojars {
+            username = "user"
+            password = "password"
+            deploy(upload) {
+                project {
+                    description "foobar"
+                }
+            }
+        }
+
+        then:
+        upload.repositories.mavenDeployer.pom.model.description.equals("foobar")
+    }
+}

File src/test/groovy/clojuresque/ClojarsPluginTest.groovy

+/*-
+ * Copyright 2013 © Meikel Brandmeyer.
+ * All rights reserved.
+ * 
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ * 
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ * 
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+package clojuresque
+
+import org.gradle.api.Project
+import org.gradle.testfixtures.ProjectBuilder
+
+import spock.lang.Specification
+
+public class ClojarsPluginTest extends Specification {
+    def Project project = ProjectBuilder.builder().build()
+
+    def setup() {
+        project.apply plugin: ClojarsPlugin
+    }
+
+    def "extension is installed by the plugin"() {
+        expect:
+        project.hasProperty("clojars")
+        project.clojars instanceof ClojarsExtension
+    }
+
+    def "deployer jar configuration is installed"() {
+        expect:
+        project.configurations["clojuresqueClojarsDeployerJars"]
+    }
+}