lib/polytrix/rspec.rb in polytrix-0.0.1 vs lib/polytrix/rspec.rb in polytrix-0.1.0.pre
- old
+ new
@@ -7,69 +7,48 @@
raise 'polytrix/rspec requires rspec 2 or later'
end
module Polytrix
module RSpec
- module Helper
- def challenge_runner
- @challenge_runner ||= Polytrix::ChallengeRunner.createRunner
- end
-
- def execute_challenge(sdk_dir, challenge_name, vars)
- implementor_name = File.basename(sdk_dir) # Might not be a good assumption
- implementor = Polytrix.implementors.find { |i| i.name == implementor_name }
- challenge = ChallengeBuilder.new(implementor).build :name => challenge_name, :vars => vars, :basedir => sdk_dir, :implementor => implementor.name
- example.metadata[:polytrix] = challenge
- result = challenge.run
- yield result
- end
- end
-
class << self
- def run_manifest(manifest)
- manifest['suites'].each do |suite_name, suite_config|
- describe suite_name do
- suite_config['samples'].each do |scenario|
- code_sample scenario, '', suite_config['env'].to_hash do |result|
- instance_exec result, &Polytrix.default_validator_callback
+ def shared_examples(caller) # rubocop:disable MethodLength
+ # FIXME: Long method because it's hard to eval in the right context
+ caller.instance_eval do
+ Polytrix.manifest['suites'].each do |suite_name, suite_config|
+ describe suite_name do
+ samples = suite_config['samples'] || []
+ samples.each do |scenario|
+ describe scenario do
+ Polytrix.implementors.each do |sdk|
+ it sdk.name, sdk.name.to_sym => true do
+ begin
+ skip "#{sdk.name} is not setup" unless File.directory? sdk.basedir
+ challenge = sdk.build_challenge suite: suite_name, name: scenario, vars: suite_config['env']
+ example.metadata[:polytrix_challenge] = challenge
+ challenge.run
+ validators = Polytrix::ValidatorRegistry.validators_for challenge
+ validators.each do |validator|
+ instance_exec challenge, &validator.callback
+ end
+ rescue Polytrix::FeatureNotImplementedError => e
+ skip e.message
+ rescue ThreadError => e
+ # Extra debug info for ThreadError
+ $stderr.puts "ThreadError detected: #{e.message}"
+ $stderr.puts "ThreadError backtrace: #{e.backtrace}"
+ fail e
+ end
+ end
+ end
+ end
end
end
end
end
end
- end
- end
-end
-def code_sample(challenge, description = '', environment = [], services = [], &block)
- challenge_file = challenge.downcase.gsub(' ', '_')
- describe challenge, markdown: description,
- # :environment => redact(environment),
- services: services do
- Polytrix.implementors.each do |sdk|
- sdk = sdk.name if sdk.respond_to? :name
- it sdk, sdk.to_sym => true, 'data-challenge' => challenge_file, 'data-sdk' => sdk do
- Polytrix.results.example_started example
- begin
- sdk_dir = Polytrix.sdk_dir sdk
- pending "#{sdk} is not setup" unless File.directory? sdk_dir
- challenge_runner.find_challenge! challenge_file, sdk_dir
- execute_challenge sdk_dir, challenge_file, environment do |result|
- Polytrix.results.execution_result example, result
- instance_exec result, &block
- end
-
- rescue Polytrix::FeatureNotImplementedError => e
- pending e.message
- rescue ThreadError => e
- puts "ThreadError detected: #{e.message}"
- puts "ThreadError backtrace: #{e.backtrace}"
- raise e
- end
+ def run_manifest(manifest)
+ shared_examples(self)
end
end
end
end
-
-RSpec.configure do |c|
- c.include Polytrix::RSpec::Helper
-end
\ No newline at end of file