小编And*_*lin的帖子

使用rspec和rails测试嵌套模块

可能重复:
在rspec中测试模块

目前我用rspec成功测试了我的模块,如下所示:

require 'spec_helper'

module Services
  module AppService
    describe AppService do
      describe "authenticate" do
        it "should authenticate the user" do
          pending "authenticate the user"
        end
      end
    end
  end
end
Run Code Online (Sandbox Code Playgroud)

我的模块位于app/services/services.rb app/services/app_service.rb中

但是,有一个更优雅的解决方案来测试我的模块而无需在规范中声明命名空间吗?我觉得它与我的规格紧密相关,做出改变会引起很多麻烦.

ruby testing rspec ruby-on-rails

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

如何为参数集定义正确的数据结构

我需要以下数据结构:

在具有存储器插槽的设备中,每个插槽具有一组参数.这些参数有不同的类型.可能的参数列表是固定的,因此不需要通用的灵活性»支持任意参数而无需改变«.而且,对于每个参数,内容的结构是已知的.典型的用例是检索和修改一个特定参数,以及将完整参数集转换为不同(但已定义)的数据结构.

F#数据结构的自然选择是这样的和类型:

type SomeParameterContentType = { Field1 : string, Field2 : int }
type SomeOtherParameterContentType = { Other1 : bool option, Other2 : double }

type Parameter =
    | SomeParameter of SomeParameterContentType
    | SomeOtherParameter of SomeOtherParameterContentType
Run Code Online (Sandbox Code Playgroud)

这样我就可以用一个非常好的数据结构创建一个集合并存储参数.这里的问题是:鉴于这个想法,如何寻找一个特定的参数?我不知道为set的find-function指定谓词的任何方法.有可能定义另一个和类型列出参数类型而没有它们的内容,使用它作为词典的键,但我不太喜欢这个想法.使用字符串而不是第二个和类型并不能使事情变得更好,因为它仍然需要提供两次可能的参数列表.

有没有人有更好的主意?

Thx --Mathias.

f#

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

Android工作室dalvik vm无法找到课程

我试图弄清楚如何修复我已经移植到android studio的遗留android项目的错误.我希望这对我的build.gradle脚本来说更是个问题.类库在编码时正常工作,完成后完成等.

我试过关闭android工作室,运行gradlew clean,然后在android studio中重新打开它,但是没有用.

这是我的settings.gradle脚本.

include ':app', ':imageloader-core-1.6.1'

这是我的项目build.gradle脚本.

buildscript {
    repositories {
        jcenter()
        mavenCentral()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:1.0.0'
        classpath 'jp.leafytree.gradle:gradle-android-scala-plugin:1.3.1'
    }
}

allprojects {
    repositories {
        jcenter()
        mavenCentral()
    }
}

这是我的app build.gradle脚本.

apply plugin: 'com.android.application'
apply plugin: 'jp.leafytree.android-scala'

android {
    compileSdkVersion 19
    buildToolsVersion "21.1.1"

    defaultConfig {
        applicationId "com.andre.andredublin"
        minSdkVersion 14
        targetSdkVersion 19
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
        }
    }

    sourceSets {
        main {
            scala {
                srcDir 'src'
            }
        }
    }

    dexOptions { …

java android scala gradle android-studio

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

将数据从表复制到另一个表MySQL

我在将没有时间戳的新添加的记录更新到同一数据库中的另一个相同表时遇到问题.这是我的查询

INSERT INTO mlscopy
SELECT * FROM mls_cvrmls AS parent
LEFT JOIN mlscopy AS child
ON child.listing_listnum != parent.listing_listnum
Run Code Online (Sandbox Code Playgroud)

父表每天早上由一个单独的公司更新,遗憾的是没有时间戳(日期时间)来关联新添加的记录.

谷歌地理编码需要我的子表(副本),因为他们的早晨udpates下降并每天早上创建父表.

我制作了父表的结构和数据副本,然后删除了最后十条记录来测试我的查询.但我一直收到错误列数与第1行的值计数不匹配.

想不到我在这里做错了什么.

以下是列表名称

listing_listing
listing_listnum
listing_propertytype
listing_status
listing_listingpublicid
listing_agentname
listing_agentlist
listing_listingbrokercode
listing_officelist
listing_lo
listing_lo00
listing_lo01
listing_lo02
listing_lo03
listing_lo04
listing_lo05
listing_agentcolist
listing_agentcolist00
listing_officecolist
listing_area
listing_listdate
listing_listprice
listing_streetnumdisplay
listing_streetdirectional
listing_streetname
listing_streettype
listing_countyid
listing_zipcode
listing_zipplus4
listing_postoffice
listing_subdivision
listing_neighborhood
listing_schoolelem
listing_schooljunior
listing_schoolhigh
listing_pud
listing_lotdim
listing_acres
listing_zoning
listing_sqfttotal
listing_sqftunfinished
listing_rooms
listing_bedrooms
listing_stories
listing_basement
listing_garage
listing_garagecap
listing_fireplaces
listing_pool
listing_bathsfull
listing_bathshalf
listing_bathstotal
listing_bathsfullbsmt
listing_bathsfulllevel1
listing_bathsfulllevel2
listing_bathsfulllevel3 …
Run Code Online (Sandbox Code Playgroud)

mysql database

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

在Rails 3中干,如果没有elsif

第二周RoR(没有编程背景).我有一个问题,我正在做Metacritic类型的网站.到处都会有收视率.我决定0到33 =红色34到66 =橙色67到100 =绿色看起来像那样

索引(控制器:显示)

 <td><% if show.reviews.count == 0 %>0
    <% elsif show.reviews.average("rating").between?(33, 66) %>
    <table class="orange">
      <tr>
        <td><b><%= number_with_precision(show.reviews.average("rating"), :precision => 0) %></b></td>
     </tr>
    </table>
    <% elsif show.reviews.average("rating").between?(66, 100) %>
    <table class="green">
      <tr>
        <td><%= number_with_precision(show.reviews.average("rating"), :precision => 0) %></td>
      </tr>
    </table>
    <% elsif show.reviews.average("rating").between?(00, 33) %>
    <table class="red">
      <tr>
        <td><%= number_with_precision(show.reviews.average("rating"), :precision => 0) %></td>
      </tr>
    </table>
    <% end %>
  </td>
Run Code Online (Sandbox Code Playgroud)

我的问题是,我需要重复那段代码,看看(我只是开始了:show(控制器展示)

<p>
  Note: <% if @ratings == 0 %>0
  <% elsif @ratings.between?(33, 66) %>
  <table class="orange">
    <tr> …
Run Code Online (Sandbox Code Playgroud)

ruby-on-rails ruby-on-rails-3

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

会在php / codeigniter中将其视为依赖项注入吗?

这将被视为依赖注入吗?

<?php
class BASE_Model extends CI_Model 
{  
    /**
     * inject_class - load class using dependency injection
     *
     * @access public
     * @param  string $path
     * @param  string $class
     * @param  string $func
     * @param  string $method
     **/
    public function inject_class($path, $class, $func, $method)
    {
        // load_class is a function located in system/core/common.php on line 123
        $obj = load_class($class, $path, NULL);
        return $obj->$func();
    }
}

// lets say this is instantiated by a user controller when a new user is made …
Run Code Online (Sandbox Code Playgroud)

php oop design-patterns codeigniter

0
推荐指数
1
解决办法
2182
查看次数