undefined method `create_db' for #<Mysql:0x000000018f2590> (NoMethodError) - ruby

#!/usr/local/bin/ruby
require 'mysql'
db=Mysql.new '127.0.0.1','root','123456'
db.create_db 'testdb'
error message:
test.rb:5:in `<main>': undefined method `create_db' for #<Mysql:0x000000015d0ab0> (NoMethodError)
What's wrong?

Though it is still in the API, create_db cannot be used since mysql4.1.
This function is deprecated. It is preferable to use mysql_query() to
issue an SQL CREATE DATABASE statement instead.
Therefore you need to use query as
require 'mysql'
db = Mysql::new('127.0.0.1','root','123456')
db.query("create database testdb;");
db.close

Related

Minitest: NoMethodError: undefined method `split' for nil:NilClass

This is my test:
test 'accepts nil first_name' do
user = User.new(first_name: nil)
assert_equal(nil, user.first_name)
end
When I run it, I am getting this error from minitest:
NoMethodError: undefined method `split' for nil:NilClass
I can create the user manually in the console and it works, so I'm pretty sure the test should be passing.
Where is this nil.split coming from? My code does not use split anywhere.
Change this:
assert_equal(nil, user.first_name)
To this:
assert_nil(user.first_name)
I didn't dig down the stack deep enough to figure out what was being split where, but this fixed the problem.

uninitialized constant Neo4j::Session (NameError)

Reading the instructions contained in the address https://neo4j.com/developer/ruby/ I built the following code:
require 'neo4j'
session = Neo4j::Session.open(
:server_db,
"http://neo4j:password#localhost:7687"
)
I have this error:
uninitialized constant Neo4j::Session (NameError).
I don't understand if it is necessary to instantiate Neo4j or if it is necessary to redefine Session. Do you have any suggestions?

NoMethodError - undefined method `now' for Watir::Time:Class

I get the following error anytime I try to interact with a Watir element.
/Library/Ruby/Gems/2.0.0/gems/watir-6.0.1/lib/watir/wait/timer.rb:40:in `current_time': undefined method `now' for Watir::Time:Class (NoMethodError)
from /Library/Ruby/Gems/2.0.0/gems/watir-6.0.1/lib/watir/wait/timer.rb:6:in `initialize'
from /Library/Ruby/Gems/2.0.0/gems/watir-6.0.1/lib/watir/elements/element.rb:656:in `new'
from /Library/Ruby/Gems/2.0.0/gems/watir-6.0.1/lib/watir/elements/element.rb:656:in `element_call'
from /Library/Ruby/Gems/2.0.0/gems/watir-6.0.1/lib/watir/elements/element.rb:114:in `click'
from fund_cc.rb:8:in `<main>'
Here is my code:
require 'watir'
# require 'time'
b = Watir::Browser.new(:chrome)#, :url => "http://localhost:9515")
b.goto "https://www.bankofamerica.com/"
contact_us= b.link(:text, "Contact Us")
contact_us.click
Does anyone know how to resolve this?
This should be fixed in version 6.0.2.
From Titus Fortner on the Watir-General mailing list:
The latest version of Watir attempts to use monotomic time where
supported and it looks like we grabbed the wrong Time class for where
it is not supported.
I just updated and pushed the fix to 6.0.2. You should be able to just
bundle update now.
I was able to reproduce this behavior. You can monkey patch your gem locally by tweaking the current_time method in /lib/watir/wait/timer.rb:
def current_time
::Time.now.to_f # was Time.now.to_f
end
And I'd suggest logging an issue on https://github.com/watir/watir/issues.

Set capybara default_wait_time to a function

I made a function called wait_for_page load, and I am trying to set the default_wait_time to this function.
I get an undefined variable error:
undefined local variable or method `page' for main:Object (NameError)
I also included the file into the main environment file:
require File.expand_path('../../support/file_name.rb', FILE)
default_wait_time is an accessor in Capybara module. So you'll need to call it on the Capybara object itself, like:
Capybara.default_wait_time = some_value
And Capybara object should be available wherever you have defined this method.
In some newer versions accessor is default_max_wait_time, you can notice this because of a DEPRECATION warning
So you need to do this:
Capybara.default_max_wait_time = 5
The default is 2 seconds

undefined method `[]' for nil:NilClass (NoMethodError)

i am using sequel gem and postgresql database
i have a file hello.rb with code
require "rubygems"
require './post'
require "sequel"
# connect to an in-memory database
DB = Sequel.connect('postgres://ritesh:newpassword#localhost')
post = Post['ruby1', 'hello world1']
post[1]
and i created a table post and
a model with code
require 'sequel'
DB = Sequel.connect('postgres://ritesh:newpassword#localhost')
class Post < Sequel::Model
set_primary_key [:category, :title]
end
when i run command ruby hello.rb .i am getting the following error
hello.rb:10: undefined method `[]' for nil:NilClass (NoMethodError)
first thing i want to know for creating we should create a table with that name and then create a model??
second thing if first assumption is true then why i am getting this error??
To construct a new object in ruby you should call new. I am not sure what is post but it seems the correct syntax should be:
post = Post.new('ruby1', 'hello world1')
Otherwise post will remain null after this line.

Resources