Know of a way to mock %[]? I'm writing tests for code that makes a few system calls, for example:
def log(file)
%x[git log #{file}]
end
and would like to avoid actually executing system calls while testing this method. Ideally I'd like to mock %x[..] and assert that the correct shell command is passed to it.
...
I have the following migration and I want to be able to check if the current database related to the environment is a mysql database. If it's mysql then I want to execute the SQL that is specific to the database.
How do I go about this?
class AddUsersFb < ActiveRecord::Migration
def self.up
add_column :users, :fb_user_id, :int...
I'm trying to split a sizeable string every four characters. This is how I'm trying to do it:
big_string.split(/..../)
This is yielding a nil array. As far as I can see, this should be working. It even does when I plug it into an online ruby regex test.
...
With the Ruby 1.9.2 release on the horizon, it's time to get developers excited about Ruby 1.9. What are some nice things you can do in Ruby 1.9 that you can't do in Ruby 1.8?
...
I want to save to a log file some SQL query rails performs, (namely the CREATE, UPDATE and DELETE ones)
therefore I need to intercept all queries and then filter them maybe with some regexp and log them as needed.
Where would I put such a thing in the rails code?
...
I've missed the memo somewhere, and I hope you'll explain this to me.
Why is the eigenclass of an object different from self.class?
class Foo
def initialize(symbol)
eigenclass = class << self
self
end
eigenclass.class_eval do
attr_accessor symbol
end
end
end
My train of logic that equates the eigenclas...
Does anybody know which version of RubyCocoa runs on this processor (if at all)?
...
I have following code
class User
attr_accessor :name
end
u = User.new
u.name = 'john'
puts u.name #=> john
In the above case everything works. However this code does not work
class User
attr_accessor :name
end
u = User.new
u.name = 'john'
u.name('john')
In order to fix that issue, I have decided to use alias_method. I know th...
Hi guys,
I have to debug some error that is db related and have been continuously monitoring the log when there is an error caused by db. Since the error is already logged, I want to have exceptions like:
ActiveRecord::StatementInvalid
to be suppressed so that user won't see the 'something went wrong page'. The error is limited to a s...
What is the best solution to programmatically take a snapshot of a webpage?
The situation is this: I would like to crawl a bunch of webpages and take thumbnail snapshots of them periodically, say once every few months, without having to manually go to each one. I would also like to be able to take jpg/png snapshots of websites that mi...
How feasible is it to translate this Ruby websocket server to PHP?
http://github.com/gimite/web-socket-ruby/blob/master/lib/web_socket.rb
I know a little bit of Ruby and a decent amount of PHP, thought I've never done socket programming. I'd like to build a chat app on top of what gimite has put up on git, but all my sites are in PHP. ...
is there some ruby code I can use to install a gem from a local file, if that gem is not installed?
i'm thinking it would look something like:
if !gem_installed("some gem name")
system "gem install -l local_copy.gem"
end
i don't know if anything exists that lets me check for gems like this or not...
...
I want to go through the children of an element and filter only the ones that are text or span, something like:
element.children.select {|child|
child.class == String || child.element_type == 'span'
}
but I can't find a way to test which type a certain element is. How do I test that? I'd like to know that regardless if there's a bet...
Hello Stackies,
I'm deploying a Sinatra app using passenger. The deployed app is working, but not entirely: some paths work fine, others simply render a blank page. I can't seem to find any major differences between the routes that work and the routes that don't, and I can't seem to track down any errors..
Handlers
I have defined the ...
what does this error mean ??
i ran
script.rb apples
and i get
:1: script.rb:91: , unexpected '\n' (SyntaxError)
...
I want to insert the following as the value for a variable in some Ruby:
`~!@#$%^&*()_-+={}|[]\:";'<>?,./
Surrounding this in double quotes doesn't work, so is there a nice escape_until_the_end sort of thing available?
...
Hey peeps.
I am a beginner-verging-on-intermediate rails developer that is working hard to improve my skills.
I am a little confused about the state of JRuby, and whether it is a viable alternative to switch to from the MRI.
Currently I run a Mac at home and edit using textedit (MRI for ruby, terminal for rails commands, etc). At w...
I have an issue that seems like very flaky behavour, is this a problem with Ruby or something I've done? Please help - my project is stalled until I resolve this.
Given this code running on Mac OS Leopard:
require 'uri'
require 'net/ssh'
require 'net/sftp'
include Net
def copy_from_uri( uri, local_path )
# SFTP copy
SFTP.start...
Say, I've got a class definition,
class A; a = 1; end
How could get the value of 'a' outside of A?
I've tried:
eval 'p a', A.send(:binding)
failed, said:
NameError: undefined local variable or method `a' for A:Class
from (irb):2:in `send'
from (irb):2
from :0
...
what is the ruby function to remove all white spaces ? kinda like php's trim() ?
...