Skip to content

Commit

Permalink
#4 fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Yegor Bugayenko committed Aug 7, 2014
1 parent 0affccf commit 3793c85
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 3 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[![Build Status](http://img.teamed.io/btn/125x25.svg)](http://www.teamed.io)
[![Build Status](http://img.teamed.io/btn/dark-125x25.svg)](http://www.teamed.io)

[![Build Status](https://travis-ci.org/teamed/pdd.svg)](https://travis-ci.org/teamed/pdd)
[![Gem Version](https://badge.fury.io/rb/pdd.svg)](http://badge.fury.io/rb/pdd)
Expand Down
3 changes: 1 addition & 2 deletions bin/pdd
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@ require 'slop'

opts = Slop.parse do
banner 'Usage: pdd [options]'
help
strict
on 'h', 'help', 'Print this page'
on 'v', 'verbose', 'Enable verbose mode'
on 's', 'source', 'Source directory to parse', argument: :required
on 'f', 'file', 'File to save XML into', argument: :required
Expand Down
24 changes: 24 additions & 0 deletions features/cli.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
Feature: Command Line Processing
As a source code writer I want to be able to
call PDD as a command line tool

Scenario: Help can be printed
When I run bin/pdd with "-h"
Then Exit code is zero
And Stdout contains "Usage: pdd"

Scenario: Simple puzzles collecting
Given I have a "Sample.java" file with content:
"""
public class Main {
/**
* @todo #13 Let's do it later, dude
* or maybe even never :)
*/
public void main(String[] args) {
// later
}
}
"""
When I run bin/pdd with "-v -s . -f out.xml"
Then XML file "out.xml" matches "/puzzles[count(puzzle)=1]"
24 changes: 24 additions & 0 deletions features/step_definitions/steps.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
require 'nokogiri'
require 'tmpdir'
require 'slop'
require 'English'

Before do
@dir = Dir.mktmpdir('test')
Expand Down Expand Up @@ -66,3 +67,26 @@
end
fail "PDD didn't fail" if passed
end

When(/^I run bin\/pdd with "([^"]*)"$/) do |arg|
home = File.join(File.dirname(__FILE__), '../..')
@stdout = `ruby -I#{home}/lib #{home}/bin/pdd #{arg}`
@exitstatus = $CHILD_STATUS.exitstatus
end

Then(/^Stdout contains "([^"]*)"$/) do |txt|
unless @stdout.include?(txt)
fail "STDOUT doesn't contain '#{txt}':\n#{@stdout}"
end
end

Then(/^XML file "([^"]+)" matches "([^"]+)"$/) do |file, xpath|
xml = Nokogiri::XML.parse(File.read(file))
if xml.xpath(xpath).empty?
fail "XML file #{file} doesn't match \"#{xpath}\":\n#{xml}"
end
end

Then(/^Exit code is zero$/) do
fail "Non-zero exit code #{@exitstatus}" unless @exitstatus == 0
end

0 comments on commit 3793c85

Please sign in to comment.