小编ord*_*rde的帖子

在 ruby​​ 单元测试中访问全局变量

我在使用测试类中定义的全局变量时遇到问题,然后在库文件中引用该全局变量。我正在使用 Ruby 1.9.3p392 和测试单元 2.5.4。

这是运行测试的代码:

require 'rubygems'
gem 'test-unit'
require 'test/unit'
require 'ci/reporter/rake/test_unit_loader'
load '../lib/functions.rb'
require 'watir'

class Test_002 < Test::Unit::TestCase

  include Functions

  class << self
   def startup
      @browser = Watir::Browser.new :ie
      @browser.speed = :fast
    end

    def shutdown
      @browser.close
    end
  end

  def test_001_login
    login('some_url', 'some_user', 'some_passw')
  end
end
Run Code Online (Sandbox Code Playgroud)

这是包含登录功能的库的一部分:

require 'rubygems'

 module Functions 

  def login(url, user, passw)
    @browser.goto(url)
    ...
  end
end
Run Code Online (Sandbox Code Playgroud)

这是输出:

Started
E
===============================================================================
Error: test_001_login(Test_002)
  NoMethodError: undefined method `goto' for nil:NilClass
(...)
     23:   end
     24:   
     25:   def …
Run Code Online (Sandbox Code Playgroud)

ruby unit-testing watir

5
推荐指数
1
解决办法
2970
查看次数

Ruby - 如何在读取文件时跳过/忽略特定行?

在读取/解析文件时使用Ruby忽略某些行的最佳方法是什么?

我正在尝试从Cucumber .feature文件中解析场景,并且想要跳过不以Scenario/Given/When/Then/And/But开头的行.

下面的代码有效,但它很荒谬,所以我正在寻找一个智能的解决方案:)

File.open(file).each_line do |line|
  line.chomp!
  next if line.empty? 
  next if line.include? "#"
  next if line.include? "Feature" 
  next if line.include? "In order" 
  next if line.include? "As a" 
  next if line.include? "I want"
Run Code Online (Sandbox Code Playgroud)

ruby parsing skip lines cucumber

5
推荐指数
2
解决办法
8273
查看次数

列表中两个单词之间的余弦相似度

我正在定义一个函数,它接受一个单词列表并返回有关列表中彼此之间具有非零余弦相似度(以及相似度值)的单词的信息。

谁能帮我解决这个问题。我在想,如果我能得到一个预先计算好的 word2vec 矢量文件,那会很有帮助,但互联网上没有。

python word2vec

4
推荐指数
1
解决办法
9959
查看次数

Windows 版 Curl -curl 无法打开文件 C:\test.txt

我正在尝试在 Windows 设备上使用 CURL,但无法计算出在特定位置上传文件的正确语法,希望有人有一个想法。

目前我正在尝试的语法如下;

curl --proxy-ntlm --proxy-user domain\username:password --proxy proxy.server:80 -vk 'filename=hello.txt' -F 'file=@C:\hello.txt' https://upload.site
Run Code Online (Sandbox Code Playgroud)

但我所能得到的只是curl: (26) couldn't open file "C:\hello.txt"

我已经尝试过 @C:\\hello.txt、@C:/hello.txt、@"C:\hello.txt" 但仍然遇到相同的错误。

有人知道我可能出错的地方吗?我不敢相信这会像我想象的那么难:-)

windows curl path

4
推荐指数
1
解决办法
1万
查看次数

rspec Bisect无限期运行

rspec --bisect在Circleci上运行时看到一些意外的行为。通常,二等分会无限期运行,直到5小时后超时。二分法最初似乎在起作用,但是一旦达到预期的终点,它就会开始缓慢地以相反的方向检查子集,直到超时为止。

我的环境:
Ruby 2.4.2p198 (2017-09-14 revision 59899) [x86_64-darwin16]
RSpec 3.7
- rspec-core 3.7.1
- rspec-expectations 3.7.0
- rspec-mocks 3.7.0
- rspec-rails 3.7.2
- rspec-support 3.7.1

命令:
DISABLE_SPRING=true RAILS_ENV=test bundle exec rspec #{all_specs} --order rand:21237 --bisect

Running suite to find failures... (1 minute 5.94 seconds)
Starting bisect with 1 failing example and 424 non-failing examples.
Checking that failure(s) are order-dependent... failure appears to be order-dependent

Round 1: bisecting over non-failing examples 1-424 .. multiple culprits detected - splitting …
Run Code Online (Sandbox Code Playgroud)

ruby rspec bisect circleci

4
推荐指数
2
解决办法
521
查看次数

从watir webdriver中的span元素中检索文本

我有以下内容:

<ul class="a">
  <li class="b">
    <a class="c">
      <span class="d">
        <strong>text</strong>
      </span>
    </a>
  </li>
</ul>
Run Code Online (Sandbox Code Playgroud)

我正试图从跨度中获取"文本".

当我尝试:

puts browser.ul( :class =>'a').li( :class =>'b').link(:class =>'c').span(:class =>'d')
Run Code Online (Sandbox Code Playgroud)

我把span元素拿回来了.#<Watir::Span:0x007fa1d11edb18>我应该这样做.

但在尝试时:

puts browser.ul( :class =>'a').li( :class =>'b').link(:class =>'c').span(:class =>'d').text
Run Code Online (Sandbox Code Playgroud)

我得到一个错误说:

unable to locate element, using {:class=>'b', :tag_name=>"li"}
Run Code Online (Sandbox Code Playgroud)

有任何想法吗 ?

watir watir-webdriver

3
推荐指数
1
解决办法
7034
查看次数

如何覆盖宝石的常量?(Ruby on Rails)

我 在我的项目中使用Twitter-text gem,但是我遇到了一些错误.我需要覆盖那个gem的一个常量.

我在StackOverflow上看到一些关于方法覆盖的问题对我有帮助,但我仍然遇到麻烦.我创建了一个名为twitter-text.rbin 的文件/config/initializers/并编写了以下代码:

module Twitter
  class Regex
    HASHTAG_CHARACTERS = "/[[^ ]_#{LATIN_ACCENTS}]/io"
  end
end
Run Code Online (Sandbox Code Playgroud)

(这个正则表达式允许我用除空格之外的任何字符编写Hashtags).

我也试图覆盖一个方法,但它似乎也不起作用.关注我的代码(在同一个文件中):

module Twitter
  module Autolink
    def auto_link_hashtags(text, options = {})  # :yields: hashtag_text
      text = text.downcase
      options = options.dup
      (...)
    end
  end
end
Run Code Online (Sandbox Code Playgroud)

我刚刚在这个方法中添加了以下行:text = text.downcase.那么,我该怎么做才能覆盖这个方法和属性/常量?

ruby overriding rubygems ruby-on-rails ruby-on-rails-3

3
推荐指数
1
解决办法
2047
查看次数

Watir 检查文本存在

我得到它不是 Watir 结合 rspec 找到我的文本。以下代码导致此错误。

  1. 代码:browser.text.include?("Coverberechnung").should == true
  2. 错误 1: expected: true got: false (using ==)
  3. 错误2: Using should from rspec-expectations' old :should syntax without explicitly enabling the syntax is deprecated. Use the new :expect syntax or explicitly enable :should instead. Called from

也许我可以帮忙

该站点的 URL:在此处输入链接描述

ruby rspec watir assertion watir-webdriver

3
推荐指数
1
解决办法
9448
查看次数

如何使用ffmpeg在特定时间向视频文件添加音频

我有一个avi和一个wav文件.假设视频文件长一小时,音频文件长30分钟,并且与视频文件的最后30分钟相关联.

有没有办法创建一个视频和音频组合的新视频文件,但在视频的前30分钟后开始播放音频?

audio video ffmpeg

3
推荐指数
1
解决办法
1701
查看次数

在Chrome中运行无头模式时,将文件下载到路径

我使用以下版本:

  • Ruby 2.4.1
  • chromedriver 2.33
  • selenium-webdriver 3.7.0
  • watir 6.7.3
  • page-object 2.2.2
  • Chrome浏览器62.0.32

env.rb文件包含下载目录的路径.运行测试时不要在无头的模式下文件下载完美的,但是当我运行它无头什么也没有发生,文件没有下载.我使用的是chromderiver 2.27和Chrome Browser 58.*它在两种模式下都有效,有人知道我怎么能克服这个问题?

ruby google-chrome watir selenium-chromedriver google-chrome-headless

3
推荐指数
1
解决办法
1489
查看次数