在Mac OS X上用黄瓜测试ruby(而不是rails)脚本

时间:2014-03-13 17:55:53

标签: ruby macos cucumber

我正在尝试让黄瓜在我的Mac上运行以测试ruby脚本。我使用带有rails的黄瓜并且从来没有遇到过设置它的问题,但是对于我想要测试的ruby脚本来说它似乎有一个问题。

脚本背景:我创建了一个通过TCPServer连接提供mysql数据的脚本,我希望能够测试这个功能。理想情况下,我启动脚本以便接受传入连接,并根据我尝试获取的内容提出错误或数据终点。

这是我所拥有的,错误低于设置:

特征性/支撑性/ env.rb     require_relative File.expand_path('../../../ lib / requirements', FILE

require "capybara/cucumber"
 require 'capybara/dsl'
 require "rspec"

# Capybara.default_driver = :selenium

 Capybara.app_host = 'http://localhost:7125'

 World(Capybara.app = "Api")
 World(Capybara::DSL)
 World(RSpec::Matchers)

特征/ rmws.feature

  Feature: Test conversion of mysql output to JSON

   Scenario:
     Given the index page can be reached
     And There is MYSQL data
     When converted to hash
     And and /mysql location is hit
     Then the data is show in JSON

特征/ step_definitions / rwms_step_definitions.rb

Given(/^the index page can be reached$/) do
  visit 'http://localhost:7125'
  expect(page).to have_content 'This is the index page'
end

Given(/^There is MYSQL data$/) do
  pending # express the regexp above with the code you wish you had
end

When(/^converted to hash$/) do
  pending # express the regexp above with the code you wish you had
end

When(/^and \/mysql location is hit$/) do
  pending # express the regexp above with the code you wish you had
end

Then(/^the data is show in JSON$/) do
  pending # express the regexp above with the code you wish you had
end

输出

   $ cucumber
   Feature: Test conversion of mysql output to JSON

    Scenario:                             # features/rmws.feature:3
   wrong argument type String (expected Module) (TypeError)
  /Users/lovell/.rvm/gems/ruby-2.0.0-p451/gems/cucumber-1.3.11/lib/cucumber/rb_support/rb_language.rb:150:in `extend'
  /Users/lovell/.rvm/gems/ruby-2.0.0-p451/gems/cucumber-1.3.11/lib/cucumber/rb_support/rb_language.rb:150:in `block in extend_world'
  /Users/lovell/.rvm/gems/ruby-2.0.0-p451/gems/cucumber-1.3.11/lib/cucumber/rb_support/rb_language.rb:149:in `each'
  /Users/lovell/.rvm/gems/ruby-2.0.0-p451/gems/cucumber-1.3.11/lib/cucumber/rb_support/rb_language.rb:149:in `extend_world'
  /Users/lovell/.rvm/gems/ruby-2.0.0-p451/gems/cucumber-1.3.11/lib/cucumber/rb_support/rb_language.rb:94:in `begin_rb_scenario'
  /Users/lovell/.rvm/gems/ruby-2.0.0-p451/gems/cucumber-1.3.11/lib/cucumber/rb_support/rb_language.rb:128:in `begin_scenario'
  /Users/lovell/.rvm/gems/ruby-2.0.0-p451/gems/cucumber-1.3.11/lib/cucumber/language_support/language_methods.rb:14:in `before'
  /Users/lovell/.rvm/gems/ruby-2.0.0-p451/gems/cucumber-1.3.11/lib/cucumber/runtime/support_code.rb:112:in `block in fire_hook'
  /Users/lovell/.rvm/gems/ruby-2.0.0-p451/gems/cucumber-1.3.11/lib/cucumber/runtime/support_code.rb:111:in `each'
  /Users/lovell/.rvm/gems/ruby-2.0.0-p451/gems/cucumber-1.3.11/lib/cucumber/runtime/support_code.rb:111:in `fire_hook'
  /Users/lovell/.rvm/gems/ruby-2.0.0-p451/gems/cucumber-1.3.11/lib/cucumber/runtime.rb:107:in `before'
  /Users/lovell/.rvm/gems/ruby-2.0.0-p451/gems/cucumber-1.3.11/lib/cucumber/runtime.rb:98:in `before_and_after'
  /Users/lovell/.rvm/gems/ruby-2.0.0-p451/gems/cucumber-1.3.11/lib/cucumber/runtime.rb:82:in `block in with_hooks'
  /Users/lovell/.rvm/gems/ruby-2.0.0-p451/gems/cucumber-1.3.11/lib/cucumber/runtime/support_code.rb:120:in `call'
  /Users/lovell/.rvm/gems/ruby-2.0.0-p451/gems/cucumber-1.3.11/lib/cucumber/runtime/support_code.rb:120:in `block (3 levels) in around'
  /Users/lovell/.rvm/gems/ruby-2.0.0-p451/gems/cucumber-1.3.11/lib/cucumber/language_support/language_methods.rb:9:in `block in around'
  /Users/lovell/.rvm/gems/ruby-2.0.0-p451/gems/cucumber-1.3.11/lib/cucumber/language_support/language_methods.rb:97:in `call'
  /Users/lovell/.rvm/gems/ruby-2.0.0-p451/gems/cucumber-1.3.11/lib/cucumber/language_support/language_methods.rb:97:in `execute_around'
  /Users/lovell/.rvm/gems/ruby-2.0.0-p451/gems/cucumber-1.3.11/lib/cucumber/language_support/language_methods.rb:8:in `around'
  /Users/lovell/.rvm/gems/ruby-2.0.0-p451/gems/cucumber-1.3.11/lib/cucumber/runtime/support_code.rb:119:in `block (2 levels) in around'
  /Users/lovell/.rvm/gems/ruby-2.0.0-p451/gems/cucumber-1.3.11/lib/cucumber/runtime/support_code.rb:123:in `call'
  /Users/lovell/.rvm/gems/ruby-2.0.0-p451/gems/cucumber-1.3.11/lib/cucumber/runtime/support_code.rb:123:in `around'
  /Users/lovell/.rvm/gems/ruby-2.0.0-p451/gems/cucumber-1.3.11/lib/cucumber/runtime.rb:94:in `around'
  /Users/lovell/.rvm/gems/ruby-2.0.0-p451/gems/cucumber-1.3.11/lib/cucumber/runtime.rb:81:in `with_hooks'
  /Users/lovell/.rvm/gems/ruby-2.0.0-p451/gems/cucumber-1.3.11/lib/cucumber/ast/tree_walker.rb:13:in `execute'
  /Users/lovell/.rvm/gems/ruby-2.0.0-p451/gems/cucumber-1.3.11/lib/cucumber/ast/scenario.rb:32:in `block in accept'
  /Users/lovell/.rvm/gems/ruby-2.0.0-p451/gems/cucumber-1.3.11/lib/cucumber/ast/scenario.rb:79:in `with_visitor'
  /Users/lovell/.rvm/gems/ruby-2.0.0-p451/gems/cucumber-1.3.11/lib/cucumber/ast/scenario.rb:31:in `accept'
  /Users/lovell/.rvm/gems/ruby-2.0.0-p451/gems/cucumber-1.3.11/lib/cucumber/ast/tree_walker.rb:58:in `block in visit_feature_element'
  /Users/lovell/.rvm/gems/ruby-2.0.0-p451/gems/cucumber-1.3.11/lib/cucumber/ast/tree_walker.rb:170:in `broadcast'
  /Users/lovell/.rvm/gems/ruby-2.0.0-p451/gems/cucumber-1.3.11/lib/cucumber/ast/tree_walker.rb:57:in `visit_feature_element'
  /Users/lovell/.rvm/gems/ruby-2.0.0-p451/gems/cucumber-1.3.11/lib/cucumber/ast/feature.rb:38:in `block in accept'
  /Users/lovell/.rvm/gems/ruby-2.0.0-p451/gems/cucumber-1.3.11/lib/cucumber/ast/feature.rb:37:in `each'
  /Users/lovell/.rvm/gems/ruby-2.0.0-p451/gems/cucumber-1.3.11/lib/cucumber/ast/feature.rb:37:in `accept'
  /Users/lovell/.rvm/gems/ruby-2.0.0-p451/gems/cucumber-1.3.11/lib/cucumber/ast/tree_walker.rb:27:in `block in visit_feature'
  /Users/lovell/.rvm/gems/ruby-2.0.0-p451/gems/cucumber-1.3.11/lib/cucumber/ast/tree_walker.rb:170:in `broadcast'
  /Users/lovell/.rvm/gems/ruby-2.0.0-p451/gems/cucumber-1.3.11/lib/cucumber/ast/tree_walker.rb:26:in `visit_feature'
  /Users/lovell/.rvm/gems/ruby-2.0.0-p451/gems/cucumber-1.3.11/lib/cucumber/ast/features.rb:28:in `block in accept'
  /Users/lovell/.rvm/gems/ruby-2.0.0-p451/gems/cucumber-1.3.11/lib/cucumber/ast/features.rb:17:in `each'
  /Users/lovell/.rvm/gems/ruby-2.0.0-p451/gems/cucumber-1.3.11/lib/cucumber/ast/features.rb:17:in `each'
  /Users/lovell/.rvm/gems/ruby-2.0.0-p451/gems/cucumber-1.3.11/lib/cucumber/ast/features.rb:27:in `accept'
  /Users/lovell/.rvm/gems/ruby-2.0.0-p451/gems/cucumber-1.3.11/lib/cucumber/ast/tree_walker.rb:21:in `block in visit_features'
  /Users/lovell/.rvm/gems/ruby-2.0.0-p451/gems/cucumber-1.3.11/lib/cucumber/ast/tree_walker.rb:170:in `broadcast'
  /Users/lovell/.rvm/gems/ruby-2.0.0-p451/gems/cucumber-1.3.11/lib/cucumber/ast/tree_walker.rb:20:in `visit_features'
  /Users/lovell/.rvm/gems/ruby-2.0.0-p451/gems/cucumber-1.3.11/lib/cucumber/runtime.rb:49:in `run!'
  /Users/lovell/.rvm/gems/ruby-2.0.0-p451/gems/cucumber-1.3.11/lib/cucumber/cli/main.rb:47:in `execute!'
  /Users/lovell/.rvm/gems/ruby-2.0.0-p451/gems/cucumber-1.3.11/bin/cucumber:13:in `<top (required)>'
  /Users/lovell/.rvm/gems/ruby-2.0.0-p451/bin/cucumber:23:in `load'
  /Users/lovell/.rvm/gems/ruby-2.0.0-p451/bin/cucumber:23:in `<main>'
  /Users/lovell/.rvm/gems/ruby-2.0.0-p451/bin/ruby_executable_hooks:15:in `eval'
  /Users/lovell/.rvm/gems/ruby-2.0.0-p451/bin/ruby_executable_hooks:15:in `<main>'
   $ 

1 个答案:

答案 0 :(得分:0)

你可以使用rake来运行黄瓜测试,我将它用于我写的宝石。您可以找到其他文档here

require 'bundler'
require 'rake/clean'

require 'rake/testtask'

require 'cucumber'
require 'cucumber/rake/task' 
require 'rspec/core/rake_task'
Cucumber::Rake::Task.new(:features) do |t|
  t.cucumber_opts = "features --format html -o #{CUKE_RESULTS} --format pretty --no-source -x"
  t.fork = false
end