ruby

How to visualize Hash data structure in ruby?

I have hash object, that structure looks similar to this: {:category1 => {:subcategory1 => [ {:article => "some article", :date => "2010-04-04"}, ... ], :subc2 => [...] }, :category2 => {...}, ... } How can I visualize it with graph in ruby? Is there a simple method/gem/lib that convert this Hash to DOT? ...

Cucumber and Images

I got a problem with Cucumber. I don't know kow to say to Cucumber that "he" has to click on a picture and then see some text...like I do with buttons or links. When I click on a picture, I have to see the text "USER OK" in the screen. How can I do that? ...

Cucumber,Capybara and ElementNotFound

In my rails application, I have a page with a link that execute a javascript function : <%= link_to_function("Add an address", "add_fields(this)".html_safe) %> In my cucumber feature I have : And I press "Add an address" And the message I get is : Capybara::ElementNotFound: no button with value or id or text 'Add an address' fou...

Rspec: How to test recursion?

I'd like to test that a method is called recursively with a specific argument. My approach: class Recursable def rec(arg) rec(7) unless arg == 7 end end describe Recursable do it "should recurse" do r = Recursable.new('test') r.should_receive(:rec).with(0).ordered r.should_receive(:rec).with(7).ordered r.rec(...

Constructing string with values from hash in Ruby

Suppose I have the hash{ "a" => "b", "c" => "d" } and I would like to transform it into the string "a=b\nc=d". The solution I've come up with so far is { "a" => "b", "c" => "d" }.map { |k, v| k + "=" + v }.join("\n") Is there a better/more elegant way? For example, can it be done using a single method call? ...

ruby 1.9.2 strange warning when running cucumber specs

Hi, I just updated to use rails 3 and tried my first project with rails 3. When I run my cucumber specs then I get following strange warnings /home/ubuntu/.rvm/gems/ruby-1.9.2-p0/gems/rack-1.2.1/lib/rack/utils.rb:16: warning: regexp match /.../n against to UTF-8 string /home/ubuntu/.rvm/gems/ruby-1.9.2-p0/gems/rack-1.2.1/lib/rack/uti...

RSpec Mock Object Example

I am new to mock objects, and I am trying to learn how to use them in RSpec. Can someone please post an example (a hello RSpec Mock object world type example), or a link (or any other reference) on how to use the RSpec mock object api? ...

Python programmer: Learning ruby (for rails)

I'm a moderately competent Python programmer, and am considering working on my first web-app; it seems a very large number of FOSS webapp code is written in Ruby (i.e. Rails), and I suspect that might help with my learning curve (i.e. for building a decent, if useless webapp). There is lots of material for learning Ruby on the interwebs...

String iteration using each_line

I have the following code which displays instructions in an ordered list. When it's rendered in the browser, it outputs all of the instructions at the end in a single line. Am I doing something wrong? See output below for example. Code: <% @recipe.instructions.each_line do |instruction| %> <li><%= instruction %></li> <% end %> Out...

How can I use Ruby to parse through XML easily to query and find certain tag values?

I am working with an API and want to know how I can easily search and display/format the output based on the tags. For example, here is the page with the API and examples of the XML OUtput: http://developer.linkedin.com/docs/DOC-1191 I want to be able to treat each record as an object, such as User.first-name User.last-name so that I ...

How do I upgrade my Ruby version in Windows using Instant Rails?

If I'm using Instant Rails, how do I upgrade my Ruby version from 1.8.6 to 1.9.* which they say runs faster in Windows? What's the necessary Instant Rails console command? Thanks. ...

Issues with link on Watir and Safari?

Hi there, I am new in using watir but I can only imagine this to be a bug: require "watir" Watir::Browser.default = 'safari' b = Watir::Browser.new b.goto() => nil b.link(:title, "Start").click Leads me to the next page as expected but on the following page no link works even they are there b....

How can I pass a hash into a class_eval'ed method with Ruby 1.8.7?

Hi, I'm trying to mock the OpenID handling in my cucumber tests. For this purpose I use the following method: def set_result_of_openid_authentication(result_type, profile_data = nil) ActionController::Base.class_eval " def begin_open_id_authentication(identity_url, options = {}) yield [OpenIdAuthentication::Result.new('#{re...

Installing ruby on CentOS

Hai. I am trying to install What's Next GTD on my CentOS machine. The app requires sqlite3-ruby installed. So i tried installing ruby first. Unfortunately, the yum installation says : "No package ruby available". Yes i know there are similar topics which already discussed this. One of them was this. So i tried what was discussed back th...

Using Struct with Rails

Hi, I came across this messaging tutorial recently, and was intrigued by the use of Struct.new. With a bit of help from google and SO I've learnt a bit more about the use of Struct in Ruby, but I would like to know a bit more about its use in Rails. In the tutorial, there is a folder model which stores the user's recieved messages: cla...

Remove array inside hash

My orginal hash is like as hash = {"sku_id"=>[4], "brand_active"=>["true"], "salesman_active"=>["true"]} How to remove the array within hash. that means to convert the hash like {"sku_id"=>4, "brand_active"=>"true", "salesman_active"=>"true"} ...

Heroku gem not working with RVM

I'm following the Ruby on Rails tutorial at http://railstutorial.org/chapters/beginning#sec:1.4.1, and all is going well until I tried to get my app going on Heroku. I installed heroku, that worked fine, but now when I run heroku keys:add or any other heroku command, I get the following error: /home/sirswap/.rvm/gems/ruby-1.9.2-p0@rail...

ruby gems under rvm on Ubuntu (failing to) install in the wrong location

I'm running Ubuntu 10.04 and originally installed ruby 1.9.1 (from source). I've just decided to try out ruby 1.9.2 and rails 3, and it seemed like a good time to use rvm to deal with the multiple ruby installs and gemsets. rvm installed and seems to be working, I installed ruby 1.9.2 in rvm and made that my default ruby. However, ev...

Is it possible to open a new tab in watir-webdriver?

The only thing that looks a bit like what I'm trying to achieve is this, but this works only for IE... for firefox I found that information, so is it not possible to open tabs, just new windows? And the attach method is accessing only already OPEN tabs/windows... Is there a way to decide to open a specific link in a new window/tab? I se...

Anyone know why I'm getting this RSpec error? getting nil <--

def mock_category(stubs={}) @mock_category ||= mock_model(Category, stubs).as_null_object end describe "GET show" do it "assigns the requested category as @category" do Category.stub(:find).with("37") { mock_category } get :show, :id => "37" assigns(:category).should be(mock_category) end end Which returns : 1) Cate...