小编Nis*_*rma的帖子

获取两个特定单词之间包含的子字符串

当我对使用ruby的特定单词之间包含的文本感兴趣时,我想知道如何继续.例如.

@var = "Hi, I want to extract container_start ONLY THIS DYNAMIC CONTENT container_end from the message contained between the container_start and container_end "
Run Code Online (Sandbox Code Playgroud)

现在我想从字符串中提取CAPITALIZED内容,即动态但始终包含在两个容器中(container_startcontainer_end)

ruby regex substring ruby-on-rails-3

6
推荐指数
1
解决办法
7114
查看次数

如何将拒绝/失败的承诺通过茉莉花间谍返回到单位测试中的角度控制器

我正在使用茉莉来测试我的角度控制器..then(successCallback, errorCallback) 虽然它在实时功能的基础上工作得很好但是我很困惑如何写一个间谍来返回一个错误,因为它总是被捕获的错误和成功successCallback()

以下是控制器: -

angular.module('myApp')
.controller('LoginCtrl', function ($scope, $location, loginService, SessionService) {
    $scope.errorMessage = '';

    $scope.login = function () {

      var credentials = {
          email: this.email,
          password: this.password
      };

     SessionService.resetSession();
     var request = loginService.login(credentials);

     request.then(function(promise){ //successfull callback
        if (promise['status'] === 200){
             //console.log('login');
            $location.path('/afterloginpath');
        }
      },
     function(errors){  //fail call back
      //  console.log(errors);
        $location.path('/login');
     });
    };
});
Run Code Online (Sandbox Code Playgroud)

我的测试用例: -

'use strict';

describe('Controller: LoginCtrl', function () {

  // load the controller's module
  beforeEach(module('myApp'));

  var LoginCtrl, scope, location, login, loginReturn, session; …
Run Code Online (Sandbox Code Playgroud)

javascript unit-testing angularjs angularjs-controller karma-jasmine

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

错误:意外请求:即使在karma/jasmine单元测试中使用html2js,也可以获取嵌套指令的GET views/partials/*

我正在使用Karma和Jasmine对我的angularjs应用程序进行单元测试.我有一个指令(比如指令A)模板,其中另一个指令(比如指令B)被渲染,虽然它在应用程序中工作正常,但测试用例无法呈现指令B的模板.以下是我得到的错误: -

    Error: Unexpected request: GET views/partials/directiveb.html
Expected GET https://my-sandbox.app.com/123456
Run Code Online (Sandbox Code Playgroud)

以下是指令A的代码: -

angular.module('myApp')
  .directive('directiveA', function (myservices, myOtherServices) {
    return {
        controller: function(){
        /* ... controller function ... */
        },
        templateUrl: '/views/partials/directivea.html',
        restrict: 'E',
        link: function postLink(scope, element, attrs) {
        /* ...link function... */
        }
    };
  });
Run Code Online (Sandbox Code Playgroud)

指令A的模板: -

<div>
    <div class="col-md-12">
        <h4>We <strong>Need</strong></h4>
        <div directive-b some-attribute=="true"></div>
    </div>
    <div directive-b some-attribute=="false"></div>
</div>
Run Code Online (Sandbox Code Playgroud)

指令A的测试案例: -

'use strict';

describe('Directive: directiveA', function () {

    // load the directive's module
    beforeEach(module('myApp'));
    beforeEach(module('template-module'));

    var element, appId, …
Run Code Online (Sandbox Code Playgroud)

unit-testing jasmine phantomjs angularjs karma-runner

6
推荐指数
1
解决办法
6466
查看次数

高效删除Ruby中数组中其他元素的所有子串

我有一个复杂的问题就是在手编辑一个数组.我有一个数组,其中一些元素是其他元素的子字符串.我想删除所有子字符串并仅保留超集/字符串.ie Array => ['1', '1 1', '1 1 1', '1 1 1 2', '1 2 3 1', '1 2', '2 3'] 操作后我应该有一个清理过的数组=>['1 1 1 2', '1 2 3 1']

是否有一种有效的算法来实现相同的目标?

ruby arrays sorting algorithm substring

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

`add_frozen_gem_path':Gem的未定义方法`source_index':模块(NoMethodError)或不推荐使用Gem.source_index

我使用rails 2.3.11,ruby-1.9.2-p320.尝试运行脚本/服务器,但收到此错误: -

system@admin:~/apps/app_name/trunk$ script/server
=> Booting WEBrick
=> Rails 2.3.11 application starting on http://0.0.0.0:3000
/home/system/.rvm/gems/ruby-1.9.2-p320@gemset_name/gems/rails-2.3.11/lib/rails/gem_dependency.rb:21:in `add_frozen_gem_path': undefined method `source_index' for Gem:Module (NoMethodError)
    from /home/system/.rvm/gems/ruby-1.9.2-p320@gemset_name/gems/rails-2.3.11/lib/initializer.rb:298:in `add_gem_load_paths'
    from /home/system/.rvm/gems/ruby-1.9.2-p320@gemset_name/gems/rails-2.3.11/lib/initializer.rb:132:in `process'
    from /home/system/.rvm/gems/ruby-1.9.2-p320@gemset_name/gems/rails-2.3.11/lib/initializer.rb:113:in `run'
    from /home/system/apps/app_name/trunk/config/environment.rb:9:in `<top (required)>'
    from /home/system/.rvm/rubies/ruby-1.9.2-p320/lib/ruby/site_ruby/1.9.1/rubygems/core_ext/kernel_require.rb:126:in `require'
    from /home/system/.rvm/rubies/ruby-1.9.2-p320/lib/ruby/site_ruby/1.9.1/rubygems/core_ext/kernel_require.rb:126:in `require'
    from /home/system/.rvm/gems/ruby-1.9.2-p320@gemset_name/gems/activesupport-2.3.11/lib/active_support/dependencies.rb:182:in `block in require'
    from /home/system/.rvm/gems/ruby-1.9.2-p320@gemset_name/gems/activesupport-2.3.11/lib/active_support/dependencies.rb:547:in `new_constants_in'
    from /home/system/.rvm/gems/ruby-1.9.2-p320@gemset_name/gems/activesupport-2.3.11/lib/active_support/dependencies.rb:182:in `require'
    from /home/system/.rvm/gems/ruby-1.9.2-p320@gemset_name/gems/rails-2.3.11/lib/commands/server.rb:84:in `<top (required)>'
    from /home/system/.rvm/rubies/ruby-1.9.2-p320/lib/ruby/site_ruby/1.9.1/rubygems/core_ext/kernel_require.rb:73:in `require'
    from /home/system/.rvm/rubies/ruby-1.9.2-p320/lib/ruby/site_ruby/1.9.1/rubygems/core_ext/kernel_require.rb:73:in `require'
    from script/server:3:in `<main>'
Run Code Online (Sandbox Code Playgroud)

然后我在SO上提到几个答案并从终端运行以下命令: -

system@admin:~/apps/app_name/trunk$ gem update --system 1.8.25
Run Code Online (Sandbox Code Playgroud)

现在我收到错误: -

system@admin:~/apps/app_name/trunk$ script/server
=> Booting WEBrick …
Run Code Online (Sandbox Code Playgroud)

rubygems ruby-on-rails deprecated ruby-on-rails-2

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

net/imap ruby​​ 不支持指定的 SASL 机制

我正在使用 ruby​​ 1.9.3 使用“net/imap”库验证电子邮件凭据。如果我尝试在 Rails 控制台中使用以下代码,它会起作用:-

imap = Net::IMAP.new('imap.aol.com')
imap.authenticate('LOGIN', "username@aol.com".split("@").first, "password")
Run Code Online (Sandbox Code Playgroud)

但是当我在 Rails 应用程序中使用它时,它给了我一个错误:-

Specified SASL mechanism not supported.
Run Code Online (Sandbox Code Playgroud)

这种情况仅发生在 AOL 的情况下,雅虎在控制台和 Rails 应用程序中都可以工作。

有谁知道它可能是什么。

谢谢

ruby authentication imap sasl ruby-on-rails-3.2

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

在 mongodb 中使用索引搜索值

我是 Mongodb 的新手,希望在 mongo 集合中实现对字段的搜索。

我的测试集合具有以下结构:-

{
  'key': <unique key>,
  'val_arr': [
               ['laptop', 'macbook pro', '16gb', 'i9', 'spacegrey'],
               ['cellphone', 'iPhone', '4gb', 't2', 'rose gold'],
               ['laptop', 'macbook air', '8gb', 'i5', 'black'],
               ['router', 'huawei', '10x10', 'white'],
               ['laptop', 'macbook', '8gb', 'i5', 'silve'],
}
Run Code Online (Sandbox Code Playgroud)

我希望根据索引号和值找到它们,即找到其中任何一个val_arris中的第一个元素laptop和第三个元素的值 is的条目8gb

我尝试查看 mongodb 中的复合索引,但它们的索引键限制为 32 个。任何在这个方向上的帮助表示赞赏。

multidimensional-array mongodb mongodb-query

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

VCR仅使用selenium webkit在capybara中进行一次集成测试

我正在使用Rspec与Capybara运行使用VCR gem的集成测试来模拟存根api请求.我面临着各种奇怪的问题.测试第一次成功运行并创建yaml文件以保存请求及其响应.但是如果我在创建yaml文件后再次运行测试,那么它会遇到问题并显示以下问题: -

F

Failures:

  1) AffiliateSignUpProcesses Sign up using affiliate link should create User/Affiliate/AffiliateToken and Conversion when user is created
     Failure/Error: visit pricing_path(:aid => 'this_is_sample_value')
     VCR::Errors::UnhandledHTTPRequestError:


       ================================================================================
       An HTTP request has been made that VCR does not know how to handle:
         GET http://127.0.0.1:58021/__identify__

       VCR is currently using the following cassette:
         - /home/pcname/appname/selenium-error/fildername/appaname/cassettes/acceptanceTest/AffiliateSignUpProcess.yml
         - :record => :once
         - :match_requests_on => [:method, :uri]

       Under the current configuration VCR can not find a suitable HTTP interaction
       to replay and is prevented from …
Run Code Online (Sandbox Code Playgroud)

rspec ruby-on-rails-3 capybara-webkit selenium-webdriver vcr

2
推荐指数
1
解决办法
2138
查看次数