Skip to content

Commit

Permalink
added commandline tests with cucumber and aruba
Browse files Browse the repository at this point in the history
  • Loading branch information
erhard committed May 25, 2014
1 parent 0b65a51 commit b7be926
Show file tree
Hide file tree
Showing 17 changed files with 140 additions and 156 deletions.
6 changes: 4 additions & 2 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
source 'http://rubygems.org'
gem 'recursive-open-struct'
group :test do
group :test do
gem "mixItRuby" , path: "."
gem 'guard-rspec'
gem 'guard-cucumber'
gem 'guard'
gem 'rspec'
gem 'cucumber'
gem 'aruba'
end

19 changes: 17 additions & 2 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,12 +1,23 @@
PATH
remote: .
specs:
mixItRuby (0.0.0)

GEM
remote: http://rubygems.org/
specs:
aruba (0.5.4)
childprocess (>= 0.3.6)
cucumber (>= 1.1.1)
rspec-expectations (>= 2.7.0)
builder (3.2.2)
celluloid (0.15.2)
timers (~> 1.1.0)
celluloid-io (0.15.0)
celluloid (>= 0.15.0)
nio4r (>= 0.5.0)
childprocess (0.5.3)
ffi (~> 1.0, >= 1.0.11)
coderay (1.1.0)
cucumber (1.3.15)
builder (>= 2.1.2)
Expand All @@ -25,6 +36,9 @@ GEM
lumberjack (~> 1.0)
pry (>= 0.9.12)
thor (>= 0.18.1)
guard-cucumber (1.4.1)
cucumber (>= 1.2.0)
guard (>= 1.1.0)
guard-rspec (4.2.8)
guard (~> 2.1)
rspec (>= 2.14, < 4.0)
Expand All @@ -45,7 +59,6 @@ GEM
rb-fsevent (0.9.4)
rb-inotify (0.9.3)
ffi (>= 0.5.0)
recursive-open-struct (0.4.5)
rspec (2.14.1)
rspec-core (~> 2.14.0)
rspec-expectations (~> 2.14.0)
Expand All @@ -62,8 +75,10 @@ PLATFORMS
ruby

DEPENDENCIES
aruba
cucumber
guard
guard-cucumber
guard-rspec
recursive-open-struct
mixItRuby!
rspec
7 changes: 4 additions & 3 deletions Guardfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ notification :tmux, display_message: true
guard :rspec do
watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
watch('spec/spec_helper.rb') { "spec" }
watch('bin/mixit') { "spec" }
watch(%r{^spec/.+_spec\.rb$})
watch(%r{^spec/spec_helper\.rb})
end



guard :cucumber do
watch(%r{^features/(.+)\.feature$}) { "bundle exec cucumber" }
end
35 changes: 20 additions & 15 deletions bin/mixit
Original file line number Diff line number Diff line change
@@ -1,35 +1,40 @@
#!/usr/bin/env ruby
require 'mixer'
require 'optparse'


require "mixer"
require "json"
options = {}
optparse = OptionParser.new do|opts|
opts.banner = "Usage: mixit [-o outputfile -i inputfile -t templatefile]"
opts.on( '-i', '--input FILE', 'json Inputfile' ) do|p|
opts.on( '-i', '--input FILE', 'json inputfile' ) do|p|
options[:inputfile] = p
end

opts.on( '-o', '--output FILE', 'mixed outputfile' ) do|p|
options[:outputfile] = p
end


opts.on( '-t', '--template directory', 'place where the templates are' ) do|p|
opts.on( '-t', '--templates DIR', 'place where the templates are' ) do|p|
options[:templateDir] = p
end

end.parse!


mixer = MIX::Mixer.new

input_string = IO.read(options["inputfile"])
outputfile = File.new(options["outputfile"])
inputdata = JSON.pars(input_string)



input_filename= options[:inputfile]
if !input_filename
STDOUT.puts "no inputfile given"
exit(1)
end

inputfile = options[:inputfile]
path = File.dirname(inputfile)
input_string = IO.read(inputfile)
outputfile = options[:outputfile] || File.basename(inputfile,".*") + ".out"
outputfile = File.join(path,outputfile)
inputdata = JSON.parse(input_string, {:symbolize_names => true})
templateDir = options[:templateDir]
mixer.mixItRuby(inputdata, templateDir)
mixer.writeResult2File(outputfile)



58 changes: 2 additions & 56 deletions features/env.rb
Original file line number Diff line number Diff line change
@@ -1,56 +1,2 @@
require 'capybara/cucumber'
require 'capybara/poltergeist'
@processingWorkingDir=File.dirname(__FILE__)
@processingWorkDir=@processingWorkingDir+"/../processing/vert/"
#Start the two servers :
#
#Processing Server :
# @t1 = fork do
# system("cd #{@processingWorkDir} && rvm use jruby-1.7.1@masha_gems && vertx run #{@processingWorkDir}server_app.js -conf test.json")
# end
# sleep(5)
# @siteServerPath=File.dirname(__FILE__) + "/../site/bin/" # This is a Serverinstance which is not deployed. It simulates the server of the provider
# @t2 = fork do
# system("cd #{@siteServerPath} && ruby pageServer.rb -p 4568")
# end
# sleep(5)
if ENV['IN_BROWSER']
# On demand: non-headless tests via Selenium/WebDriver
# To run the scenarios in browser (default: Firefox), use the following command line:
# IN_BROWSER=true bundle exec cucumber
# or (to have a pause of 1 second between each step):
# IN_BROWSER=true PAUSE=1 bundle exec cucumber
Capybara.default_driver = :selenium
AfterStep do
sleep (ENV['PAUSE'] || 0).to_i
end
else
# DEFAULT: headless tests with poltergeist/PhantomJS
Capybara.register_driver :poltergeist do |app|
Capybara::Poltergeist::Driver.new(
app,
window_size: [1280, 1024]#,
#debug: true
)
end
Capybara.default_driver = :poltergeist
Capybara.javascript_driver = :poltergeist
end
at_exit do

puts @t1
puts @t2


if @t1
puts "processserver killed"
Process.kill("HUP",@t1)
sleep(10)
end
if @t2
puts "pageServer killed"
Process.kill("HUP",@t2)
sleep(10)
end
puts "bye"
end
$LOAD_PATH << File.join(File.dirname(__FILE__),'../lib')
require "aruba/cucumber"
29 changes: 24 additions & 5 deletions features/mixer.feature
Original file line number Diff line number Diff line change
@@ -1,13 +1,32 @@
Feature:Commandline functionality

A User should be able to call a command to get a mixed outputfile
@announce
Scenario: CommandlineCall should give an error, when no inputfile
When I run `mixit`
Then the output should contain "no inputfile given"



Scenario: CommandlineCall
Given a empty testenvironment with one erb file and one data file
When I enter "mix dataInput dataoutput templateDir"
Then I should get a file with the name dataInput and the suffix mixed


Scenario: exit status of 0
When I run `mixit`
Then the exit status should be 1



@announce
Scenario: Generatining an outputfile
Given the testdatafile is in the aruba filespace
When I run `mixit -i testdata/testdata.json`
When I run `cat testdata/testdata.out`
Then the stdout should contain "Bond"


@announce
Scenario: mixIt should also run from another templatepath
Given the testdatafile is in the aruba filespace
Given the templatefiles are in the aruby filespace
When I run `mixit -i testdata/testdata.json -t tmp/aruba`
And I run `cat testdata/testdata.out`
Then the stdout should contain "Bond"
19 changes: 7 additions & 12 deletions features/step_definitions/mixer_steps.rb
Original file line number Diff line number Diff line change
@@ -1,18 +1,13 @@


Given(/^the testdatafile is in the aruba filespace$/) do
`mkdir tmp/aruba/testdata && cp testdata/testdata.json tmp/aruba/testdata`
end


Given(/^a empty testenvironment with one erb file and one data file$/) do
###just do something
if File.exists?("features/testDir/output/test.txt")
system("rm /features/testDir/output/*")
end
end
Given(/^the templatefiles are in the aruby filespace$/) do
`mkdir tmp/aruba/templates && cp templates/* tmp/aruba/templates`
end


When(/^I enter "(.*?)"$/) do |arg1|
system(arg1)
end

Then(/^I should get a file with the name dataInput and the suffix mixed$/) do
File.exists?("features/testDir/output/test.txt").should==true
end
Empty file removed features/testDir/data.json
Empty file.
Empty file.
50 changes: 25 additions & 25 deletions lib/mixer.rb
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
module MIX
require 'ostruct'
require 'erb'

module MIX
class Mixer

def initialize(data)
@data = data
def initialize()
@result = []
@deeps = 0
end
#get all variables if the level, binds it and templates it
#this is important to maintain the order of buildingblock for the input
#get all variables if the level, binds it and templates it
#this is important to maintain the order of buildingblock for the input


def premix(data)
def premix(data,templatePath)
bind_hash={}
data.each do |k,v|
if v.kind_of?(Hash)
Expand All @@ -23,47 +23,47 @@ def premix(data)
et = ErbIT.new( bind_hash)
template = getTemplate(bind_hash[:id])
filled = et.render(template)
puts filled.inspect
@result.push(filled)
end


def mixItRuby(data)
def mixItRuby(data,templatePath=nil)
###putting an Index to the elements to find the sequence which has been in the json###
@deeps=@deeps + 1
premix(data)
premix(data,templatePath)
bind_hash={}
data.each do |k,v|
if v.kind_of?(Hash)
mixItRuby(v)
elsif v.kind_of?(Array)
ar = v
ar.each do |element|
mixItRuby(element)
end
ar = v
ar.each do |element|
mixItRuby(element)
end
else
#done in premix
#done in premix
end
end

puts @deeps.inspect
@deeps = @deeps -1
end


def writeResult2File(filename)
File.write(filename,@result)
end


def getResult
@result
end
def getResult
@result
end



def getTemplate(id)
path = File.join(File.dirname(__FILE__),'../templates')
filename = File.join(path,id)
template = IO.read(filename)
template
def getTemplate(id,path = File.dirname(__FILE__))
path = File.join(path, '../templates')
filename = File.join(path,id)
template = IO.read(filename)
template
end


Expand Down
4 changes: 4 additions & 0 deletions lib/template.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@

#This file is for future use to extract the variables from a erb template


class Template
attr_accessor :file_path,:contents

Expand Down
20 changes: 9 additions & 11 deletions mixItRuby.gemspec
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
Gem::Specification.new do |s|
s.name = 'mixItRuby'
s.version = '0.0.0'
s.date = '2014-05-29'
s.summary = "MitItRuby!"
s.description = "A gem for mixing a nested json structure in erb files"
s.authors = ["Erhard Karger"]
s.email = '[email protected]'
s.files = ["lib/mixer.rb"]
s.homepage = "www.kargers.org"
'http://rubygems.org/gems/mixItRuby'
s.license = 'MIT'
s.name = 'mixItRuby'
s.version = '0.0.0'
s.date = '2014-05-29'
s.summary = "MitItRuby!"
s.description = "A gem for mixing a nested json structure in erb files"
s.authors = ["Erhard Karger"]
s.email = '[email protected]'
s.homepage = 'http://rubygems.org/gems/mixItRuby'
s.license = 'MIT'
git_files = `git ls-files`.split("\n") rescue ''
s.files = git_files
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
Expand Down
5 changes: 4 additions & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,10 @@ Then an array follow. An Array must be build of hashes, which can have subarrays
What is mixItRuby needed for ?
==============================
With that little gem you can build up personalized letters or emails or html pages.
Just imagine the erb file are tex files or xmlfo or html files or they are files with are ruby file again, which produce some output.
Just imagine the erb file are tex files or xml-fo or html files or they are files with are ruby file again, which produce some output.

Another possibility is create other json files. Imagine the template erbs are templates for json. Then for example in SOA business objects can be chained and enriched from services.

There are a lot of posibilities.


Expand Down
Loading

0 comments on commit b7be926

Please sign in to comment.