basic rspec plugin

This commit is contained in:
Christian Meier 2015-07-19 11:54:57 +02:00
parent 528d212bbe
commit ab76cd5a0e
27 changed files with 913 additions and 0 deletions

24
.travis.yml Normal file
View File

@ -0,0 +1,24 @@
language: groovy
sudo: false
install:
- ./gradlew clean
script:
- ./gradlew -S -i
- ./gradlew -S -i gradleTest
jdk:
- oraclejdk7
- oraclejdk8
- openjdk7
os:
- linux
- osx
env: TERM=dumb
cache:
directories:
- $HOME/.gradle

20
HACKING.md Normal file
View File

@ -0,0 +1,20 @@
== Running Tests
This project has both unit tests and integration tests. In our context the distinguishing point is that integration tests
need network connectivity, and unit tests need no more than local file system access. We also expect unit tests to be
very quick, whereas integration tests are allowed to take a _little_ longer.
Unit tests are in 'src/test' and integration tests are in 'src/integTest'. To run integration tests you would need to
do `./gradlew check` or `./gradlew build`. For unittests just doing `./gradlew test` is enough.
Test logging is controlled via `logback-test.xml`. Be aware that integration tests generate a lot of debug information.
Please do not commit the config file back with DEBUG turned on.
=== Running single test suites
If you only want to run the unittests in say `JRubyPlugin` then you can do `./gradlew test -Dtest.single=JRubyPlugin`.
In a similar manner for integration tests one can do `./gradlew integrationTest -Dtest.single=JRubyIntegrationSpec`.
== Release HOWTO
*TBC*

24
LICENSE.md Normal file
View File

@ -0,0 +1,24 @@
jruby-gradle-plugin is distributed under the following license:
----------------------------------------------------
Copyright (c) 2014 Lookout, Inc.
https://www.lookout.com/about/contact
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.

83
build.gradle Normal file
View File

@ -0,0 +1,83 @@
buildscript {
repositories {
jcenter()
maven {
url "https://plugins.gradle.org/m2/"
}
}
dependencies {
classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.2'
classpath 'com.netflix.nebula:gradle-extra-configurations-plugin:1.12.+'
classpath 'org.ysb33r.gradle:gradletest:0.5.3'
classpath 'org.asciidoctor:asciidoctor-gradle-plugin:1.5.1'
classpath "org.ajoberstar:gradle-git:1.2.0"
}
}
apply plugin: "org.asciidoctor.gradle.asciidoctor"
apply plugin: 'org.ajoberstar.github-pages'
group = 'com.github.jruby-gradle'
version = '0.4.1'
defaultTasks 'check', 'assemble'
if (!releaseBuild) {
version = "${version}-SNAPSHOT"
}
subprojects {
apply plugin: 'groovy'
apply plugin: 'maven'
apply plugin: 'com.jfrog.bintray'
apply plugin: 'org.ysb33r.gradletest'
apply plugin: 'provided-base'
apply from: "${rootProject.projectDir}/gradle/integration-tests.gradle"
repositories {
jcenter()
}
dependencies {
compile gradleApi()
compile localGroovy()
}
test {
testLogging {
showStandardStreams = true
exceptionFormat "full"
}
}
task sourcesJar(type: Jar, dependsOn: classes) {
classifier = 'sources'
from sourceSets.main.allSource
}
artifacts {
archives sourcesJar
}
}
task release(type: Exec) {
description 'Create and upload a release'
dependsOn subprojects.collect { ":${it.name}:bintrayUpload" }
commandLine 'git', 'tag', "v${project.version}"
}
//asciidoctor {
// separateOutputDirs false
// attributes 'stylesheet' : 'foundation.css',
// 'stylesdir' : "${projectDir}/src/docs/asciidoc/stylesheets"
//}
//githubPages {
// repoUri = 'git@github.com:jruby-gradle/jruby-gradle.github.io'
// targetBranch = 'master'
// pages {
// from asciidoctor
// from subprojects.collect { ":${it.name}:groovydoc" }
// }
//}
//publishGhPages.dependsOn subprojects.collect { ":${it.name}:groovydoc" }

4
gradle.properties Normal file
View File

@ -0,0 +1,4 @@
org.gradle.daemon=true
bintrayUser=
bintrayKey=
releaseBuild=false

View File

@ -0,0 +1,38 @@
// This is based upon what Rob Fletcher has done at
// https://raw.githubusercontent.com/robfletcher/gradle-compass/master/gradle/integration-tests.gradle
configurations {
integrationTestCompile {
extendsFrom testCompile
}
integrationTestRuntime {
extendsFrom integrationTestCompile, testRuntime
}
integrationTestGems
}
sourceSets {
integrationTest {
java.srcDir file("src/integTest/java")
groovy.srcDir file("src/integTest/groovy")
resources.srcDir file("src/integTest/resources")
compileClasspath = sourceSets.main.output + configurations.integrationTestCompile
runtimeClasspath = output + compileClasspath + configurations.integrationTestRuntime
}
}
task copyIntegrationTestGems (type:Copy) {
from ({configurations.integrationTestGems.files})
into new File(buildDir,'tmp/integrationTest/flatRepo')
}
task integrationTest(type: Test, dependsOn: jar) {
testClassesDir = sourceSets.integrationTest.output.classesDir
classpath = sourceSets.integrationTest.runtimeClasspath
mustRunAfter test
dependsOn copyIntegrationTestGems
}
check.dependsOn integrationTest

BIN
gradle/wrapper/gradle-wrapper.jar vendored Normal file

Binary file not shown.

View File

@ -0,0 +1,6 @@
#Fri Aug 22 00:43:11 BST 2014
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-2.0-all.zip

164
gradlew vendored Executable file
View File

@ -0,0 +1,164 @@
#!/usr/bin/env bash
##############################################################################
##
## Gradle start up script for UN*X
##
##############################################################################
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS=""
APP_NAME="Gradle"
APP_BASE_NAME=`basename "$0"`
# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD="maximum"
warn ( ) {
echo "$*"
}
die ( ) {
echo
echo "$*"
echo
exit 1
}
# OS specific support (must be 'true' or 'false').
cygwin=false
msys=false
darwin=false
case "`uname`" in
CYGWIN* )
cygwin=true
;;
Darwin* )
darwin=true
;;
MINGW* )
msys=true
;;
esac
# For Cygwin, ensure paths are in UNIX format before anything is touched.
if $cygwin ; then
[ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"`
fi
# Attempt to set APP_HOME
# Resolve links: $0 may be a link
PRG="$0"
# Need this for relative symlinks.
while [ -h "$PRG" ] ; do
ls=`ls -ld "$PRG"`
link=`expr "$ls" : '.*-> \(.*\)$'`
if expr "$link" : '/.*' > /dev/null; then
PRG="$link"
else
PRG=`dirname "$PRG"`"/$link"
fi
done
SAVED="`pwd`"
cd "`dirname \"$PRG\"`/" >&-
APP_HOME="`pwd -P`"
cd "$SAVED" >&-
CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
# Determine the Java command to use to start the JVM.
if [ -n "$JAVA_HOME" ] ; then
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
# IBM's JDK on AIX uses strange locations for the executables
JAVACMD="$JAVA_HOME/jre/sh/java"
else
JAVACMD="$JAVA_HOME/bin/java"
fi
if [ ! -x "$JAVACMD" ] ; then
die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
Please set the JAVA_HOME variable in your environment to match the
location of your Java installation."
fi
else
JAVACMD="java"
which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
Please set the JAVA_HOME variable in your environment to match the
location of your Java installation."
fi
# Increase the maximum file descriptors if we can.
if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
MAX_FD_LIMIT=`ulimit -H -n`
if [ $? -eq 0 ] ; then
if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
MAX_FD="$MAX_FD_LIMIT"
fi
ulimit -n $MAX_FD
if [ $? -ne 0 ] ; then
warn "Could not set maximum file descriptor limit: $MAX_FD"
fi
else
warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
fi
fi
# For Darwin, add options to specify how the application appears in the dock
if $darwin; then
GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
fi
# For Cygwin, switch paths to Windows format before running java
if $cygwin ; then
APP_HOME=`cygpath --path --mixed "$APP_HOME"`
CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
# We build the pattern for arguments to be converted via cygpath
ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
SEP=""
for dir in $ROOTDIRSRAW ; do
ROOTDIRS="$ROOTDIRS$SEP$dir"
SEP="|"
done
OURCYGPATTERN="(^($ROOTDIRS))"
# Add a user-defined pattern to the cygpath arguments
if [ "$GRADLE_CYGPATTERN" != "" ] ; then
OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
fi
# Now convert the arguments - kludge to limit ourselves to /bin/sh
i=0
for arg in "$@" ; do
CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
else
eval `echo args$i`="\"$arg\""
fi
i=$((i+1))
done
case $i in
(0) set -- ;;
(1) set -- "$args0" ;;
(2) set -- "$args0" "$args1" ;;
(3) set -- "$args0" "$args1" "$args2" ;;
(4) set -- "$args0" "$args1" "$args2" "$args3" ;;
(5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
(6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
(7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
(8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
(9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
esac
fi
# Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
function splitJvmOpts() {
JVM_OPTS=("$@")
}
eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"

90
gradlew.bat vendored Normal file
View File

@ -0,0 +1,90 @@
@if "%DEBUG%" == "" @echo off
@rem ##########################################################################
@rem
@rem Gradle startup script for Windows
@rem
@rem ##########################################################################
@rem Set local scope for the variables with windows NT shell
if "%OS%"=="Windows_NT" setlocal
@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
set DEFAULT_JVM_OPTS=
set DIRNAME=%~dp0
if "%DIRNAME%" == "" set DIRNAME=.
set APP_BASE_NAME=%~n0
set APP_HOME=%DIRNAME%
@rem Find java.exe
if defined JAVA_HOME goto findJavaFromJavaHome
set JAVA_EXE=java.exe
%JAVA_EXE% -version >NUL 2>&1
if "%ERRORLEVEL%" == "0" goto init
echo.
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.
goto fail
:findJavaFromJavaHome
set JAVA_HOME=%JAVA_HOME:"=%
set JAVA_EXE=%JAVA_HOME%/bin/java.exe
if exist "%JAVA_EXE%" goto init
echo.
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.
goto fail
:init
@rem Get command-line arguments, handling Windowz variants
if not "%OS%" == "Windows_NT" goto win9xME_args
if "%@eval[2+2]" == "4" goto 4NT_args
:win9xME_args
@rem Slurp the command line arguments.
set CMD_LINE_ARGS=
set _SKIP=2
:win9xME_args_slurp
if "x%~1" == "x" goto execute
set CMD_LINE_ARGS=%*
goto execute
:4NT_args
@rem Get arguments from the 4NT Shell from JP Software
set CMD_LINE_ARGS=%$
:execute
@rem Setup the command line
set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
@rem Execute Gradle
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
:end
@rem End local scope for the variables with windows NT shell
if "%ERRORLEVEL%"=="0" goto mainEnd
:fail
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
rem the _cmd.exe /c_ return code!
if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
exit /b 1
:mainEnd
if "%OS%"=="Windows_NT" endlocal
:omega

4
jruby-gradle-rspec-plugin/.gitignore vendored Normal file
View File

@ -0,0 +1,4 @@
.gradle
build/
*.sw*
*.iml

View File

@ -0,0 +1,7 @@
language: java
jdk:
- oraclejdk8
- oraclejdk7
cache:
directories:
- $HOME/.gradle

View File

@ -0,0 +1,3 @@
# Changelog
## v0.1.0

View File

@ -0,0 +1,21 @@
The MIT License (MIT)
Copyright (c) 2014 JRuby Gradle
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.

View File

@ -0,0 +1,4 @@
jruby-gradle-rspec-plugin
=======================
[![Build Status](https://buildhive.cloudbees.com/job/jruby-gradle/job/jruby-gradle-jar-plugin/badge/icon)](https://buildhive.cloudbees.com/job/jruby-gradle/job/jruby-gradle-jar-plugin/) [![Download](https://api.bintray.com/packages/jruby-gradle/plugins/jruby-gradle-jar-plugin/images/download.png)](https://bintray.com/jruby-gradle/plugins/jruby-gradle-jar-plugin) [![Gitter chat](https://badges.gitter.im/jruby-gradle/jruby-gradle-plugin.png)](https://gitter.im/jruby-gradle/jruby-gradle-plugin)

View File

@ -0,0 +1,16 @@
version: "{branch} {build}"
build:
verbosity: detailed
build_script:
- gradlew.bat assemble --info
test_script:
- gradlew.bat check --info
branches:
only:
- master
- development

View File

@ -0,0 +1,94 @@
group = rootProject.group
version = rootProject.version
configurations {
testRepo
}
repositories {
mavenLocal()
maven { url 'http://rubygems.lasagna.io/proxy/maven/releases' }
}
dependencies {
compile 'com.github.jruby-gradle:jruby-gradle-plugin:0.4.0'
testCompile ("org.spockframework:spock-core:0.7-groovy-${gradle.gradleVersion.startsWith('1.')?'1.8':'2.0'}") {
exclude module : 'groovy-all'
}
// For the testRepo tests I am locking the versions, instead of a open version, as it makes
// unit testing easier, This does not affect the final artifact.
// If you change values here, you need to update JRubyJarPluginSpec as well.
testRepo ("org.jruby:jruby-complete:1.7.21") {
transitive = false
}
testRepo ('rubygems:rspec:3.3.0') {
transitive = true
}
testRepo ("org.spockframework:spock-core:0.7-groovy-2.0") {
transitive = false
}
}
ext {
testRepoDir = new File(buildDir,'tmp/test/repo' )
}
test {
doFirst {
copy {
from project.configurations.testRepo.files
into testRepoDir
}
}
if(gradle.startParameter.isOffline()) {
systemProperties 'TESTS_ARE_OFFLINE' : '1'
}
systemProperties TESTROOT : new File(buildDir,'tmp/test/unittests').absolutePath
systemProperties TESTREPO_LOCATION : testRepoDir.absolutePath
systemProperties 'logback.configurationFile' : new File(projectDir,'src/test/resources/logback-test.xml').absolutePath
}
groovydoc {
docTitle = "${archivesBaseName} ${version}"
}
task installGroovyDoc (type : Copy) {
from ({new File(buildDir,'docs/groovydoc')}) {
include '**'
}
into {new File(project.properties.jrubyGradleWebsiteInstallDir,"docs/api/${archivesBaseName}/${version}")}
onlyIf { project.hasProperty('jrubyGradleWebsiteInstallDir') }
}
bintray {
user = project.bintrayUser
key = project.bintrayKey
publish = true
dryRun = false
configurations = ['archives']
pkg {
userOrg = 'jruby-gradle'
repo = 'plugins'
name = 'jruby-gradle-rspec-plugin'
labels = ['jruby']
version {
name = project.version
vcsTag = "v${project.version}"
attributes = ['gradle-plugin' : 'com.github.jruby-gradle.rspec:com.github.jruby-gradle:jruby-gradle-jar-plugin']
desc = 'This plugin encapsulates rspec gem functionality for JRuby Gradle projects'
}
}
}
bintrayUpload.dependsOn assemble
// vim: ft=groovy

View File

@ -0,0 +1,34 @@
package com.github.jrubygradle.rspec
import com.github.jrubygradle.JRubyPlugin
import groovy.transform.PackageScope
import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.api.Task
/**
* @author Christian Meier
*/
class JRubyRSpecPlugin implements Plugin<Project> {
void apply(Project project) {
project.apply plugin : 'com.github.jruby-gradle.base'
project.apply plugin : 'java-base'
project.configurations.maybeCreate('rspec')
project.tasks.create( 'rspec', RSpec)
addAfterEvaluateHooks(project)
}
@PackageScope
void addAfterEvaluateHooks(Project project) {
project.afterEvaluate {
project.tasks.withType(RSpec) { Task task ->
project.configurations.maybeCreate(task.name)
project.dependencies.add(task.name, "org.jruby:jruby-complete:${task.jrubyVersion}")
project.dependencies.add(task.name, "rubygems:rspec:${task.version}")
}
}
}
}

View File

@ -0,0 +1,59 @@
package com.github.jrubygradle.rspec
import com.github.jrubygradle.GemUtils
import com.github.jrubygradle.internal.JRubyExecUtils
import groovy.transform.PackageScope
import org.gradle.api.Incubating
import org.gradle.api.InvalidUserDataException
import org.gradle.api.DefaultTask
import org.gradle.api.Project
//import org.gradle.api.Configuration
import org.gradle.api.tasks.Input
import org.gradle.api.tasks.OutputDirectory
import org.gradle.api.tasks.TaskAction
/**
* @author Christian Meier
*/
class RSpec extends DefaultTask {
static final String DEFAULT_VERSION = '3.3.0'
String version
@Input
String jrubyVersion = project.jruby.defaultVersion
void jrubyVersion(String version) {
this.jrubyVersion = version
}
RSpec(){
version = DEFAULT_VERSION
}
@TaskAction
void run() {
def config = project.configurations.getByName(name)
File jrubyJar = JRubyExecUtils.jrubyJar(config)
File gemDir = new File(project.buildDir, "${name}-gems")
GemUtils.extractGems(project, jrubyJar, config, gemDir, GemUtils.OverwriteAction.SKIP)
GemUtils.setupJars(config, gemDir, GemUtils.OverwriteAction.OVERWRITE)
project.javaexec {
// JRuby looks on the classpath inside the 'bin' directory
// for executables
classpath jrubyJar.absolutePath, gemDir.absolutePath
main 'org.jruby.Main'
//TODO args '-I' + JRubyExec.jarDependenciesGemLibPath(gemDir)
args '-rjars/setup', '-S','rspec'
environment 'GEM_HOME' : gemDir.absolutePath
environment 'GEM_PATH' : gemDir.absolutePath
environment 'JARS_HOME' : new File(gemDir.absolutePath, 'jars')
environment 'JARS_LOCK' : new File(gemDir.absolutePath, 'Jars.lock')
}
}
}

View File

@ -0,0 +1 @@
implementation-class=com.github.jrubygradle.rspec.JRubyRSpecPlugin

View File

@ -0,0 +1,176 @@
package com.github.jrubygradle.rspec
import org.gradle.api.InvalidUserDataException
import org.gradle.api.Project
import org.gradle.api.Task
import org.gradle.api.file.FileCollection
import org.gradle.testfixtures.ProjectBuilder
import spock.lang.Specification
import org.gradle.process.internal.ExecException
import java.nio.file.Files
import static org.gradle.api.logging.LogLevel.LIFECYCLE
/**
* @author Christian Meier
*
*/
class JRubyRSpecPluginSpec extends Specification {
static final File TESTROOT = new File("${System.getProperty('TESTROOT') ?: 'build/tmp/test/unittests'}")
static final File TESTREPO_LOCATION = new File("${System.getProperty('TESTREPO_LOCATION') ?: 'build/tmp/test/repo'}")
//static final String jrubyTestVersion = '1.7.21'
def project
def specDir
static String captureStdout( Closure closure ){
OutputStream output = new ByteArrayOutputStream()
PrintStream out = System.out
try {
System.out = new PrintStream(output)
closure.call()
}
finally {
System.out = out
}
output.toString()
}
static Set<String> fileNames(FileCollection fc) {
Set<String> names = []
fc.asFileTree.visit { fvd ->
names.add(fvd.relativePath.toString())
}
return names
}
static Project setupProject() {
Project project = ProjectBuilder.builder().build()
//project.gradle.startParameter.offline = true
project.buildscript {
repositories {
flatDir dirs : TESTREPO_LOCATION.absolutePath
}
}
project.buildDir = TESTROOT
//project.logging.level = LIFECYCLE
project.apply plugin: 'com.github.jruby-gradle.rspec'
//project.jruby.defaultRepositories = false
project.repositories {
flatDir dirs : TESTREPO_LOCATION.absolutePath
}
return project
}
void setup() {
if(TESTROOT.exists()) {
// TESTROOT.deleteDir()
}
TESTROOT.mkdirs()
project = setupProject()
specDir = new File(project.projectDir, 'spec').getAbsoluteFile()
}
def 'Checking tasks exist'() {
expect:
project.tasks.getByName('rspec')
}
def "Checking configurations exist"() {
given:
def cfg = project.configurations
expect:
cfg.getByName('rspec')
}
def "Checking jruby-complete jar is configured"() {
given:
project.evaluate()
def cfg = project.configurations.getByName('rspec')
expect:
cfg.files.find { it.name.startsWith('jruby-complete-') }
cfg.files.find { it.name.startsWith('rspec-') }
}
def "Run rspec with defaults and not specs"() {
given:
project.evaluate()
String output = captureStdout {
project.tasks.getByName('rspec').run()
}
expect:
output.contains( 'No examples found.' )
}
def "Throw exception on test failure"() {
when:
Files.createSymbolicLink(specDir.toPath(), new File('src/test/resources/failing/spec').getAbsoluteFile().toPath())
project.evaluate()
project.tasks.getByName('rspec').run()
then:
thrown(ExecException)
}
def "Run rspec"() {
given:
Files.createSymbolicLink(specDir.toPath(), new File('src/test/resources/simple/spec').getAbsoluteFile().toPath())
project.evaluate()
project.tasks.getByName('rspec').run()
String output = captureStdout {
project.tasks.getByName('rspec').run()
}
println output
expect:
output.contains( '3 examples, 0 failures' )
}
def "Run rspec tasks separated"() {
given:
Files.createSymbolicLink(specDir.toPath(), new File('src/test/resources/simple/spec').getAbsoluteFile().toPath())
project.dependencies {
rspec 'rubygems:leafy-metrics:0.6.0'
rspec 'org.slf4j:slf4j-simple:1.6.4'
}
Task task = project.tasks.create( 'mine', RSpec)
project.evaluate()
String outputMine = captureStdout {
task.run()
}
println outputMine
specDir.delete()
Files.createSymbolicLink(specDir.toPath(), new File('src/test/resources/more/spec').getAbsoluteFile().toPath())
String output = captureStdout {
project.tasks.getByName('rspec').run()
}
println output
expect:
outputMine.contains( '3 examples, 0 failures' )
output.contains( '2 examples, 0 failures' )
}
// def "Run rspec tasks separated reversed"() {
// given:
// Files.createSymbolicLink(specDir.toPath(), new File('src/test/resources/more/spec').getAbsoluteFile().toPath())
// project.dependencies {
// rspec 'rubygems:leafy-metrics:0.6.0'
// rspec 'org.slf4j:slf4j-simple:1.6.4'
// }
// project.evaluate()
// String output = captureStdout {
// project.tasks.getByName('rspec').run()
// }
// println output
// expect:
// output.contains( '3 examples, 0 failures' )
// }
}

View File

@ -0,0 +1,5 @@
describe 'Failing' do
it 'should' do
expect(true).to eq false
end
end

View File

@ -0,0 +1,11 @@
<configuration>
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
</encoder>
</appender>
<root level="info">
<appender-ref ref="STDOUT" />
</root>
</configuration>

View File

@ -0,0 +1,11 @@
describe 'More' do
it 'has no $CLASSPATH entries' do
expect($CLASSPATH.size).to eq 5
end
it 'has some loaded gems' do
require 'leafy-metrics'
expect(Gem.loaded_specs.size).to eq 7
end
end

View File

@ -0,0 +1,13 @@
describe 'Simple' do
it 'should' do
expect(true).to eq true
end
it 'has no $CLASSPATH entries' do
expect($CLASSPATH.size).to eq 0
end
it 'has some loaded gems' do
expect(Gem.loaded_specs.size).to eq 6
end
end

1
settings.gradle Normal file
View File

@ -0,0 +1 @@
include 'jruby-gradle-rspec-plugin'