diff --git a/jruby-gradle-rspec-plugin/src/main/groovy/com/github/jrubygradle/rspec/RSpec.groovy b/jruby-gradle-rspec-plugin/src/main/groovy/com/github/jrubygradle/rspec/RSpec.groovy index f815bd4..babbd5d 100644 --- a/jruby-gradle-rspec-plugin/src/main/groovy/com/github/jrubygradle/rspec/RSpec.groovy +++ b/jruby-gradle-rspec-plugin/src/main/groovy/com/github/jrubygradle/rspec/RSpec.groovy @@ -61,6 +61,10 @@ class RSpec extends DefaultTask { if (pattern != null) { args += ['--pattern', pattern] } + String file = System.getProperty("${name}.file") + if (file != null) { + args += [file] + } jruby.exec(args) } } diff --git a/jruby-gradle-rspec-plugin/src/test/groovy/com/github/jrubygradle/rspec/JRubyRSpecPluginSpec.groovy b/jruby-gradle-rspec-plugin/src/test/groovy/com/github/jrubygradle/rspec/JRubyRSpecPluginSpec.groovy index 00788be..85c6301 100644 --- a/jruby-gradle-rspec-plugin/src/test/groovy/com/github/jrubygradle/rspec/JRubyRSpecPluginSpec.groovy +++ b/jruby-gradle-rspec-plugin/src/test/groovy/com/github/jrubygradle/rspec/JRubyRSpecPluginSpec.groovy @@ -242,4 +242,48 @@ class JRubyRSpecPluginSpec extends Specification { output.contains( '0 examples, 0 failures' ) outputOther.contains( '4 examples, 0 failures' ) } + + def "Run rspec with directory picker via system properties"() { + given: + Task task = project.tasks.create('other', RSpec) + project.evaluate() + System.setProperty('rspec.file', new File('src/test/resources/simple/spec').absolutePath) + String output = captureStdout { + project.tasks.getByName('rspec').run() + } + String outputOther = captureStdout { + task.run() + } + expect: + outputOther.contains( '0 examples, 0 failures' ) + output.contains( '4 examples, 0 failures' ) + } + + def "Run rspec task with file picker via system properties"() { + given: + Task task = project.tasks.create('other', RSpec) + project.evaluate() + System.properties.remove('rspec.file') + System.setProperty('other.file', new File('src/test/resources/simple/spec/one_spec.rb').absolutePath) + String outputOther = captureStdout { + project.tasks.getByName('rspec').run() + } + String output = captureStdout { + task.run() + } + expect: + outputOther.contains( '0 examples, 0 failures' ) + output.contains( '4 examples, 0 failures' ) + } + + def "fails rspec with file picker if file is missing"() { + when: + project.evaluate() + System.setProperty('rspec.file', 'path/does/not/exists/one_spec.rb') + String output = captureStdout { + project.tasks.getByName('rspec').run() + } + then: + thrown(ExecException) + } }