Rails system tests unable to load a lib file required in a model, file loads fine in development, how can I fix this? - selenium-chromedriver

(From chapter 14 in 'Agile Web Development with Rails 6')
I am trying to run a system test which touches a model which requires a file from the /lib directory. The file loads fine and the code works fine on localhost in development mode, but as soon as I run the test it errors with:
Error:
OrdersTest#test_visiting_the_index:
DRb::DRbRemoteError: cannot load such file -- pago (LoadError)
app/models/order.rb:1:in `<main>'
Excerpt from the model, order.rb, that requires the file is:
require "pago"
class Order < ApplicationRecord
enum pay_type: {
"Cheque" => 0,
"Credit card" => 1,
"Purchase order" => 2
}
has_many :line_items, dependent: :destroy
validates :name, :address, :email, presence: true
validates :pay_type, inclusion: pay_types.keys
def add_line_items_from_cart(cart)
cart.line_items.each do |item|
item.cart_id = nil
line_items << item
end
end
def charge!(pay_type_params)
payment_details = {}
payment_method = nil
case pay_type
when "Cheque"
payment_method = :cheque
payment_details[:routing] = pay_type_params[:routing_number]
payment_details[:account] = pay_type_params[:account_number]
when "Credit card"
payment_method = :credit_card
month,year = pay_type_params[:expiration_date].split(//)
payment_details[:cc_num] = pay_type_params[:credit_card_number]
payment_details[:expiration_month] = month
payment_details[:expiration_year] = year
when "Purchase order"
payment_method = :po
payment_details[:po_num] = pay_type_params[:po_number]
end
payment_result = Pago.make_payment(
order_id: id,
payment_method: payment_method,
payment_details: payment_details
)
if payment_result.succeeded?
OrderMailer.received(self).deliver_later
else
raise payment_result.error
end
end
end
Excerpt from the actual /lib/pago.rb:
require "ostruct"
class Pago
def self.make_payment(order_id:,
payment_method:,
payment_details:)
case payment_method
when :cheque
Rails.logger.info "Processing cheque: " +
payment_details.fetch(:routing).to_s + "/" +
payment_details.fetch(:account).to_s
when :credit_card
Rails.logger.info "Processing credit_card: " +
payment_details.fetch(:cc_num).to_s + "/" +
payment_details.fetch(:expiration_month).to_s + "/" +
payment_details.fetch(:expiration_year).to_s
when :po
Rails.logger.info "Processing purchase order: " +
payment_details.fetch(:po_num).to_s
else
raise "Unknown payment_method #{payment_method}"
end
sleep 3 unless Rails.env.test?
Rails.logger.info "Done Processing Payment"
OpenStruct.new(succeeded?: true)
end
end
The test file that I', trying to run:
test/system/orders_test.rb
require "application_system_test_case"
class OrdersTest < ApplicationSystemTestCase
include ActiveJob::TestHelper
setup do
#order = orders(:one)
end
test "visiting the index" do
visit orders_url
assert_selector "h1", text: "Orders"
end
test "destroying an Order" do
visit orders_url
page.accept_confirm do
click_on "Destroy", match: :first
end
assert_text "Order was successfully destroyed"
end
test "check full payment with cheque flow" do
LineItem.delete_all
Order.delete_all
visit store_index_url
click_on 'Add to cart', match: :first
click_on 'Checkout'
fill_in 'order_name', with: 'Dave Thomas'
fill_in 'order_address', with: '123 Main Street'
fill_in 'order_email', with: 'dave#example.com'
assert_no_selector "#order_routing_number"
select 'Cheque', from: 'Pay type'
fill_in 'Routing #', with: '123456'
fill_in 'Account #', with: '678901'
assert_selector "#order_routing_number"
assert_selector "#order_account_number"
perform_enqueued_jobs { click_button 'Place order' }
orders = Order.all
assert_equal 1, orders.size
order = orders.first
assert_equal 'Dave Thomas', order.name
assert_equal '123 Main Street', order.address
assert_equal 'dave#example.com', order.email
assert_equal 'Cheque', order.pay_type
assert_equal 1, order.line_items.size
mail = ActionMailer::Base.deliveries.last
assert_equal ['dave#example.com'], mail.to
assert_equal 'James Kemp<from#example.com>', mail[:from].value
assert_equal 'Order received; thanks', mail.subject
end
test "check CC number for credit card payment choice" do
visit store_index_url
click_on 'Add to cart', match: :first
click_on 'Checkout'
fill_in 'order_name', with: 'Dave Thomas'
fill_in 'order_address', with: '123 Main Street'
fill_in 'order_email', with: 'dave#example.com'
assert_no_selector "#order_credit_card_number"
assert_no_selector "#order_expiration_date"
select 'Credit card', from: 'Pay type'
assert_selector "#order_credit_card_number"
assert_selector "#order_expiration_date"
end
test "check PO number for purchase order payment choice" do
visit store_index_url
click_on 'Add to cart', match: :first
click_on 'Checkout'
fill_in 'order_name', with: 'Dave Thomas'
fill_in 'order_address', with: '123 Main Street'
fill_in 'order_email', with: 'dave#example.com'
assert_no_selector "#order_po_number"
select 'Purchase order', from: 'Pay type'
assert_selector "#order_po_number"
end
end
If i run rails console require 'pago' returns true. I don't see any clues in the various config and environment files as to what the problem might be. The tutorial code seems to be char by char the same as mine. I just can't work out what's oging wrong here. Can anyone help?
My Gemfile FYI (I have bundle installed):
source 'https://rubygems.org'
git_source(:github) { |repo| "https://github.com/#{repo}.git" }
ruby '3.0.2'
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails', branch: 'main'
gem 'rails', '~> 6.1.4', '>= 6.1.4.1'
# Use sqlite3 as the database for Active Record
gem 'sqlite3', '~> 1.4'
# Use Puma as the app server
gem 'puma', '~> 5.0'
# Use SCSS for stylesheets
gem 'sass-rails', '>= 6'
# Transpile app-like JavaScript. Read more: https://github.com/rails/webpacker
gem 'webpacker', '~> 5.0'
# Turbolinks makes navigating your web application faster. Read more: https://github.com/turbolinks/turbolinks
gem 'turbolinks', '~> 5'
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '~> 2.7'
# Use Redis adapter to run Action Cable in production
# gem 'redis', '~> 4.0'
# Use Active Model has_secure_password
# gem 'bcrypt', '~> 3.1.7'
# Use Active Storage variant
# gem 'image_processing', '~> 1.2'
# Reduces boot times through caching; required in config/boot.rb
gem 'bootsnap', '>= 1.4.4', require: false
group :development, :test do
# Call 'byebug' anywhere in the code to stop execution and get a debugger console
gem 'byebug', platforms: [:mri, :mingw, :x64_mingw]
end
group :development do
# Access an interactive console on exception pages or by calling 'console' anywhere in the code.
gem 'web-console', '>= 4.1.0'
# Display performance information such as SQL time and flame graphs for each request in your browser.
# Can be configured to work on production as well see: https://github.com/MiniProfiler/rack-mini-profiler/blob/master/README.md
gem 'rack-mini-profiler', '~> 2.0'
gem 'listen', '~> 3.3'
# Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
gem 'spring'
end
group :test do
# Adds support for Capybara system testing and selenium driver
gem 'capybara', '>= 3.26'
gem 'selenium-webdriver'
# Easy installation and use of web drivers to run system tests with browsers
gem 'webdrivers'
end
# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]

Related

Bundler::GemNotFound: Could not find logstash-input-jdbc-4.2.1 in any of the sources 9 (logstash,elasticsearch)

I am working with elasticsearch and im also trying to connect mysql with elasticsearch via logstash. I created the config file and when i run it i get the following error
Bundler::GemNotFound: Could not find logstash-input-jdbc-4.2.1 in any of the sources
materialize at C:/Users/esmer/E/ELK/logstash-5.5.1/vendor/bundle/jruby/1.9/gems/bundler-1.9.10/lib/bundler/spec_set.rb:92
map! at org/jruby/RubyArray.java:2446
materialize at C:/Users/esmer/E/ELK/logstash-5.5.1/vendor/bundle/jruby/1.9/gems/bundler-1.9.10/lib/bundler/spec_set.rb:85
specs at C:/Users/esmer/E/ELK/logstash-5.5.1/vendor/bundle/jruby/1.9/gems/bundler-1.9.10/lib/bundler/definition.rb:132
specs_for at C:/Users/esmer/E/ELK/logstash-5.5.1/vendor/bundle/jruby/1.9/gems/bundler-1.9.10/lib/bundler/definition.rb:177
requested_specs at C:/Users/esmer/E/ELK/logstash-5.5.1/vendor/bundle/jruby/1.9/gems/bundler-1.9.10/lib/bundler/definition.rb:166
requested_specs at C:/Users/esmer/E/ELK/logstash-5.5.1/vendor/bundle/jruby/1.9/gems/bundler-1.9.10/lib/bundler/environment.rb:18
setup at C:/Users/esmer/E/ELK/logstash-5.5.1/vendor/bundle/jruby/1.9/gems/bundler-1.9.10/lib/bundler/runtime.rb:13
setup at C:/Users/esmer/E/ELK/logstash-5.5.1/vendor/bundle/jruby/1.9/gems/bundler-1.9.10/lib/bundler.rb:122
setup! at C:/Users/esmer/E/ELK/logstash-5.5.1/lib/bootstrap/bundler.rb:67
(root) at C:\Users\esmer\E\ELK\logstash-5.5.1\lib\bootstrap\environment.rb:67code here
the config file's code is below:
input {
jdbc {
jdbc_connection_string => "jdbc:mysql://localhost:80/temperature"
jdbc_user => "admin1"
jdbc_password => ""
jdbc_driver_library => "c:\e\elk\logstash-5.5.1\lib\mysql-connector-java-5.1.43-bin.jar"
jdbc_driver_class => "com.mysql.jdbc.Driver"
statement => "SELECT * FROM temperature"
jdbc_paging_enabled => "true"
jdbc_page_size => "50000"
}
}
output {
stdout {codec => rubydebug}
elasticsearch {
hosts => "localhost:9200"
index => "temperature"
document_type => "data"
}
}
Gemfile :
# This is a Logstash generated Gemfile.
# If you modify this file manually all comments and formatting will be lost.
source "https://rubygems.org"
gem "logstash-core", :path => "./logstash-core"
gem "logstash-core-plugin-api", :path => "./logstash-core-plugin-api"
gem "paquet", "~> 0.2.0"
gem "ruby-progressbar", "~> 1.8.1"
gem "builder", "~> 3.2.2"
gem "file-dependencies", "0.1.6"
gem "ci_reporter_rspec", "1.0.0", :group => :development
gem "simplecov", :group => :development
gem "tins", "1.6", :group => :development
gem "rspec", "~> 3.1.0", :group => :development
gem "logstash-devutils", :group => :development
gem "benchmark-ips", :group => :development
gem "octokit", "3.8.0", :group => :build
gem "stud", "~> 0.0.22", :group => :build
gem "fpm", "~> 1.3.3", :group => :build
gem "rubyzip", "~> 1.1.7", :group => :build
gem "gems", "~> 0.8.3", :group => :build
gem "rack", "1.6.6"
gem "rack-test", :require => "rack/test", :group => :development
gem "flores", "~> 0.0.6", :group => :development
gem "term-ansicolor", "~> 1.3.2", :group => :development
gem "docker-api", "1.31.0", :group => :development
gem "rest-client", "1.8.0", :group => :development
gem "pleaserun", "~>0.0.28"
gem "logstash-input-heartbeat"
gem "logstash-codec-collectd"
gem "logstash-output-xmpp"
gem "logstash-codec-cef"
gem "logstash-codec-dots"
gem "logstash-codec-edn"
gem "logstash-codec-edn_lines"
gem "logstash-codec-fluent"
gem "logstash-codec-es_bulk"
gem "logstash-codec-graphite"
gem "logstash-codec-json"
gem "logstash-codec-json_lines"
gem "logstash-codec-line"
gem "logstash-codec-msgpack"
gem "logstash-codec-multiline"
gem "logstash-codec-netflow", "~> 3.4.0"
gem "logstash-codec-plain"
gem "logstash-codec-rubydebug"
gem "logstash-filter-clone"
gem "logstash-filter-csv"
gem "logstash-filter-date"
gem "logstash-filter-dns"
gem "logstash-filter-drop"
gem "logstash-filter-fingerprint"
gem "logstash-filter-geoip", "~> 4.2.0"
gem "logstash-filter-grok"
gem "logstash-filter-json"
gem "logstash-filter-kv"
gem "logstash-filter-metrics"
gem "logstash-filter-mutate"
gem "logstash-filter-ruby"
gem "logstash-filter-sleep"
gem "logstash-filter-split"
gem "logstash-filter-syslog_pri"
gem "logstash-filter-throttle"
gem "logstash-filter-urldecode"
gem "logstash-filter-useragent", "~> 3.1.0"
gem "logstash-filter-uuid"
gem "logstash-filter-xml"
gem "logstash-input-couchdb_changes"
gem "logstash-input-elasticsearch"
gem "logstash-input-exec"
gem "logstash-input-file"
gem "logstash-input-ganglia"
gem "logstash-input-gelf"
gem "logstash-input-generator"
gem "logstash-input-graphite"
gem "logstash-input-http"
gem "logstash-input-http_poller"
gem "logstash-input-imap"
gem "logstash-input-irc"
gem "logstash-input-jdbc"
gem "logstash-input-log4j"
gem "logstash-input-lumberjack"
gem "logstash-input-pipe"
gem "logstash-input-rabbitmq"
gem "logstash-input-redis"
gem "logstash-input-s3"
gem "logstash-input-snmptrap"
gem "logstash-input-sqs"
gem "logstash-input-stdin"
gem "logstash-input-syslog"
gem "logstash-input-tcp", "~> 4.1.0"
gem "logstash-input-twitter"
gem "logstash-input-udp"
gem "logstash-input-unix"
gem "logstash-input-xmpp"
gem "logstash-input-kafka", "~> 5"
gem "logstash-input-beats", "~> 3.0", ">= 3.1.18"
gem "logstash-output-cloudwatch"
gem "logstash-output-csv"
gem "logstash-output-elasticsearch"
gem "logstash-output-file"
gem "logstash-output-graphite"
gem "logstash-output-http"
gem "logstash-output-irc"
gem "logstash-output-kafka", "~> 5"
gem "logstash-output-nagios"
gem "logstash-output-null"
gem "logstash-output-pagerduty"
gem "logstash-output-pipe"
gem "logstash-output-rabbitmq"
gem "logstash-output-redis"
gem "logstash-output-s3"
gem "logstash-output-sns"
gem "logstash-output-sqs"
gem "logstash-output-statsd"
gem "logstash-output-stdout"
gem "logstash-output-tcp"
gem "logstash-output-udp"
gem "logstash-output-webhdfs"
gem "logstash-filter-dissect"
gem "logstash-input-dead_letter_queue"
I have tried bundle install and also tried to change the PATH but it doesnt recognise it as internal variable, don't know how to fix this.
Any suggestions ?
Thank you.
First you must install the logstash input plugin by running
bin/logstash-plugin install logstash-input-jdbc
And also If it does not help,
try
Java::com.mysql.jdbc.Driver
instead of the
com.mysql.jdbc.Driver
for the jdbc_driver_class. I had a same kind of problem with oracle when I did not use the
Java::
before the oracle.jdbc.OracleDriver as the jdbc_driver_class.

Sequel::AdapterNotFound: LoadError: cannot load such file -- mysql

When I am trying to migrate files using command prompt:
sequel -m db/migrations/ mysql://root:root#localhost/todo
I get the following error:
Error: Sequel::AdapterNotFound: LoadError: cannot load such file --
mysql
C:/Ruby24-x64/lib/ruby/2.4.0/rubygems/core_ext/kernel_require.rb:55:in
`require'
Below is my migration file in db/migrations:
Sequel.migration do
change do
create_table :users do
primary_key :id
String :name, :unique => true, :length => 32, :null => false
String :password, :length => 32, :null => false
DateTime :created_at
end
end
end
My gemfile:
> GEM remote: https://rubygems.org/ specs:
> rack (2.0.3)
> rack-protection (2.0.0)
> rack
> sinatra (2.0.0)
> rack (~> 1.4)
> rack-protection (~> 1.4)
> tilt (~> 1.3, >= 1.3.4)
> tilt (2.0.7)
>
> PLATFORMS x64-mingw32
>
> DEPENDENCIES bundler (= 1.15.1) sinatra (= 2.0.0)
>
> BUNDLED WITH
> 1.15.1
You have to use the mysql2 adapter for your connection string. That also means you have to install the mysql2 gem on your machine. Make sure you have the MySQL development package on your machine and build essentials since this gem is a native extension and has dependencies outside Ruby.
Then connect via:
sequel -m db/migrations/ mysql2://root:root#localhost/todo

mysql Databases how can I fix this?

Hi Im trying to set up a database to store emails using ruby, sinatra, ActiveRecord, and mysql. Any suggestions on what im doing wrong? Im trying to output it to a seperate page that only i can see and then post it using a url on hostgator.
require 'sinatra'
require 'activerecord'
# require 'sinatra-activerecord'
get '/' do
erb :index
end
def save_email (email)
file.print(email)
end
get '/email' do
params[:email]
# # redirect '/'
end
post '/email' do
params[:email]
#email = params[:email]
erb :email, :locals => {:email => params[:email]}
end
# Change the following to reflect your database settings
ActiveRecord::Base.establish_connection(
adapter: 'mysql', # or 'postgresql'
host: 'localhost',
database: 'Stored_Emails',
)
class Stored_Emails < Sinatra::Application
end
class Stored_Emails < ActiveRecord::Base
end
ActiveRecord::Migration.create_table :email do |t|
t.string :emails
end
create_table :emails, force: true do |t|
t.string :email
t.belongs_to :email, index: true
end
get '/email' do
params[:email].all
end
Typically you break out your code into multiple files (we use folders named config, helpers, libraries, views, routes, models, migrations) and require them at the top of your app. However, if you want to put it in the same file and just use that and a Gemfile and Gemfile.lock that'll work too. Here's how it might look:
# Require your gems
require 'sinatra'
require 'activerecord'
# Libraries
# Models
class Stored_Emails < ActiveRecord::Base
end
# Configuration
# Change the following to reflect your database settings
ActiveRecord::Base.establish_connection(
adapter: 'mysql', # or 'postgresql'
host: 'localhost',
database: 'Stored_Emails'
)
ActiveRecord::Migration.create_table :email do |t|
t.string :emails
end
# Migrations
create_table :emails, force: true do |t|
t.string :email
end
# Helpers
def save_email (email)
file.print(email)
end
# Routes
get '/' do
# Load whatever you want to show in your index page into class variables
erb :index
end
get '/email' do
Stored_Emails.all.to_json
end
post '/email' do
#email = Stored_Emails.find_by(params[:email])
erb :email
end
Now you're going to have to do a good bit of work to get this running. Here's what I suggest you read:
1) Sinatra documentation - http://www.sinatrarb.com/intro.html
routes
running your sinatra app
views with ERB
2) Bundler documentation for gems - http://bundler.io/
3) ActiveRecord documentation - http://guides.rubyonrails.org/active_record_basics.html
Connecting to a database Creating your database with a migration -
this is a one time deal Querying the database
Good Luck!

Why are my json attributes bouncing off in POST in Sinatra?

I hope someone can share their knowledge with me. I have a small Sinatra app that I want to POST json data to it. The record is being created, thankfully, but none of the attributes make it. I've read several JSON examples using curl but they all yield the same result. So it makes me think it's my model. I can create records using tux fine so perhaps it's not my model.
curl command:
curl -XPOST -H "Content-Type: application/json"
"localhost:4567/date" -d
'{ "post": { "title": "different tile here"}}'
curl output:
=> {"id":13,"title":null,"body":null,"created_at":"2014-04-21T18:13:53Z",
"updated_at":"2014-04-21T18:13:53Z"}
sinatra output:
[2014-04-27T20:03:48.035710 #45360] DEBUG -- : (0.1ms) commit transaction
127.0.0.1 - - [27/Apr/2014 20:03:48] "POST /date HTTP/1.1" 200 - 0.0181
{"post":{"title":"different tile here"}}
D, [2014-04-27T20:09:32.614274 #45360] DEBUG -- : (0.1ms) begin transaction
D, [2014-04-27T20:09:32.615917 #45360] DEBUG -- : SQL (0.4ms) INSERT INTO "posts" ("created_at", "updated_at") VALUES (?, ?) [["created_at", 2014-04-28 01:09:32 UTC], ["updated_at", 2014-04-28 01:09:32 UTC]]
D, [2014-04-27T20:09:32.617656 #45360] DEBUG -- : (1.5ms) commit transaction
D, [2014-04-27T20:09:32.617852 #45360] DEBUG -- : (0.1ms) begin transaction
D, [2014-04-27T20:09:32.618132 #45360] DEBUG -- : (0.0ms) commit transaction
127.0.0.1 - - [27/Apr/2014 20:09:32] "POST /date HTTP/1.1" 200 - 0.0070
D, [2014-04-27T20:09:57.796909 #45360] DEBUG -- : Post Load (0.3ms) SELECT "posts".* FROM "posts" ORDER BY created_at DESC
127.0.0.1 - - [27/Apr/2014 20:09:57] "GET / HTTP/1.1" 200 2149 0.0128
app.rb
require 'sinatra'
require 'sinatra/activerecord'
require './environments'
require 'sinatra/flash'
require 'sinatra/redirect_with_flash'
require 'json'
class Post < ActiveRecord::Base
end
post "/posts" do
#post = Post.new(params[:post])
if #post.save
redirect "posts/#{#post.id}"
else
erb :"posts/create"
end
end
post '/date', :provides => 'json' do
data = JSON.parse(request.body.read)
json_data = data.to_json
content_type :json
##post = Post.new(params)
#post = Post.create(
title: data[:title]
body: data[:body]
)
if #post.save
#post.to_json
else
halt 500
end
end
get "/posts/create" do
#title = "Create post"
#post = Post.new
erb :"posts/create"
end
get "/posts/:id" do
#post = Post.find(params[:id])
#title = #post.title
erb :"posts/view"
end
get "/" do
#posts = Post.order("created_at DESC")
#title = "Welcome."
erb :"posts/index"
end
Gemfile
source 'https://rubygems.org'
ruby "2.0.0"
gem "sinatra"
gem 'activerecord', '4.0.4'
gem "sinatra-activerecord"
gem 'sinatra-flash'
gem 'sinatra-redirect-with-flash'
gem 'json'
group :development do
gem 'sqlite3'
gem "tux"
end
group :production do
gem 'pg'
end
environments.rb
configure :development do
set :database, 'sqlite3:///dev.db'
set :show_exceptions, true
end
configure :production do
db = URI.parse(ENV['DATABASE_URL'] || 'postgres:///localhost/mydb')
ActiveRecord::Base.establish_connection(
adapter: db.scheme == 'postgres' ? 'postgresql' : db.scheme,
host: db.host,
username: db.user,
password: db.password,
database: db.path[1..-1],
encoding: 'utf9'
)
end
I've left off my layout files since I'm testing this POST via this rudimentary API. I've bounced around the few examples of Sinatra API's on the web and don't know what I'm not seeing. What am I overlooking here? It's almost like Strong Parameters in Rails 4, but if so why does tux allow me to create records? thanx, sam

Issues while connecting to mysql using ruby

require 'rubygems'
require 'mysql'
db = Mysql.connect('localhost', 'root', '', 'mohit')
//db.rb:4: undefined method `connect' for Mysql:Class (NoMethodError)
//undefined method `real_connect' for Mysql:Class (NoMethodError)
db.query("CREATE TABLE people ( id integer primary key, name varchar(50), age integer)")
db.query("INSERT INTO people (name, age) VALUES('Chris', 25)")
begin
query = db.query('SELECT * FROM people')
puts "There were #{query.num_rows} rows returned"
query.each_hash do |h|
puts h.inspect
end
rescue
puts db.errno
puts db.error
end
error i am geting is:
undefined method `connect' for Mysql:Class (NoMethodError)
OR
undefined method `real_connect' for Mysql:Class (NoMethodError)
EDIT
return value of Mysql.methods
["private_class_method", "inspect", "name", "tap", "clone", "public_methods", "object_id", "__send__", "method_defined?", "instance_variable_defined?", "equal?", "freeze", "extend", "send", "const_defined?", "methods", "ancestors", "module_eval", "instance_method", "hash", "autoload?", "dup", "to_enum", "instance_methods", "public_method_defined?", "instance_variables", "class_variable_defined?", "eql?", "constants", "id", "instance_eval", "singleton_methods", "module_exec", "const_missing", "taint", "instance_variable_get", "frozen?", "enum_for", "private_method_defined?", "public_instance_methods", "display", "instance_of?", "superclass", "method", "to_a", "included_modules", "const_get", "instance_exec", "type", "<", "protected_methods", "<=>", "class_eval", "==", "class_variables", ">", "===", "instance_variable_set", "protected_instance_methods", "protected_method_defined?", "respond_to?", "kind_of?", ">=", "public_class_method", "to_s", "<=", "const_set", "allocate", "class", "new", "private_methods", "=~", "tainted?", "__id__", "class_exec", "autoload", "untaint", "nil?", "private_instance_methods", "include?", "is_a?"]
return value of Mysql.methods(false)
is []... blank array
EDIT2
mysql.rb file
# support multiple ruby version (fat binaries under windows)
begin
require 'mysql_api'
rescue LoadError
if RUBY_PLATFORM =~ /mingw|mswin/ then
RUBY_VERSION =~ /(\d+.\d+)/
require "#{$1}/mysql_api"
end
end
# define version string to be used internally for the Gem by Hoe.
class Mysql
module GemVersion
VERSION = '2.8.1'
end
end
I had this same problem and solved this way:
make sure you have installed only the gem ruby-mysql
and not the gem mysql. For me, now:
$ gem list --local | grep mysql
ruby-mysql (2.9.2)
If that is not the case, uninstall
$ sudo gem uninstall mysql
(I uninstalled every gem with mysql in its name)
and then reinstalled ruby-mysql.
In my case, because I have mysql installed in a usb disk
the installation command was:
sudo env ARCHFLAGS="-arch i386" gem install ruby-mysql --
--with-mysql-config=/Volumes/usb/opt/bin/osx/mysql/bin/mysql_config
--with-mysql-lib=/Volumes/usb/opt/bin/osx/mysql/lib/
--with-mysql-dir=/Volumes/usb/opt/bin/osx/mysql
(and I was using the 32bits binary for MacOs, don't know if that applies for you)
Finally, my ruby test program was
require 'rubygems'
require 'mysql'
dbh = Mysql.real_connect('localhost', 'root', 'your password', 'TEST')
res = dbh.query("select * from Persons;");
puts res.class
res.each do |row|
puts row.join(" ")
end
Short answer:
Remove mysql-ruby
Rebuild mysql-ruby
Reinstall mysql-ruby.
Alternative answer
Remove mysql-ruby
Install ruby-mysqlThe pure ruby MySQL protocol client.
Longer Explanation:
This just happened to me. My 2.8.1 mysql-ruby bindings had been built against libmysqlclient.so.15, and worked fine until I upgraded my MySQL installation and replaced that client library with .so.16. Rebuild resolved this issue.
The 3rd-party gem you used (I used it, too) introduces faulty logic in the mysql.rb file it supplies to trap an error on Windows systems. Notice that in the excerpt you posted, that this mysql.rb file does not re-raise the LoadError on non-Windows platforms. Bummer.
Edit
I contacted the gemspec author, and he has corrected the error! (2010-05-25) With luck no one else will be baffled by this silent failure.