Ubuntu11.10+ruby on rails 3+rspec+autotest+spork配置

本文详细介绍了如何在Rails项目中配置自动化测试环境,包括安装必要的gem包、设置autotest及spork等步骤。
step1:    创建新的项目,不包含默认测试文件(-T)
    $ rails new sampleapp -T

step2:
    $ cd sampleapp

step3:
    修改Gemfile
    添加
    gem 'therubyracer'
    group :development do
    gem 'rspec-rails'
    end
    group :test do
    gem 'rspec'
    gem 'webrat'
    end

step4:
    $ bundle install

step5:    安装rspec
    $ rails generate rspec:install

step6:    新建几个页面,【并删掉部分测试(可略过)】
    $ rails generate controller Pages home contact
    $ rm -rf spec/views
    $ rm -rf spec/helpers

step7: 安装autotest( http://automate-everything.com/2009/08/gnome-and-autospec-notifications/#comments)
    
    $sudo gem install ZenTest
    【#可能在安装的时候提示gem版本太低,需要~>1.8,需要升级,以下给出升级方法(直接gem update --system是不行的):
    #$sudo gem install rubygems-update -v 1.8.24(我安装时的最新版本)
    #$sudo update_rubygems
    #$sudo gem update --system
    #】
    $sudo gem install redgreen
    $sudo apt-get install libnotify-bin
step8:
    新建文件~/.autotest,内容如下
 
   #!/bin/ruby
    require 'redgreen' #若为ubuntu11.*需要去掉此行
    require 'autotest/timestamp'
    module Autotest::GnomeNotify
        def self.notify title, msg, img
            system "notify-send '#{title}' '#{msg}' -i #{img} -t 3000"
        end
        Autotest.add_hook :ran_command do |at|
            image_root = "~/.autotest_images"
            results = [at.results].flatten.join("\n")
            results.gsub!(/\\e\[\d+m/,'')
            output = results.slice(/(\d+)\sexamples?,\s(\d+)\sfailures?(,\s(\d+)\spending?|)/)
            full_sentence, green, failures, garbage, pending = $~.to_a.map(&:to_i)
            if output
                if failures > 0
                    notify "FAIL", "#{output}", "#{image_root}/fail.png"
                elsif pending > 0
                    notify "Pending", "#{output}", "#{image_root}/pending.png"
                else
                    notify "Pass", "#{output}", "#{image_root}/pass.png"
                end
            end
        end
    end


step9:
    下载autotest_images.zip,将.autotest_images放到放到~/下,即~/.autotest_images/
    下载链接: http://automate-everything.com/wp-content/uploads/2009/08/autotest_images.zip

step10:享受成果。
$cd sampleapp  #若已在此目录,略过
$autotest

step11:有关spork配置察看链接http://blog.youkuaiyun.com/emerald0106/article/details/7251332

注意启动spork时,spork为小写,即

$spork

先展示下效果 https://pan.quark.cn/s/5061241daffd 在使用Apache HttpClient库发起HTTP请求的过程中,有可能遇到`HttpClient`返回`response`为`null`的现象,这通常暗示着请求未能成功执行或部分资源未能得到妥善处理。 在本文中,我们将详细研究该问题的成因以及应对策略。 我们需要掌握`HttpClient`的运作机制。 `HttpClient`是一个功能强大的Java库,用于发送HTTP请求并接收响应。 它提供了丰富的API,能够处理多种HTTP方法(例如GET、POST等),支持重试机制、连接池管理以及自定义请求头等特性。 然而,一旦`response`对象为`null`,可能涉及以下几种情形:1. **连接故障**:网络连接未成功建立或在请求期间中断。 需要检查网络配置,确保服务器地址准确且可访问。 2. **超时配置**:若请求超时,`HttpClient`可能不会返回`response`。 应检查连接和读取超时设置,并根据实际需求进行适当调整。 3. **服务器故障**:服务器可能返回了错误状态码(如500内部服务器错误),`HttpClient`无法解析该响应。 建议查看服务器日志以获取更多详细信息。 4. **资源管理**:在某些情况下,如果请求的响应实体未被正确关闭,可能导致连接被提前释放,进而使后续的`response`对象为`null`。 在使用`HttpClient 3.x`版本时,必须手动调用`HttpMethod.releaseConnection()`来释放连接。 而在`HttpClient 4.x`及以上版本中,推荐采用`EntityUtils.consumeQuietly(respons...
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值