Ruby EventMachine testing

My first question concerning Ruby. I'm trying to test EventMachine interaction inside the Reactor loop - I guess it could be classified as "functional" testing. Say I have two classes - a server and a client. And I want to test both sides - I need to be sure about their interaction. Server: require 'singleton' class EchoServer < EM::Connection include EM::Protocols::Lin

Ruby EventMachine测试

我的第一个关于Ruby的问题。 我试图在Reactor循环内测试EventMachine交互 - 我想它可以被归类为“功能”测试。 假设我有两个类 - 一个服务器和一个客户端。 我想测试双方 - 我需要确定他们的互动。 服务器: require 'singleton' class EchoServer < EM::Connection include EM::Protocols::LineProtocol def post_init puts "-- someone connected to the echo server!" end def receive_data data s

Unescaping HAML in an Attribute Hash

I have a problem similar to some I've found on stackoverflow, but not quite the same. I'd like to avoid the solution to the following question: https://stackoverflow.com/a/10407782/996587 Basically, would like the following HTML output: <div class='myclass' extraattr='UNESCAPED <>& CONTENT'> Content... </div> The HAML I'm using looks like this: .mycla

在属性散列中消除HAML

我有一个类似于我在stackoverflow上找到的一些问题,但不完全一样。 我想避免解决以下问题: https://stackoverflow.com/a/10407782/996587 基本上,会喜欢下面的HTML输出: <div class='myclass' extraattr='UNESCAPED <>& CONTENT'> Content... </div> 我使用的HAML如下所示: .myclass{ "extraattr" => "UNESCAPED <>& CONTENT" } Content... 我无法弄清楚如何让内容以我

Custom profile for Chrome

Environment: Mac OS X 10.8.3, Ruby 2.0.0p0, selenium-webdriver 2.32.1, ChromeDriver 26.0.1383.0. I want to change default browser language. I am testing if the site detects the browser language correctly and displays the pages in the language. I was able to set Firefox language to German: require "selenium-webdriver" profile = Selenium::WebDriver::Firefox::Profile.new profile["intl.accept

Chrome的自定义个人资料

环境:Mac OS X 10.8.3,Ruby 2.0.0p0,selenium-webdriver 2.32.1,ChromeDriver 26.0.1383.0。 我想更改默认的浏览器语言。 我正在测试网站是否正确检测到浏览器语言并以该语言显示页面。 我能够将Firefox语言设置为德语: require "selenium-webdriver" profile = Selenium::WebDriver::Firefox::Profile.new profile["intl.accept_languages"] = "de" caps = Selenium::WebDriver::Remote::Capabilities.firefox(fir

LSD Radix Sort for Integers

I'm having trouble wrapping my head around using radix sort for a group of fixed-length integers. In my below attempt to implement least significant digit radix sort, I have a function called num_at which returns the digit d in the number num. The code I've written has w = 2, where w represents the length of each number. (Essentially, then, this code is written for 3 digit numbers as m

LSD基数排序整数

我在使用基数排序来处理一组固定长度的整数时遇到了麻烦。 在我下面的尝试实现最小有效数字基数排序,我有一个名为num_at函数返回数字num中的数字d。 我写的代码有w = 2,其中w代表每个数字的长度。 (本质上,然后,这个代码是为3位数字编写的,如下面的输入所示)。 我将此模型化为每个数字的按键索引计数,但是我得到了[0, 12, 32, 32, 44, 0] 0,12,32,32,44,0]的输出,坦白地说,为什么会有一段艰难的时间。 这是

See if google user is online

I'm currently trying to create a rails app that checks if a google user is online or not but I'm not even sure where to start. Should I use the google plus API or gmail api to retrieve the online status of a user or is there another alternative or example I can use as reference preferably in ruby or javascript? Thanks in advance Neither of those apis give you online status. in fac

查看谷歌用户是否在线

我目前正在尝试创建一个Rails应用程序来检查一个谷歌用户是否在线,但我甚至不知道从哪里开始。 我应该使用谷歌plus API还是gmail api来检索用户的在线状态,还是有其他的替代或例子,我可以用它作为参考,最好在ruby或javascript中使用? 提前致谢 这两种apis都不会给你在线状态。 事实上,目前还没有一个谷歌API可以告诉你这个,那就是你为什么找不到它。

What does class << self mean?

Regarding: class Test class << self def hi puts "Hi there" end end I came up with following image in my head: Since everything is an object in Ruby, classes themselves are objects of class Class . By calling class << self you open up Class definition from the inside of Test and inject few instance methods. Since Test is an instance of Class , you can call those m

类“自我”是什么意思?

关于: class Test class << self def hi puts "Hi there" end end 我在脑海中形成了如下图像: 由于Ruby中的所有东西都是对象,所以类本身就是Class对象。 通过调用class << self您可以从Test内部打开Class定义并注入少量实例方法。 由于Test是Class一个实例,因此您可以像调用对象上的实例方法一样调用这些方法: Test.hi 。 以下是有助于可视化我的上一句话的伪代码: class Class d

Surprising output using Parallel gem with srand and rand

I'm working with ruby 2.4.1 + parallel 1.11.2. I'm running the following in irb: require 'parallel' srand(1) Parallel.map([0, 1], in_processes: 2) { |i| puts "in process #{i}; rand => #{rand}" } My understanding is that when in_processes is specified, Parallel.map forks the process and then executes the loop body. Given that, I expect both processes to have the same global state an

使用srand和rand的并行gem令人惊讶的输出

我正在使用红宝石2.4.1 +并行1.11.2。 我在irb中运行以下内容: require 'parallel' srand(1) Parallel.map([0, 1], in_processes: 2) { |i| puts "in process #{i}; rand => #{rand}" } 我的理解是,当指定in_processes时, Parallel.map分叉进程并执行循环体。 鉴于此,我预计这两个进程都具有相同的全局状态,因此我期望两者都输出相同的随机数。 但是,这是我得到的: irb(main):003:0> Parallel.map([0, 1], in_

a set of strings and reopening String

In an attempt to answer this question: How can I make the set difference insensitive to case?, I was experimenting with sets and strings, trying to have a case-insensitive set of strings. But for some reason when I reopen String class, none of my custom methods are invoked when I add a string to a set. In the code below I see no output, but I expected at least one of the operators that I overlo

一组字符串并重新打开String

在试图回答这个问题时:我如何使设置差别对大小写不敏感?我正在尝试使用集合和字符串,尝试设置字符串不区分大小写。 但由于某种原因,当我重新打开String类时,我没有任何自定义方法在向字符串添加字符串时被调用。 在下面的代码中,我看不到任何输出,但我期望至少有一个我重载的操作符被调用。 为什么是这样? 编辑:如果我创建一个自定义类,比如说,String2,我定义了一个哈希方法等,这些方法确实会在我将对象添加到

Best practice or workaround for RSpec specs faking class constants

Let's say I have classes Car and Mechanic. Car has "run" method. Mechanic requires Car for some reason. Then I write RSpec specs. In mechanic I define a fake clas like this: class Car; end and later stub the method that mechanic uses on it. All works fine if I run tests seperately. But when I run both tests together (rspec spec/directory/) my Mechanic specs use real Car clas

RSpec规范伪造类常量的最佳做法或解决方法

比方说,我有汽车和机械师课。 汽车有“跑”的方法。 机械师出于某种原因需要汽车。 然后我写RSpec规格。 在机械师中,我定义了一个假的clas: class Car; end 并稍后存根据机制使用的方法。 如果我单独运行测试,所有工作正常。 但是当我将两个测试一起运行时(rspec spec / directory /),我的机械规格使用真正的Car类。 所以。 我想这是因为红宝石类是“开放”的,我已经为Car规格加载过一次类。 但有没有更好的方法

job going into a busy loop when lodging second task

I am running delayed_job for a few background services, all of which, until recently, run in isolation eg send an email, write a report etc. I now have a need for one delayed_job, as its last step, to lodge another delayed_job. delay.deploy() - when delayed_job runs this, it triggers a deploy action, the last step of which is to ... delay.update_status() - when delayed_job runs this job, it

工作在进入第二项任务时进入繁忙的循环

我正在为一些后台服务运行delayed_job,直到最近,所有这些服务都是孤立运行的,例如发送电子邮件,编写报告等。 我现在需要一个delayed_job作为最后一步,提交另一个delayed_job。 delay.deploy() - 当delayed_job运行这个时,它触发一个部署操作,最后一步是... delay.update_status() - 当delayed_job运行此作业时,它将检查我们开始部署的状态。 如果部署仍在进行中,我们再次调用delay.update_status(),如果