how to mock `backticks operator` in your test specs using RR
July 5th, 2010
I was working on tests for blender when I came upon a need to mock or stub a back-tick operator e.g. `shell command`.
Apparently this is just a shortcut for calling Kernel method :`.
So the mocking should probably be easier with Rspec mocks or mocha. something like that (didn’t test see below):
@obj.should_receive(:`, "shell command").and_return("....")
But the problem was that I’m using RR. And RR uses a much more succinct and easy to use syntax but in this particular case it was a problem. Consider this:
# This doesn't work. it stubs the :send, not the :`
stub(@obj).send(:`, "shell command") { "...." }
RR has an instance_eval syntax, but with it I don’t know how to pass a block to the back-ticks call:
stub(@obj) do
`shell command` { "...." } # invalid syntax here ;).
end
So after some digging inside RR’s sources I got the following working:
stub(@obj).
__double_definition_create__.
call(:`, "shell command") { "...." }
Open 2010 Conference
June 16th, 2010
The OPEN 2010 conference was very well organized and had many interesting talks.
The side of low level, infrastructure things was presented by people from Red Hat, VMWare and IBM. The buzz words “SaaS”, “PaaS” and the likes were all over the place together with recent hot topic of virtualization.
On the application level there were interesting presentations about Django, PostgreSQL. And of course our own presentations on Ruby, Rails, NoSQL along with a longer, 2 hours “Introduction to Ruby” workshop.
The food was great too. That’s important.
We uploaded our slides with english transcription for some of them on the “we speak” page.
Read the rest of this entryopen 2010 tomorrow and we are there big time
June 9th, 2010
We are giving 4 out of 20 sessions at Open 2010, an Israeli open source conference.
Michael is giving the last keynote and me and Boris will be opening 2 of the 3 tracks: open startup and open enterprise.
I’m going to talk about “NoSQL, when, why, and how” and Boris is giving an introduction to Rails, web development that doesn’t hurt.
After the tracks we will also have a long 2 hour Ruby and Rails workshop.
See you there ;)
P.S. btw, Astrails is sponsoring this event together with a couple of smaller companies like IBM, Red Hat and VMWare :)
P.P.S. Big thanks goes to Raphael Fogel and People&Computers for organizing the whole thing.
installing mysql gem on Snow Leopard
May 21st, 2010
I just recently reinstalled my MacBook Pro, this time with Snow Leopard. So I’m again going through various installation problems I already forgot about from few years back when I installed Leopard.
Anyway, just had to hunt down a problem with mysql gem installation on Snow Leopard.
Apparently if you just do ‘gem install mysql’ it seems to install fine, but doesn’t work.
You get “uninitialized constant MysqlCompat::MysqlRes” error when trying to run rails.
The solution is to pass it some arguments for installation:
ARCHFLAGS="-arch x86_64" gem install mysql -- --with-mysql-config=/usr/local/mysql/bin/mysql_config
Oh, and of course install 64bit mysql version before that. I usually just download the binaries from mysql.com.
Ruby is Better then Lisp (sometimes)
May 20th, 2010
A few days ago I gave a presentation about Ruby for Sayeret Lambda discussion group.
The title was “Ruby is an acceptable lisp” but the message is better served by “Ruby is Better then Lisp … sometimes” :)
The presentation slides are now online:The html version is just an export from Keynote so nothing fancy, it only knows how to move forward :) Some slides are bigger, so don’t click again if it seems that its stuck (you will have to refresh to go back), just wait a little.
SmallRecord - Simple Object persistency library for Cassandra
April 13th, 2010
Simple Object persistency library for Cassandra
- Home: http://astrails.com/smallrecord
- Code: http://github.com/astrails/smallrecord
- Blog: http://blog.astrails.com/smallrecord
Motivation & History (you can skip it :)
I was developing an multiplayer online game for a client (TBD: link when released :) and we decided to use Cassandra for performance and scaling benefits. Also the game’s internal data structures mapped very well to key-value semantics.
I did some research but couldn’t find anything that was Ready at the time to be used for development.
Read the rest of this entryIsrael Ruby Group Meeting - Mar 2010
March 22nd, 2010
About a week ago about 15 people were gathered in People and Computers offices thanks to Raphael Fogel.
Jerry Cheung, nice guy from Outspokes, told everyone how Outspokes was built from the inside and shared his view on building javascript intensive application with Rails as a backend.
Outspokes uses fancy javascript to allow in-browser collaboration of development/design/client teams to request changes, track progress and report problems on ongoing project. I definitely will try it out.
Boris Nadion from Astrails (that’s us in case you were wondering) told the story of our own MarkupSlicer - free to use project we wrote to simplify creating ERB/HAML layouts and partials out of HTML markup we get from our slicing team.
Vitaly Kushner, also from Astrails, made a nice intro presenation about Cassandra - our choice of NoSQL breed. We working with yet to be disclosed client on very technologically challenging project and cassandra is one of many interesting solutions we working with (You can expect a case study on this project in couple of months, as soon as it will go public).
Read the rest of this entryThere is no magic, indeed.
January 14th, 2010
I’ve just read ”Do You Believe In Magic?” and the following quote resonated particularly well:
“It’s not magic. There is no magic involved. It’s just, if you never learnt Lisp, then you never learned to program, and Ruby’s power is exposing a deficiency in your skills.”
I find it to be very true, and I suppose one of the reasons I’m so happy about Ruby is that I learned Lisp and Scheme before.
Even though I didn’t use Lisp for any sizable project. I tried, but I found it to be quite unfriendly and ‘hairy’ in setup, environment and library support. Ruby solved all that for me w/o sacrificing almost anything power vise.
astrails-safe-0.2.4 - dry run fix, move to gemcutter
October 9th, 2009
Since Github stopped to build gems we are moving to the gemcutter.
Changes in 0.2.4 since 0.2.2:
- fixed couple of README errors (thanks Bobby Wilson)
- changed name from ‘safe’ to ‘astrails-safe’ due to the move to gemcutter
- added missing net-sftp dependency to the gemspec.
- fixed bug where it would crash in a dry-run since local storage didn’t update some internal variables.
To install the latest version:
gem install astrails-safe --source http://gemcutter.org
astrails-safe-0.2.2 - sftp, timing + another rotation bugfix
October 9th, 2009
Damn, I just found this unpublished article in the blog admin…
How come it evaded my attention for 3 months??!!
Anyway, releasing it now thought this is all quite old news, going to announce 0.2.4 in a moment :)
There is a new 0.2.2 version of astrails-safe on github.
If you don’t know it yet astrails-safe is an easy to use backup solution for Unix like operating systems. It supports filesystem, mysql, postgresql, subversion backups to local filesytem, Amazon S3 and remote SFTP.
Read the rest of this entryAstrails-safe: 0.1.9 - BUGFIX release
May 22nd, 2009
I just pushed new version 0.1.9 of astrails-safe to github.
The main difference is a fix to an embarrassing bug in the S3 backup rotation code. Thanks to Thuvarakan Tharmalingam for reporting.
Again, the reason it escaped was the fact that we don't yet have full test coverage. We are getting there though....
It looks like our astrails-safe gem is quite popular :). People started to contribute new features:
- Mark Mansour contributed PostgreSQL backup support
- Richard Luther contributed Subversion repository dump support
I just released new version 0.1.8 on the github.
In addition to postgre/svn support this release also includes a long overdue test suite.
Read the rest of this entryImporting Mephisto comments into Disqus
May 20th, 2009
Mephisto commenting system is… how do i put it … outdated :)
And we wanted something more engaging for our blog. Looking around the web we found that Disqus was used all over the place, so we decided to integrate it into our blog instead of the native comments system.
Read the rest of this entryYes We Can. "require" over HTTP, That Is.
May 12th, 2009
Wouldn’t it be cool if you could just require “http://my-host/my-lib.rb” in ruby?
Now You Can! Using our “http_require” gem! :-)
test.rb:
require "http_require"
# this will download bar.rb and eval it
require "http://example.com/foo/bar.rb"
If a remote file (or one of its local dependencies) requires something that can’t be found locally, it will try to find it remotely from the same location as the parent.
Example
http://example.com/test/foo.rb:
# this will load "http://example.com/test/foo/bar.rb"
# if "foo/bar" is not available locally
require "foo/bar"
Stacktrace
http_require properly sets filename on eval so that the file’s URI appears in the stacktrace:
http://example.com/foo/foo.rb:
puts :foo
require 'bar'
def foo
bar
end
http://example.com/foo/bar.rb
puts :bar
def bar
raise
end
$ irb
>> require 'http_require'
=> true
>> require 'http://example.com/foo/bar.rb'
foo
bar
=> nil
>> foo
RuntimeError:
from http://localhost:2000/bar.rb:3:in `bar'
from http://localhost:2000/foo.rb:5:in `foo'
from (irb):3
>>
Installation
sudo gem install astrails-http_require --source http://gems.github.com/
Sources
You can find sources on github
UPDATE:
There seems to be lots of similar comments that I’d like to answer here:
- Q: This is a HUGE security hole
A: No it isn’t. running it directly from the web is no less secure then downloading it and then running locally. you can use same security protections, for example SSH tunnel, or SSL like you would for any other kind of ‘code delivery’ e.g. rsync, scp etc. If you control the source and the ‘tunnel’ then this is no less secure, and if you don’t, then no other method is secure unless you start encrypting/signing files.
Q: Why on earth would you do something crazy like this?
- A: It is kind of cool :) Seriously though I do have a real usage in mind for this (more on that later), meanwhile consider rails app templates (rails -m app_template.rb) which do support running templates form the web, and no one seems to be crying out laud about a huge security hole :) Unfortunately though rails templates do not support (not out of the box) breaking down such remote templates into subfiles. you will need to do manual path mangeling (see app_lego for example). I guess http_require can be used to do it cleaner.
RRDtool and Ruby bindings on OSX Leopard
April 1st, 2009
RRDtool is the OpenSource industry standard, high performance data logging and graphing system for time series data. Use it to write your custom monitoring shell scripts or create whole applications using its Perl, Python, Ruby, TCL or PHP bindings.
Let’s run it with Ruby on Leopard.
Read the rest of this entry