Unable to send exception data to Raygun through the rails app and rake test task. Works through Rails Console - ruby

I am unable to send exception data to Raygun through the Rails App and the Rake Test task on our staging environment. The sending of exception data works through the Rails Console though.
Raygun.rb
Raygun.setup do |config|
config.api_key = [Key]
config.filterparameters = Rails.application.config.filterparameters
config.enable_reporting = !Rails.env.development?
end
Gemfile.lock raygun entry
raygun4ruby (1.1.9)
httparty (~> 0.11)
json
rack
The error that I get when I try the rake test
$ RAILS_ENV=production rake raygun:test
Oh-oh, something went wrong - double check your API key
API Key - [FIltered])
rake aborted!
TypeError: no implicit conversion of HTTParty::Response into String
/var/lib/gems/2.3.0/gems/raygun4ruby-1.1.9/lib/raygun/testable.rb:17:in `rescue in tracktestexception'
/var/lib/gems/2.3.0/gems/raygun4ruby-1.1.9/lib/raygun/testable.rb:8:in `tracktestexception'
/var/lib/gems/2.3.0/gems/raygun4ruby-1.1.9/lib/tasks/raygun.tasks:5:in `block (2 levels) in
Raygun::ItWorksException: Woohoo! Your Raygun<->Ruby connection is set up correctly
/var/lib/gems/2.3.0/gems/raygun4ruby-1.1.9/lib/raygun/testable.rb:9:in `tracktestexception'
/var/lib/gems/2.3.0/gems/raygun4ruby-1.1.9/lib/tasks/raygun.tasks:5:in `block (2 levels) in
Tasks: TOP => raygun:test
(See full trace by running task with --trace)
We are using AWS for our staging environment. It is surprising to me that Rails C works while through the app and rake test it does not.
When done through the Rails Console
irb(main):003:0> class ItWorksException < StandardError; end
=> nil
irb(main):004:0> e = ItWorksException.new("Woohoo! Your Raygun<->Ruby connection is set up correctly")
=> #
irb(main):005:0> response = Raygun.track_exception(e)
[Raygun] Tracking Exception...
=> #
irb(main):006:0> response.success?
=> true

This may seem a bit odd, but can you try running it in a slightly different order like:
rake RAILS_ENV=production raygun:test

Related

rake spec failed, it cannot load or find constant or global variable

I create standalone rspec test script to testing existing api framework. It works pretty well, but I found problem where in the Rakefile I need to assign some value from YAML file (uri link, email) either CONSTANT or $global_var the code in the Rakefile looks like this:
require 'rubygems'
require 'bundler/setup'
require 'yaml'
require 'rspec/core/rake_task'
task :default => :spec
desc 'Running rspec test'
task :spec, :option do |t, opt|
choice = opt[:choice]
if choice == "production"
puts 'Test running on production'
VAR = YAML::load(File.read(File.expand_path("../config/prod_variable.yml", __FILE__)))
elsif choice == "development"
puts 'Test running on development'
VAR = YAML::load(File.read(File.expand_path("../config/dev_variable.yml", __FILE__)))
end
puts VAR['URI'] #=> print out the value correctly
RSpec::Core::RakeTask.new do |task|
test = Rake.application.original_dir
task.fail_on_error = false
task.rspec_opts = '--format documentation --color'
end
end
When I run the rake command on the terminal, the rspec failed find the VAR constant value. Here is the error message from rspec
Failures:
1) ApiTest Testing API platform for GET request
Failure/Error: #var = ApiTest.new(VAR['URI'] ,
NameError:
uninitialized constant VAR
# ./rspec_test/api_test/api_test_get_spec.rb:8:in `block (2 levels) in <top (required)>'
2) ApiTest Testing API platform for POST request
Failure/Error: #zat = ApiTest.new(VAR['URI'] ,
NameError:
uninitialized constant VAR
# ./rspec_test/api_test/api_test_post_spec.rb:7:in `block (2 levels) in <top (required)>'
Is there any idea how to get this works? I need to get value from VAR constant or global variable, but seems ruby failed to assign the value.
If opt[:choice] is neither "production" nor "development", VAR is undefined in your code.

Ruby: CLI progress bar with open-uri

I'm trying to experiment with the open-uri and want to make a Command line interface progress bar.
I've going over the documentation for OpenURI::OpenRead where is has a progress bar code sample.
pbar = nil
open('latest.zip', 'wb') do |fo|
fo.print open('http://wordpress.org/latest.zip',
:content_length_proc => lambda { |t|
if t && 0 < t
pbar = ProgressBar.new("...", t)
pbar.file_transfer_mode
end
},
:progress_proc => lambda {|s|
pbar.set s if pbar
}).read
end
but I'm can keep getting the following error:
zip_dowloader.rb:11:in `block (2 levels) in <main>': uninitialized constant ProgressBar (NameError)
gem install progressbar
Then add:
require 'progressbar'
to the top of your script.
Or, in a bundler-enabled project, add:
gem 'progressbar'
to your Gemfile and run bundle install.

Sinatra, Mongoid, Heroku, MongoHQ: connecting to Mongodb

Trying to get Mongoid up and running with Sinatra on Heroku (MongoHQ). Previous experience with Rails but first time with the stack and Sinatra.
Started with one of the simple examples on the web (app.rb):
require 'rubygems'
require 'sinatra'
require 'mongo'
require 'mongoid'
configure do
Mongoid.load!('mongoid.yml')
Mongoid.configure do |config|
if ENV['MONGOHQ_URL']
conn = Mongo::Connection.from_uri(ENV['MONGOHQ_URL'])
uri = URI.parse(ENV['MONGOHQ_URL'])
# problem happens here
config.master = conn.db(uri.path.gsub(/^\//, ''))
else
config.master = Mongo::Connection.from_uri("mongodb://localhost:27017").db('test')
end
end
end
# Models
class Counter
include Mongoid::Document
field :count, :type => Integer
def self.increment
c = first || new({:count => 0})
c.inc(:count, 1)
c.save
c.count
end
end
# Controllers
get '/' do
"Hello visitor n" + Counter.increment.to_s
end
For reference, mongoid.yml looks like:
development:
sessions:
default:
database: localhost
production:
sessions:
default:
uri: <%= ENV['MONGOHQ_URL'] %>
As per app.rb (# problem happens here), my logs say:
/app/app.rb:15:in `block (2 levels) in <top (required)>': undefined method `master=' for Mongoid::Config:Module (NoMethodError)
from /app/vendor/bundle/ruby/1.9.1/gems/mongoid-3.0.3/lib/mongoid.rb:112:in `configure'
from /app/app.rb:11:in `block in <top (required)>'
from /app/vendor/bundle/ruby/1.9.1/gems/sinatra-1.3.2/lib/sinatra/base.rb:1273:in `configure'
from /app/app.rb:8:in `<top (required)>'
I have also tried variants, including:
config.master = Mongo::Connection.from_uri(ENV['MONGOHQ_URL']).db('appXXXXX')
Mongoid.database = Mongo::Connection.from_uri(ENV['MONGOHQ_URL']).db('appXXXXXXX')
But get the same error:
undefined method `master` for Mongoid::Config:Module (NoMethodError)
or:
undefined method `database=` for Mongoid::Config:Module (NoMethodError)
What am I missing?
Shouldn't be
configure do
Mongoid.load!('mongoid.yml')
end
enough?
That's what the mongid docs are saying. The MONGOHQ_URL environment variable already contains every information to initialize the connection to the db.
So was using Mongoid 3.x ... which:
Doesn't use 10gen driver: uses Moped
Doesn't use config.master
The canonical sample code above which is all over the web works out of the box with Mongoid 2.x so have dropped back to that for the time being.
Thanks!

Rake task not running

Every time I call my rake task it say:
[2012-07-12 15:50:01] ERROR IOError: An existing connection was forcibly closed by the remote host
C:/jruby-1.3.1/lib/ruby/1.8/webrick/httpresponse.rb:324:in `_write_data'
C:/jruby-1.3.1/lib/ruby/1.8/webrick/httpresponse.rb:180:in `send_header'
C:/jruby-1.3.1/lib/ruby/1.8/webrick/httpresponse.rb:103:in `send_response'
C:/jruby-1.3.1/lib/ruby/1.8/webrick/httpserver.rb:79:in `run'
C:/jruby-1.3.1/lib/ruby/1.8/webrick/server.rb:173:in `start_thread'
C:/jruby-1.3.1/lib/ruby/1.8/webrick/server.rb:162:in `start'
[2012-07-12 15:50:29] ERROR IOError: An existing connection was forcibly closed by the remote host
C:/jruby-1.3.1/lib/ruby/1.8/webrick/httpserver.rb:55:in `run'
C:/jruby-1.3.1/lib/ruby/1.8/webrick/server.rb:173:in `start_thread'
C:/jruby-1.3.1/lib/ruby/1.8/webrick/server.rb:162:in `start'
I have tryed different options thinking that it could be the call to the rake task but apparently isn't, also I have tryed with Mongrel and WEBRick in case that it could be the server.
I'm using Jruby 1.3.1
The task it's not been executed.
This is part of my code:
application_controller.rb
def call_rake(task, options = {})
options[:rails_env] ||= Rails.env
args = options.map { |n, v| "#{n.to_s.upcase}='#{v}'" }
system "C:/jruby-1.3.1/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake #{task} #{args.join(' ')} start"
end
forbidden_file.rake
desc "Process CSV file"
task :process_file => :environment do
forbidden_file = ForbiddenFile.find(ENV["csv"])
forbidden_file.upload_file
end
Controller
...
call_rake :process_file, :csv => params[:files]
redirect_to forbidden_files_url
...
It's working now, I just removed the word start from the command.
system "rake #{task} #{args.join(' ')}"

pusher-client gem throwing 2 for 1 error with Presence-Channels

The pusher-client rubygem works fine when subscribing to Public Channels, but it's throwing "ArgumentError: wrong number of arguments (2 for 1)" when I try to subscribe to a Presence or Private Channel. Does this happen for anyone else?
module PusherClientTest
require 'pusher-client'
PusherClient.logger = Logger.new(STDOUT)
options = { :secret => '12345' }
socket = PusherClient::Socket.new("54321", options)
USER_ID = 1
socket.subscribe('presence-TestChannel', USER_ID)
socket.bind('remark') do |data|
puts data
end
socket.connect
end
Results in:
ree-1.8.7-2010.02 > PusherClientTest
ArgumentError: wrong number of arguments (2 for 1)
from /Users/Dev/Sites/test_app/app/models/pusher_client_test.rb:16:in `subscribe'
from /Users/Dev/Sites/test_app/app/models/pusher_client_test.rb:16
from /Users/Dev/.rvm/gems/ree-1.8.7-2010.02#test_app/gems/activesupport-2.3.14/lib/active_support/dependencies.rb:406:in `load_without_new_constant_marking'
from /Users/Dev/.rvm/gems/ree-1.8.7-2010.02#test_app/gems/activesupport-2.3.14/lib/active_support/dependencies.rb:406:in `load_file'
from /Users/Dev/.rvm/gems/ree-1.8.7-2010.02#test_app/gems/activesupport-2.3.14/lib/active_support/dependencies.rb:547:in `new_constants_in'
from /Users/Dev/.rvm/gems/ree-1.8.7-2010.02#test_app/gems/activesupport-2.3.14/lib/active_support/dependencies.rb:405:in `load_file'
from /Users/Dev/.rvm/gems/ree-1.8.7-2010.02#test_app/gems/activesupport-2.3.14/lib/active_support/dependencies.rb:285:in `require_or_load'
from /Users/Dev/.rvm/gems/ree-1.8.7-2010.02#test_app/gems/activesupport-2.3.14/lib/active_support/dependencies.rb:451:in `load_missing_constant'
from /Users/Dev/.rvm/gems/ree-1.8.7-2010.02#test_app/gems/activesupport-2.3.14/lib/active_support/dependencies.rb:106:in `const_missing_not_from_s3_library'
from /Users/Dev/.rvm/gems/ree-1.8.7-2010.02#test_app/gems/aws-s3-0.6.2/lib/aws/s3/extensions.rb:206:in `const_missing'
from /Users/Dev/.rvm/gems/ree-1.8.7-2010.02#test_app/gems/activesupport-2.3.14/lib/active_support/dependencies.rb:118:in `const_missing'
from (irb):1
The git URL to the pusher-client repo needs to be specified in order to subscribe to presence & private Channels. It appears as though the published pusher-client gem hasn't been updated with the latest commits to the repo.
gem 'pusher-client', :git => "git://github.com/logankoester/pusher-client.git"
Further to this, specifying a fork of the main repo will enable :user_info options to be passed across in the subscription:
gem 'pusher-client', :git => "git://github.com/agileanimal/pusher-client.git"

Resources