I have a small modular Sinatra app that I'm building to act as a front end for a separate REST API. Everything was going swimmingly until I added HTTParty (to make requests to my API) and now no page will load.
The API server was running on localhost port 9393, but the error persists even when I shut down that server. (And when I comment out the one HTTParty request I have in my routes.
Here's my app.rb file:
ENV["RACK_ENV"] ||= "development"
require 'bundler' require 'sinatra/base' require 'sinatra/contrib/all' require 'json' require 'sinatra/strong-params' require 'haml' require 'sinatra/partial' require 'sass'
# require 'httparty'
require 'pry'
Bundler.setup Bundler.require(:default, ENV["RACK_ENV"].to_sym)
# DATABASE CONFIG
# dbconfig = YAML.load(File.read('./config/database.yml'))
# ActiveRecord::Base.establish_connection dbconfig["#{settings.environment}"]
# Base URL for API calls API_BASE = 'http://localhost:9393'
class PantryApp < Sinatra::Base include HTTParty register Sinatra::Partial
set :root, File.dirname(__FILE__) enable :sessions
# set folder for templates to ../views, but make the path absolute set :views, File.expand_path('../app/views', __FILE__)
# don't enable logging when running tests configure :production, :development do
enable :logging end
# will be used to display 404 error pages not_found do
erb :not_found end
get '/' do
haml :login end
get '/login' do
haml :login end
post '/login' do
# api_token = HTTParty.post(API_BASE + '/token', query: {email: params['email'], password: params['password']})
binding.pry
haml :user_pantry end
# REQUIRE ALL APP FILES Dir["./app/**/*.rb"].each { |f| require f }
end
And when I try to go to /login, I get:
Boot Error
Something went wrong while loading config.ru
Errno::ECONNREFUSED: Connection refused - connect(2) for nil port 80
/Users/rileypants/.rvm/rubies/ruby-2.2.3/lib/ruby/2.2.0/net/http.rb:879:in `initialize' /Users/rileypants/.rvm/rubies/ruby-2.2.3/lib/ruby/2.2.0/net/http.rb:879:in `open' /Users/rileypants/.rvm/rubies/ruby-2.2.3/lib/ruby/2.2.0/net/http.rb:879:in `block in connect' /Users/rileypants/.rvm/rubies/ruby-2.2.3/lib/ruby/2.2.0/timeout.rb:73:in `timeout' /Users/rileypants/.rvm/rubies/ruby-2.2.3/lib/ruby/2.2.0/net/http.rb:878:in `connect' /Users/rileypants/.rvm/rubies/ruby-2.2.3/lib/ruby/2.2.0/net/http.rb:863:in `do_start' /Users/rileypants/.rvm/rubies/ruby-2.2.3/lib/ruby/2.2.0/net/http.rb:852:in `start' /Users/rileypants/.rvm/rubies/ruby-2.2.3/lib/ruby/2.2.0/net/http.rb:1375:in `request' /users/rileypants/.rvm/gems/ruby-2.2.3#pantry_ui/gems/httparty-0.13.7/lib/httparty/request.rb:117:in `perform' /users/rileypants/.rvm/gems/ruby-2.2.3#pantry_ui/gems/httparty-0.13.7/lib/httparty.rb:545:in `perform_request' /users/rileypants/.rvm/gems/ruby-2.2.3#pantry_ui/gems/httparty-0.13.7/lib/httparty.rb:476:in `get' /Users/rileypants/dev/capstone/ui/app.rb:46:in `<class:PantryApp>' /Users/rileypants/dev/capstone/ui/app.rb:26:in `<top (required)>' config.ru:1:in `require' config.ru:1:in `block in inner_app' /users/rileypants/.rvm/gems/ruby-2.2.3#pantry_ui/gems/rack-1.6.4/lib/rack/builder.rb:55:in `instance_eval' /users/rileypants/.rvm/gems/ruby-2.2.3#pantry_ui/gems/rack-1.6.4/lib/rack/builder.rb:55:in `initialize' config.ru:1:in `new' config.ru:1:in `inner_app' /users/rileypants/.rvm/gems/ruby-2.2.3#pantry_ui/gems/shotgun-0.9.1/lib/shotgun/loader.rb:113:in `eval' /users/rileypants/.rvm/gems/ruby-2.2.3#pantry_ui/gems/shotgun-0.9.1/lib/shotgun/loader.rb:113:in `inner_app' /users/rileypants/.rvm/gems/ruby-2.2.3#pantry_ui/gems/shotgun-0.9.1/lib/shotgun/loader.rb:103:in `assemble_app' /users/rileypants/.rvm/gems/ruby-2.2.3#pantry_ui/gems/shotgun-0.9.1/lib/shotgun/loader.rb:86:in `proceed_as_child' /users/rileypants/.rvm/gems/ruby-2.2.3#pantry_ui/gems/shotgun-0.9.1/lib/shotgun/loader.rb:31:in `call!' /users/rileypants/.rvm/gems/ruby-2.2.3#pantry_ui/gems/shotgun-0.9.1/lib/shotgun/loader.rb:18:in `call' /users/rileypants/.rvm/gems/ruby-2.2.3#pantry_ui/gems/shotgun-0.9.1/lib/shotgun/favicon.rb:12:in `call' /users/rileypants/.rvm/gems/ruby-2.2.3#pantry_ui/gems/rack-1.6.4/lib/rack/urlmap.rb:66:in `block in call' /users/rileypants/.rvm/gems/ruby-2.2.3#pantry_ui/gems/rack-1.6.4/lib/rack/urlmap.rb:50:in `each' /users/rileypants/.rvm/gems/ruby-2.2.3#pantry_ui/gems/rack-1.6.4/lib/rack/urlmap.rb:50:in `call' /users/rileypants/.rvm/gems/ruby-2.2.3#pantry_ui/gems/rack-1.6.4/lib/rack/builder.rb:153:in `call' /users/rileypants/.rvm/gems/ruby-2.2.3#pantry_ui/gems/rack-1.6.4/lib/rack/handler/webrick.rb:88:in `service' /Users/rileypants/.rvm/rubies/ruby-2.2.3/lib/ruby/2.2.0/webrick/httpserver.rb:138:in `service' /Users/rileypants/.rvm/rubies/ruby-2.2.3/lib/ruby/2.2.0/webrick/httpserver.rb:94:in `run' /Users/rileypants/.rvm/rubies/ruby-2.2.3/lib/ruby/2.2.0/webrick/server.rb:294:in `block in start_thread'
and config.ru is simply:
require File.dirname(__FILE__) + '/app.rb'
map('/users') { run UsersController }
map('/') { run PantryApp }
It looks to me like something about the 'get' from my first route in app.rb is leading to httparty instead of Sinatra, but I don't know why or what to do to fix it.
I answered my own question, but I want to leave this here in case it is useful for someone else.
In this case, I needed to not use the include HTTParty in the class, but rather require it at the top. I think using include was what was mixing up the get request.
Related
My Ruby file
require 'puppet'
# ...
require 'googleauth'
module PuppetX
module Puppetlabs
module Google_cloud_dns
class Provider < PuppetX::Puppetlabs::Swagger::Provider
def client
self.class.client
end
My RSpec file
I am using this two alternatively, but none of them working:
require_relative'../../lib/puppet_x/puppetlabs/google_cloud_dns/provider'
File.expand_path("../../lib/puppet_x/puppetlabs/google_cloud_dns/provider.rb",File.dirname(__FILE__)))
require 'spec_helper'
require_relative '../../lib/puppet_x/puppetlabs/google_cloud_dns/provider'
File.expand_path("../../lib/puppet_x/puppetlabs/google_cloud_dns/provider.rb", File.dirname(__FILE__))
describe Provider do
it "checks function" do
provide = Provider.new
provide.should respond_to :client
end
end
The error which I am getting
rspec Mymodule/gc_dns/puppet-google_cloud_dns/spec/classes/provider_spec.rb --format documentation/home/vivekkumarmishra17/Mymodule/gc_dns/puppet-google_cloud_dns/spec/classes/provider_spec.rb:19:in `<top (required)>': uninitialized constant Provider (NameError)
from /var/lib/gems/1.9.1/gems/rspec-core-3.4.4/lib/rspec/core/configuration.rb:1361:in `load'
from /var/lib/gems/1.9.1/gems/rspec-core-3.4.4/lib/rspec/core/configuration.rb:1361:in `block in load_spec_files'
from /var/lib/gems/1.9.1/gems/rspec-core-3.4.4/lib/rspec/core/configuration.rb:1359:in `each'
from /var/lib/gems/1.9.1/gems/rspec-core-3.4.4/lib/rspec/core/configuration.rb:1359:in `load_spec_files'
from /var/lib/gems/1.9.1/gems/rspec-core-3.4.4/lib/rspec/core/runner.rb:106:in `setup'
from /var/lib/gems/1.9.1/gems/rspec-core-3.4.4/lib/rspec/core/runner.rb:92:in `run'
from /var/lib/gems/1.9.1/gems/rspec-core-3.4.4/lib/rspec/core/runner.rb:78:in `run'
from /var/lib/gems/1.9.1/gems/rspec-core-3.4.4/lib/rspec/core/runner.rb:45:in `invoke'
from /var/lib/gems/1.9.1/gems/rspec-core-3.4.4/exe/rspec:4:in `<top (required)>'
from /usr/local/bin/rspec:23:in `load'
from /usr/local/bin/rspec:23:in `<main>'
Can anyone tell what I am doing wrong?
When running rspec to test a feature test using Sinatra Base, we are getting the following error.
This is how our feature tests looks
require 'capybara/rspec'
feature 'Enter names' do
scenario 'submitting names' do
visit('/')
fill_in :player_1_name, with: 'Dave'
fill_in :player_2_name, with: 'Mittens'
click_button 'Submit'
expect(page).to have_content 'Dave vs. Mittens'
end
end
This is our Gemfile:
source 'https://rubygems.org'
gem 'sinatra'
gem 'rspec-sinatra'
gem 'capybara'
error:
1.1) Failure/Error: visit "/"
ArgumentError:
rack-test requires a rack application, but none was given
# /Users/Russell/.rvm/gems/ruby-2.2.3/gems/capybara-2.4.4/lib/capybara/rack_test/driver.rb:16:in `initialize'
# /Users/Russell/.rvm/gems/ruby-2.2.3/gems/capybara-2.4.4/lib/capybara.rb:372:in `new'
# /Users/Russell/.rvm/gems/ruby-2.2.3/gems/capybara-2.4.4/lib/capybara.rb:372:in `block in <top (required)>'
# /Users/Russell/.rvm/gems/ruby-2.2.3/gems/capybara-2.4.4/lib/capybara/session.rb:79:in `call'
# /Users/Russell/.rvm/gems/ruby-2.2.3/gems/capybara-2.4.4/lib/capybara/session.rb:79:in `driver'
# /Users/Russell/.rvm/gems/ruby-2.2.3/gems/capybara-2.4.4/lib/capybara/session.rb:227:in `visit'
# /Users/Russell/.rvm/gems/ruby-2.2.3/gems/capybara-2.4.4/lib/capybara/dsl.rb:51:in `block (2 levels) in <module:DSL>'
# ./spec/feature/feature_spec.rb:5:in `block (2 levels) in <top (required)>'
1.2) Failure/Error: Unable to find matching line from backtrace
ArgumentError:
rack-test requires a rack application, but none was given
# /Users/Russell/.rvm/gems/ruby-2.2.3/gems/capybara-2.4.4/lib/capybara/rack_test/driver.rb:16:in `initialize'
# /Users/Russell/.rvm/gems/ruby-2.2.3/gems/capybara-2.4.4/lib/capybara.rb:372:in `new'
# /Users/Russell/.rvm/gems/ruby-2.2.3/gems/capybara-2.4.4/lib/capybara.rb:372:in `block in <top (required)>'
# /Users/Russell/.rvm/gems/ruby-2.2.3/gems/capybara-2.4.4/lib/capybara/session.rb:79:in `call'
# /Users/Russell/.rvm/gems/ruby-2.2.3/gems/capybara-2.4.4/lib/capybara/session.rb:79:in `driver'
# /Users/Russell/.rvm/gems/ruby-2.2.3/gems/capybara-2.4.4/lib/capybara/session.rb:103:in `reset!'
# /Users/Russell/.rvm/gems/ruby-2.2.3/gems/capybara-2.4.4/lib/capybara.rb:257:in `block in reset_sessions!'
# /Users/Russell/.rvm/gems/ruby-2.2.3/gems/capybara-2.4.4/lib/capybara.rb:257:in `each'
# /Users/Russell/.rvm/gems/ruby-2.2.3/gems/capybara-2.4.4/lib/capybara.rb:257:in `reset_sessions!'
# /Users/Russell/.rvm/gems/ruby-2.2.3/gems/capybara-2.4.4/lib/capybara/rspec.rb:20:in `block (2 levels) in <top (required)>'
We've tried requiring the spec_helper file in our feature test, and also requiring our app.rb in the feature test and we get a different error saying it cannot load sinatra-base
Here is our spec_helper
ENV['RACK_ENV'] = 'test'
require File.join(File.dirname(__FILE__), '..', 'app.rb')
require 'capybara'
require 'capybara/rspec'
require 'rspec'
Capybara.app = Battle
RSpec.configure do |config|
config.include Capybara::DSL
config.expect_with :rspec do |expectations|
expectations.include_chain_clauses_in_custom_matcher_descriptions = true
end
config.mock_with :rspec do |mocks|
mocks.verify_partial_doubles = true
end
end
Any direction would be massively appreciated.
Thanks
Russ
Have a look here:
http://recipes.sinatrarb.com/p/testing/rspec
It suggests, among other things, adding the following to your spec_helper.rb:
module RSpecMixin
include Rack::Test::Methods
def app() Sinatra::Application end
end
RSpec.configure do |config|
config.include RSpecMixin
end
I was experimenting with the soundcloud gem and suddenly I always get an error with every request I make.
For example this following code:
require 'soundcloud'
client = SoundCloud.new(:client_id => MY_CLIENT_ID)
track_url = 'https://soundcloud.com/sohight/sohight-cheevy-money-is-love-out-now'
track = client.get('/resolve', :url => track_url)
puts track.genre
Anyone knows why I get this error?
/Users/angel/.rvm/gems/ruby-2.2.0/gems/httparty-0.13.4/lib/httparty/hash_conversions.rb:33:in `normalize_param': uninitialized constant HTTParty::HashConversions::ERB (NameError)
from /Users/angel/.rvm/gems/ruby-2.2.0/gems/httparty-0.13.4/lib/httparty/hash_conversions.rb:15:in `block in to_params'
from /Users/angel/.rvm/gems/ruby-2.2.0/gems/httparty-0.13.4/lib/httparty/hash_conversions.rb:15:in `each'
from /Users/angel/.rvm/gems/ruby-2.2.0/gems/httparty-0.13.4/lib/httparty/hash_conversions.rb:15:in `map'
from /Users/angel/.rvm/gems/ruby-2.2.0/gems/httparty-0.13.4/lib/httparty/hash_conversions.rb:15:in `to_params'
from /Users/angel/.rvm/gems/ruby-2.2.0/gems/httparty-0.13.4/lib/httparty/request.rb:148:in `normalize_query'
from /Users/angel/.rvm/gems/ruby-2.2.0/gems/httparty-0.13.4/lib/httparty/request.rb:180:in `query_string'
from /Users/angel/.rvm/gems/ruby-2.2.0/gems/httparty-0.13.4/lib/httparty/request.rb:70:in `uri'
from /Users/angel/.rvm/gems/ruby-2.2.0/gems/httparty-0.13.4/lib/httparty/request.rb:157:in `setup_raw_request'
from /Users/angel/.rvm/gems/ruby-2.2.0/gems/httparty-0.13.4/lib/httparty/request.rb:98:in `perform'
from /Users/angel/.rvm/gems/ruby-2.2.0/gems/httparty-0.13.4/lib/httparty.rb:521:in `perform_request'
from /Users/angel/.rvm/gems/ruby-2.2.0/gems/httparty-0.13.4/lib/httparty.rb:459:in `get'
from /Users/angel/.rvm/gems/ruby-2.2.0/gems/soundcloud-0.3.2/lib/soundcloud/client.rb:27:in `block in get'
from /Users/angel/.rvm/gems/ruby-2.2.0/gems/soundcloud-0.3.2/lib/soundcloud/client.rb:145:in `call'
from /Users/angel/.rvm/gems/ruby-2.2.0/gems/soundcloud-0.3.2/lib/soundcloud/client.rb:145:in `handle_response'
from /Users/angel/.rvm/gems/ruby-2.2.0/gems/soundcloud-0.3.2/lib/soundcloud/client.rb:26:in `get'
from sound.rb:9:in `<main>'
Possibly a bug in HTTParty.
Line 33 of hash_conversions.rb:
param << "#{key}=#{ERB::Util.url_encode(value.to_s)}&"
Put this at the top of your script and try again:
require 'erb'
I am trying to get cucumber working on my Mac for testing a ruby script. I use cucumber with rails and have never had an issue setting it up there, but seem to be having quite an issue creating it just for a ruby script that I want to test.
Script background: I have created a script that serves mysql data via a TCPServer connection and I want to be able to test this functionality. So ideally I launch the script so that it accepts incoming connections and depending on what I am attempting to get to it presents an error or the data end point.
Here is what I have and the error is below the settings:
features/support/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)
features/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
features/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
Output
$ 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>'
$
You could use rake to run cucumber tests, I use it for a gem that I wrote. You can find additional doc 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
Run cucumber --init to get the testing suite set up.
I have a ruby web- / data-server application which is built on a Sinatra foundation. I'm adding EventMachine and em-websocket so that I can have async data transfer connections.
#! /usr/bin/env ruby
require 'yajl'
require 'json'
require 'em-websocket'
require 'sinatra/base'
require 'thin'
require './Actors/DataProvider.rb'
my_host = '10.2.56.87'
my_web_port = '4004'
my_web_sock = '8008'
EventMachine.epoll # choose kernel epoll over select for deterministic execution under load
EventMachine.run do
class SinatraApp < Sinatra::Base
configure do
set :bind, '10.2.56.87'
set :port, '4004'
end
encoder = Yajl::Encoder.new
communicator = DataProvider.new( encoder )
get '/' do
redirect '/index-work.html'
end
before do
content_type 'application/json'
end
post '/auth' do
end
post '/data/:id' do
puts 'got d i '
end
end
EventMachine::WebSocket.start( :host => my_host, :port => my_web_sock ) do | ws |
ws.onopen do
end
ws.onmessage do
end
ws.onclose do
end
end
begin
SinatraApp.run!
rescue => ex
puts "#{ ex.class}: #{ ex.message }"
end
end
The Thin server worked fine when just serving Sinatra, but now that I've added the EM foundation the following occurs:
/usr/local/rvm/gems/ruby-1.9.3-p286/gems/thin-2.0.0.pre/lib/thin/server.rb:192:in `block (2 levels) in start': undefined method `attach_server' for EventMachine:Module (NoMethodError)
from /usr/local/rvm/gems/ruby-1.9.3-p286/gems/thin-2.0.0.pre/lib/thin/server.rb:191:in `each'
from /usr/local/rvm/gems/ruby-1.9.3-p286/gems/thin-2.0.0.pre/lib/thin/server.rb:191:in `block in start'
from /usr/local/rvm/gems/ruby-1.9.3-p286/gems/thin-2.0.0.pre/lib/thin/backends/prefork.rb:30:in `block (2 levels) in start'
from /usr/local/rvm/gems/ruby-1.9.3-p286/gems/eventmachine-1.0.0/lib/eventmachine.rb:187:in `call'
from /usr/local/rvm/gems/ruby-1.9.3-p286/gems/eventmachine-1.0.0/lib/eventmachine.rb:187:in `run_machine'
from /usr/local/rvm/gems/ruby-1.9.3-p286/gems/eventmachine-1.0.0/lib/eventmachine.rb:187:in `run'
from /usr/local/rvm/gems/ruby-1.9.3-p286/gems/thin-2.0.0.pre/lib/thin/backends/prefork.rb:23:in `block in start'
from /usr/local/rvm/gems/ruby-1.9.3-p286/gems/preforker-0.1.1/lib/preforker/worker.rb:52:in `call'
from /usr/local/rvm/gems/ruby-1.9.3-p286/gems/preforker-0.1.1/lib/preforker/worker.rb:52:in `work'
from /usr/local/rvm/gems/ruby-1.9.3-p286/gems/preforker-0.1.1/lib/preforker.rb:129:in `block (2 levels) in spawn_missing_workers'
from (eval):6:in `block in fork'
from (eval):6:in `fork'
from (eval):6:in `fork'
from /usr/local/rvm/gems/ruby-1.9.3-p286/gems/preforker-0.1.1/lib/preforker.rb:126:in `block in spawn_missing_workers'
from /usr/local/rvm/gems/ruby-1.9.3-p286/gems/preforker-0.1.1/lib/preforker.rb:124:in `times'
from /usr/local/rvm/gems/ruby-1.9.3-p286/gems/preforker-0.1.1/lib/preforker.rb:124:in `spawn_missing_workers'
from /usr/local/rvm/gems/ruby-1.9.3-p286/gems/preforker-0.1.1/lib/preforker.rb:44:in `run'
from /usr/local/rvm/gems/ruby-1.9.3-p286/gems/thin-2.0.0.pre/lib/thin/backends/prefork.rb:37:in `start'
from /usr/local/rvm/gems/ruby-1.9.3-p286/gems/thin-2.0.0.pre/lib/thin/server.rb:187:in `start'
from /usr/local/rvm/gems/ruby-1.9.3-p286/gems/rack-1.4.1/lib/rack/handler/thin.rb:13:in `run'
from /usr/local/rvm/gems/ruby-1.9.3-p286/gems/sinatra-1.3.3/lib/sinatra/base.rb:1350:in `run!'
from /home/devel/ISF_Server/server-work.rb:122:in `block in <top (required)>'
from /usr/local/rvm/gems/ruby-1.9.3-p286/gems/eventmachine-1.0.0/lib/eventmachine.rb:187:in `call'
from /usr/local/rvm/gems/ruby-1.9.3-p286/gems/eventmachine-1.0.0/lib/eventmachine.rb:187:in `run_machine'
from /usr/local/rvm/gems/ruby-1.9.3-p286/gems/eventmachine-1.0.0/lib/eventmachine.rb:187:in `run'
from /home/devel/ISF_Server/server-work.rb:15:in `<top (required)>'
from /usr/local/rvm/gems/ruby-1.9.3-p286/gems/ruby-debug-ide-0.4.17.beta14/lib/ruby-debug-ide.rb:127:in `debug_load'
from /usr/local/rvm/gems/ruby-1.9.3-p286/gems/ruby-debug-ide-0.4.17.beta14/lib/ruby-debug-ide.rb:127:in `debug_program'
from /usr/local/rvm/gems/ruby-1.9.3-p286/gems/ruby-debug-ide-0.4.17.beta14/bin/rdebug-ide:118:in `<top (required)>'
from -e:1:in `load'
from -e:1:in `<main>'
I do notice that the Thin gem was recently updated, but EM has not been. That's my next point of inquiry. Somebody else posted that Thin should not be run from within EM.run block, but the example I am building from had it this way.
Okay. I corresponded with Marc-Andre Cournoyer directly. He says, first, don't spawn This (through Sinatra) inside an EM.run block.
Secondly, the error is generated from Thin 2 (pre) which requires the EventMachine live Edition, or gem eventmachine-le.
Mo' bettah now. :D