Skip to content

Commit

Permalink
Complete move to Cucumber
Browse files Browse the repository at this point in the history
  • Loading branch information
Julian Ghionoiu committed Oct 16, 2015
1 parent 2fd1387 commit 9d7814c
Show file tree
Hide file tree
Showing 14 changed files with 76 additions and 410 deletions.
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
source 'https://rubygems.org'

ruby '2.2.1'
ruby '2.2.2'

# Specify your gem's dependencies in tdl-client-ruby.gemspec
gemspec
21 changes: 14 additions & 7 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,26 @@ GEM
simplecov (~> 0.10.0)
term-ansicolor (~> 1.3)
thor (~> 0.19.1)
cucumber (2.1.0)
cucumber (2.0.2)
builder (>= 2.1.2)
cucumber-core (~> 1.3.0)
cucumber-core (~> 1.2.0)
diff-lcs (>= 1.1.3)
gherkin3 (~> 3.1.0)
gherkin (~> 2.12)
multi_json (>= 1.7.5, < 2.0)
multi_test (>= 0.1.2)
cucumber-core (1.3.0)
gherkin3 (~> 3.1.0)
cucumber-core (1.2.0)
gherkin (~> 2.12.0)
debase (0.1.4)
debase-ruby_core_source
debase-ruby_core_source (0.8.0)
diff-lcs (1.2.5)
docile (1.1.5)
domain_name (0.5.24)
unf (>= 0.0.5, < 1.0.0)
gherkin3 (3.1.2)
gherkin (2.12.2)
multi_json (~> 1.3)
gherkin (2.12.2-java)
multi_json (~> 1.3)
http-cookie (1.0.2)
domain_name (~> 0.5)
json (1.8.3)
Expand Down Expand Up @@ -76,7 +82,8 @@ PLATFORMS
DEPENDENCIES
bundler (~> 1.9)
coveralls (~> 0.8.2)
cucumber (~> 2.1)
cucumber (~> 2.0.0)
debase (~> 0.1.4)
json (~> 1.8.3)
minitest (= 5.4.1)
minitest-reporters (~> 1.0, >= 1.0.19)
Expand Down
12 changes: 6 additions & 6 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,26 +12,26 @@ end

task :default => :test

Coveralls::RakeTask.new
task :test_with_coveralls => [:test, 'coveralls:push']

require 'cucumber/rake/task'

Cucumber::Rake::Task.new(:features) do |t|
t.cucumber_opts = "features --format pretty --tags ~@wip"
t.cucumber_opts = 'features'
end

Coveralls::RakeTask.new
task :features_with_coveralls => [:features, 'coveralls:push']

#~~~~~~~~~ Play

desc 'Run the example'
task :example do
sh 'jruby -I lib examples/add_numbers.rb'
sh 'ruby -I lib examples/add_numbers.rb'
end


desc 'Run the test playground'
task :playground do
sh 'jruby -I lib ./test/utils/jmx/broker/playground.rb'
sh 'ruby -I lib ./features/utils/jmx/broker/playground.rb'
end


Expand Down
78 changes: 44 additions & 34 deletions features/step_definitions.rb
Original file line number Diff line number Diff line change
@@ -1,14 +1,8 @@
require_relative "./test_helper"
require_relative './test_helper'
require 'logging'

Logging.logger.root.appenders = Logging.appenders.stdout

REQUESTS = [ 'X1, 0, 1', 'X2, 5, 6' ]
EXPECTED_RESPONSES = ['X1, 1', 'X2, 11']
FIRST_EXPECTED_TEXT = 'id = X1, req = [0, 1], resp = 1'
SECOND_EXPECTED_TEXT = 'id = X2, req = [5, 6], resp = 11'
EXPECTED_DISPLAYED_TEXT = [ FIRST_EXPECTED_TEXT, SECOND_EXPECTED_TEXT ]

CORRECT_SOLUTION = lambda { |params|
x = params[0].to_i
y = params[1].to_i
Expand All @@ -27,6 +21,8 @@
STOMP_PORT = 21613
USERNAME = 'test'

# ~~~~~ Setup

Given(/^I start with a clean broker$/) do
@request_queue = BROKER.add_queue("#{USERNAME}.req")
@request_queue.purge
Expand All @@ -37,19 +33,53 @@
@client = TDL::Client.new(HOSTNAME, STOMP_PORT, USERNAME)
end

Given(/^the broker is not available$/) do
@client_without_broker = TDL::Client.new("#{HOSTNAME}1", STOMP_PORT, 'broker')
end

Given(/^I receive the following requests:$/) do |table|
table.raw.each { |request|
@request_queue.send_text_message(request)
}
@request_count = table.raw.count
end

When(/^I go live with an implementation that adds two numbers$/) do
# ~~~~~ Implementations


IMPLEMENTATION_MAP = {
'adds two numbers' => lambda { |params|
x = params[0].to_i
y = params[1].to_i
x + y
},
'returns null' => lambda { nil },
'throws exception' => lambda { raise StandardError },
'is valid' => lambda { :value },
}

def get_lambda(name)
if IMPLEMENTATION_MAP.has_key?(name)
IMPLEMENTATION_MAP[name]
else
raise "Not a valid implementation reference: \"#{name}\""
end
end

When(/^I go live with an implementation that (.*)$/) do |implementation_name|
@captured_io = capture_subprocess_io do
@client.go_live_with(&CORRECT_SOLUTION)
@client.go_live_with(&get_lambda(implementation_name))
end
end

When(/^I do a trial run with an implementation that (.*)$/) do |implementation_name|
@captured_io = capture_subprocess_io do
@client.trial_run_with(&get_lambda(implementation_name))
end
end

# ~~~~~ Assertions

Then(/^the client should consume all requests$/) do
assert_equal 0, @request_queue.get_size, 'Requests have not been consumed'
end
Expand All @@ -60,12 +90,14 @@

Then(/^the client should display to console:$/) do |table|
table.raw.flatten.each { |row|
assert_includes @captured_io.join(""), row
assert_includes @captured_io.join(''), row
}
end

When(/^I go live with an implementation that returns null$/) do
@client.go_live_with { nil }
Then(/^the client should not display to console:$/) do |table|
table.raw.flatten.each { |row|
refute_includes @captured_io.join(''), row
}
end

Then(/^the client should not consume any request$/) do
Expand All @@ -78,30 +110,8 @@
'The response queue has different size. Messages have been published'
end

When(/^I go live with an implementation that throws exception$/) do
@client.go_live_with { raise StandardError }
end

Given(/^the broker is not available$/) do
@client_without_broker = TDL::Client.new("#{HOSTNAME}1", STOMP_PORT, 'broker')
end

When(/^I go live with an implementation that is valid$/) do
@client.go_live_with { :value }
end

Then(/^I should get no exception$/) do
#OBS if you get here there were no exceptions
end

When(/^I do a trial run with an implementation that adds two numbers$/) do
@captured_io = capture_subprocess_io do
@client.trial_run_with(&CORRECT_SOLUTION)
end
end

Then(/^the client should not display to console:$/) do |table|
table.raw.flatten.each { |row|
refute_includes @captured_io.join(""), row
}
end
1 change: 1 addition & 0 deletions features/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
]
SimpleCov.start do
add_filter '/test/'
add_filter '/features/'
end

require 'tdl'
Expand Down
3 changes: 2 additions & 1 deletion tdl-client-ruby.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,6 @@ Gem::Specification.new do |spec|
spec.add_development_dependency 'simplecov', '~>0.10.0'
spec.add_development_dependency 'coveralls', '~>0.8.2'
spec.add_development_dependency 'json', '~>1.8.3'
spec.add_development_dependency 'cucumber', '~>2.1'
spec.add_development_dependency 'cucumber', '~>2.0.0'
spec.add_development_dependency 'debase', '~>0.1.4'
end
8 changes: 8 additions & 0 deletions tdl-client-ruby.iml
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,22 @@
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/test" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/lib" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/features" isTestSource="true" />
</content>
<orderEntry type="jdk" jdkName="rbenv: 2.2.2" jdkType="RUBY_SDK" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" scope="PROVIDED" name="ansi (v1.5.0, rbenv: 2.2.2) [gem]" level="application" />
<orderEntry type="library" scope="PROVIDED" name="builder (v3.2.2, rbenv: 2.2.2) [gem]" level="application" />
<orderEntry type="library" scope="PROVIDED" name="bundler (v1.10.6, rbenv: 2.2.2) [gem]" level="application" />
<orderEntry type="library" scope="PROVIDED" name="coveralls (v0.8.2, rbenv: 2.2.2) [gem]" level="application" />
<orderEntry type="library" scope="PROVIDED" name="cucumber (v2.0.2, rbenv: 2.2.2) [gem]" level="application" />
<orderEntry type="library" scope="PROVIDED" name="cucumber-core (v1.2.0, rbenv: 2.2.2) [gem]" level="application" />
<orderEntry type="library" scope="PROVIDED" name="debase (v0.1.4, rbenv: 2.2.2) [gem]" level="application" />
<orderEntry type="library" scope="PROVIDED" name="debase-ruby_core_source (v0.8.0, rbenv: 2.2.2) [gem]" level="application" />
<orderEntry type="library" scope="PROVIDED" name="diff-lcs (v1.2.5, rbenv: 2.2.2) [gem]" level="application" />
<orderEntry type="library" scope="PROVIDED" name="docile (v1.1.5, rbenv: 2.2.2) [gem]" level="application" />
<orderEntry type="library" scope="PROVIDED" name="domain_name (v0.5.24, rbenv: 2.2.2) [gem]" level="application" />
<orderEntry type="library" scope="PROVIDED" name="gherkin (v2.12.2, rbenv: 2.2.2) [gem]" level="application" />
<orderEntry type="library" scope="PROVIDED" name="http-cookie (v1.0.2, rbenv: 2.2.2) [gem]" level="application" />
<orderEntry type="library" scope="PROVIDED" name="json (v1.8.3, rbenv: 2.2.2) [gem]" level="application" />
<orderEntry type="library" scope="PROVIDED" name="little-plugger (v1.1.4, rbenv: 2.2.2) [gem]" level="application" />
Expand All @@ -31,6 +38,7 @@
<orderEntry type="library" scope="PROVIDED" name="minitest (v5.4.1, rbenv: 2.2.2) [gem]" level="application" />
<orderEntry type="library" scope="PROVIDED" name="minitest-reporters (v1.0.19, rbenv: 2.2.2) [gem]" level="application" />
<orderEntry type="library" scope="PROVIDED" name="multi_json (v1.11.2, rbenv: 2.2.2) [gem]" level="application" />
<orderEntry type="library" scope="PROVIDED" name="multi_test (v0.1.2, rbenv: 2.2.2) [gem]" level="application" />
<orderEntry type="library" scope="PROVIDED" name="netrc (v0.10.3, rbenv: 2.2.2) [gem]" level="application" />
<orderEntry type="library" scope="PROVIDED" name="rake (v10.4.2, rbenv: 2.2.2) [gem]" level="application" />
<orderEntry type="library" scope="PROVIDED" name="rest-client (v1.8.0, rbenv: 2.2.2) [gem]" level="application" />
Expand Down
131 changes: 0 additions & 131 deletions test/tdl/client_test.rb

This file was deleted.

Loading

0 comments on commit 9d7814c

Please sign in to comment.