ruby

Cucumber::ArityMismatchError error after Transform

my step definition Transform /^user "([^"]*)"$/ do | email | Person.find_by_email(email) end Given /^login as (user "([^"]*)")$/ do | user | login_as email end my feature login as user "[email protected]" I am getting this error And user "[email protected]" has security role "contact" # features/step_definitions/security_role_...

Question about checkbox on Ruby on Rails

Hello, I'm developing a website for my University and I got a problem. There is a page where I have the list of all students of the university. The admin can select some students that will be able to go to a selective process and then he have to see them in other separate page. How can I do that using Ruby On Rails? Thanks, Hugo Hen...

Ruby: Removing all empty elements from a hash / YAML?

How would I go about removing all empty elements (empty list items) from a nested Hash or YAML file? Thanks for any advice. ...

Ruby Telnet Lib - Weird Response

Hello, I am trying to execute cmds on a remote CPU through telnet. While some commands sent (through Ruby's stdlib for telnet) are successful, others are giving me a weird response: *=============================================================== Welcome to Microsoft Telnet Server. *=============================================...

Strange problems with Nokogiri

Say, we have an HTML, in which, all ... <div class="replace-me"> </div> ... must be replaced with <video src='my_video.mov'></video> The code is following: doc.css("div.replace-me").each do |div| div.replace "<video src='my_video.mov'></video>" end It's simple, but, unfortunately, it does't work for me. Nokogiri crashes with f...

How to wrap long lines in a text using Regular Expressions when you also need to indent the wrapped lines?

How can one change the following text The quick brown fox jumps over the lazy dog. to The quick brown fox + jumps over the + lazy dog. using regex? UPDATE1 A solution for Ruby is still missing... A simple one I came to so far is def textwrap text, width, indent="\n" return text.split("\n").collect do |line| line.sc...

Cannot install RCov from Gem

gem install rcov Error: Building native extensions. This could take a while... ERROR: Error installing rcov: ERROR: Failed to build gem native extension. "C:/Program Files/Ruby191/bin/ruby.exe" extconf.rb creating Makefile make Makefile:154: warning: overriding commands for target `C:/Program' Makefile:148: warning: ignoring ...

MySQL clone a table, prune some data and then hotswap their names

We have a 8 million row MySQL table. We want to prune about 2m rows from it, remove some outdated indexes and add new ones. To achieve almost no downtime, our plan is to create a clone of the table (and lock the original), run a script (Ruby) to prune the data that we don't need anymore and finally add the new indexes. Then we would p...

Unit Testing File I/O Methods

I am still relatively new to unit testing. I have written a class in Ruby that takes a file, searches through that file for a given Regex pattern, replaces it, then saves the changes back to the file. I want to be able to write unit tests for this method, but I don't know how I would go about doing that. Can somebody tell me how we unit ...

How to setup to get smtp log from rails

Can someone tell me how to configure rails to get an smtp log. thanks, ash ...

Programmatically drop all connections

At work, we do distributed testing, where rsync out to everyone elses machine and distribute out test files to speed up the testing process. One issue we are running into is that if someone has an instance of pgadmin open, it won't let us reset the test database due to connections being open. Is there any way we can programmatically kil...

How does Python stack up to other scripting languages?

I'm learning Python (and it's my first programming language so don't be too intense with your reasons) and I wanted to know how it stacks up to other scripting languages, like Perl and Ruby. What is Python better in comparison to other scripting languages, and what is it worse for? ...

Better way to write if condition.

Is there any better way to write this condition? if (self.expense.nil? && self.income.nil?) || (!self.expense.nil? && !self.income.nil?) puts "test" end ...

rspec expect throws "undefined method"

I am a complete Ruby newby and am playing around with rspec I am testing a class (Account) that has this line: attr_reader :balance When I try to test it with this method: it "should deposit twice" do @acc.deposit(75) expect { @acc.deposit(50) }.to change(Account.balance).to(125) end I get this error: NoMethodError in...

Comma Delinated string, of Ids, from Array of Objects. RoR

Why doesn't this work? I have an array of Objects, one of the attributes is the db id. I can make the array like so. qc_parts.map!{|a| a.id} However when I want to just make it a string. With qc_parts.map!{|a| a.id}.join(",") I only get an array out. I've also tried .to_s & .to_a Any idea why this would be happening? ...

How to strip leading and trailing quote from string, in Ruby

I want to strip leading and trailing quotes, in Ruby, from a string. The quote character will occur 0 or 1 time. For example, all of the following should be converted to foo,bar: "foo,bar" "foo,bar foo,bar" foo,bar ...

consume soap service with ruby and savon

I'm trying to use ruby and Savon to consume a web service. The test service is http://www.webservicex.net/WS/WSDetails.aspx?WSID=9&amp;CATID=2 require 'rubygems' require 'savon' client = Savon::Client.new "http://www.webservicex.net/stockquote.asmx?WSDL" client.get_quote do |soap| soap.body = {:symbol => "AAPL"} end Which retur...

Can an instance_method of a Module be invoked?

This is strictly theoretical. module BleeTest def meth puts 'foo' end end This code runs without error, but is it ever possible the invoke the method "meth"? It seems to me that "meth" is an instance method of a module which cannot be instantiated. But then why is this construct allowed by the interpreter? ...

undefined method `topics_path'

Not sure what this means and why... I got the undefined method error when I try to go to http://localhost:3000/forums, and after I generate my first forum. ActionView::TemplateError (undefined method `topics_path' for #<ActionView::Base:0x10319f2e0>) on line #25 of app/views/forums/index.html.erb: The area of code the error refers to...

How to send a kill signal to stop ruby app?

If you start a ruby app with the script/server command, what command do you use to stop it? ...