代码的功能是依赖外部其它网络的,所以,测试需要模拟外部的条件
如果只是cucumber测试可以直接在definitions里写mock
Given /^I have uploaded the claim file to "(.*)"$/ do |url|
require 'fakeweb'
FakeWeb.register_uri(:get, url, :body => @current_user.id.to_s)
end
Given /^I have not uploaded the claim file to "(.*)"$/ do |url|
require 'fakeweb'
FakeWeb.register_uri(:get, url, :status => ["404", "Not Found"])
end
Given /^I have uploaded an invalid claim file to "(.*)"$/ do |url|
require 'fakeweb'
FakeWeb.register_uri(:get, url, :body => "abc123def456")
end
以上,表示我们准备了外部的url并且保证外部url可以返回的结果。
然而,我们的页面有ajax调用
所以要用selenium配置见底
而用selenium就会有异步调用的问题,上面的写法就不能找到,而会访问真正的url不是模拟的。
那么,可以如下解决:
#test/mocks/selenium
require 'app/models/monitoring/claim'
require 'fakeweb'
module Monitoring
class Claim
def can_verify_ownership_with_fake_web
if index.url == 'http://notmatch.com'
FakeWeb.register_uri(:get, index.url + "/yottaa.html", :body => "no such code")
elsif index.url == 'http://nofilefound.com'
FakeWeb.register_uri(:get, index.url + "/yottaa.html", :status => ["404", "Not Found"])
else
FakeWeb.register_uri(:get, index.url + "/yottaa.html", :body => user.id.to_s)
end
can_verify_ownership_without_fake_web
end
alias_method_chain :can_verify_ownership, :fake_web
end
end
selenium配置
#feature/support/selenium.rb
Webrat.configure do |config|
config.application_environment = :selenium
config.selenium_browser_startup_timeout = 180
config.mode = :selenium
config.open_error_files = true # Set to true if you want error pages to pop up in the browser
end
class ActiveSupport::TestCase
setup do |session|
session.host! "localhost:3001"
end
end
Cucumber::Rails::World.use_transactional_fixtures = true
还有环境配置
ENV["RAILS_ENV"] ||= "cucumber"
require File.expand_path(File.dirname(__FILE__) + '/../../config/environment')
require 'cucumber/formatter/unicode' # Remove this line if you don't want Cucumber Unicode support
require 'cucumber/rails/rspec'
require 'cucumber/rails/world'
require 'cucumber/rails/active_record'
require 'cucumber/web/tableish'
require 'webrat'
require 'webrat/core/matchers'
require 'email_spec/cucumber'
require 'spec/stubs/cucumber'
Webrat.configure do |config|
config.mode = :rails
config.open_error_files = true # Set to true if you want error pages to pop up in the browser
end
分享到:
相关推荐
Ajax-Rails-4-AJAX-Form.zip,rails 4 ajax表单示例,ajax代表异步javascript和xml。它是多种web技术的集合,包括html、css、json、xml和javascript。它用于创建动态网页,其中网页的小部分在不重新加载网页的情况下...
jruby-maven-plugins, 以 Maven 方式,Maven 插件用来处理 rubygems 包括对 rspec Rails Cucumber rake等的支持 Maven 插件 gem-工件有 Maven 存储库,torquebox.org 提供了来自 rubygems.org的gem ( 只有 ruby 和...
从事RAILS开发的人员如何使用AJAX. Learn to build dynamic, interactive web applications using the two most important approaches to web development today: Ajax and the phenomenally efficient Ruby on ...
Ajax on Rails 的 PPT。 pdf格式。
NULL 博文链接:https://hlee.iteye.com/blog/1236898
docker-compose-rails-selenium-example 仅有的几种Docker Compose 3种集成技术: Rails 5.0开发和Travis CI测试 将捆绑程序gem缓存到Docker卷中,该卷在构建和Gemfile更改之间持续存在 运行Capybara测试的...
Ajax-Rails-4-AJAX-modal-form-render-JS-response-as-table-row.zip,rails 4 ajax模式表单将js响应呈现为表行,ajax代表异步javascript和xml。它是多种web技术的集合,包括html、css、json、xml和javascript。它用于...
Ajax、Prototype和Scriptaculous等JavaScript代码库和RJS,Session管理、用户登录和认证系统,XML和ActiveResource,后台处理和ActionMaile,测试和specs(包括RSpec on Rails和Selenium),安装、管理、编写插件,...
Apress,.Beginning.Google.Maps.Applications.with.Rails.and.Ajax.
ajax on rails压缩包,全英文
Cucumber-Rails将Cucumber引入了Rails 5.x和6.x。 安装 在使用生成器之前,请按照以下步骤将gem添加到项目的Gemfile中: group :test do gem 'cucumber-rails' , require : false # database_cleaner is not ...
Ajax-rails-ajax-demo.zip,ruby on rails的ajax演示项目,ajax代表异步javascript和xml。它是多种web技术的集合,包括html、css、json、xml和javascript。它用于创建动态网页,其中网页的小部分在不重新加载网页的...
主要介绍了在Ruby on Rails中使用AJAX的教程,文章来自于IBM官方网站技术文档,需要的朋友可以参考下
NULL 博文链接:https://michael-roshen.iteye.com/blog/1730158
Rails-4-AJAX表格Rails 4 AJAX表单示例请阅读同伴博客文章: :
使用RSpec 测试Rails 程序.pdf
您一定知道Ajax是这样一种编程技术,它...Ruby on Rails框架和Ajax的完美集成所产生的力量在一定程度上促成了该框架的繁荣。本文全面介绍了两个简单的Ajax例子,延着这个思路介绍了Ruby/Ajax这一组合如此成功的原因。