ruby-on-rails - 我应该使用 Selenium 还是 Jasmine 来使用 RSpec 测试 View 文件?

标签 ruby-on-rails ruby selenium rspec jasmine

我正在使用 Ruby on Rails 3.2.2、cucumber-rails-1.3.0、rspec-rails-2.8.1 和 capybara-1.1.2 以及 Selenium 驱动程序。收到我的答案后previous question我有一个疑问:我应该使用 Selenium ruby​​-gem 还是 Jasmine ruby​​-gem 来使用 RSpec 测试 View 文件?如果是这样,因为我已经在使用 Selenium 来测试 JavaScript使用 Cucumber 查看文件,为什么(使用 RSpec 测试时)我应该使用 Jasmine 而不是 Selenium?也就是说,为什么要使用两个具有相同用途并制作相同东西的 ruby ?

一般来说,实际上,您建议如何使用 RSpec 测试 View 文件? ...但是,这是使用 RSpec 测试 View 文件的“正确方法”还是应该使用 Cucumber 测试这些文件?

最佳答案

我更喜欢使用selenium服务器,firefox中的selenium IDE来记录和rspec的selenium客户端。

selenium_helper.rb

ENV["RAILS_ENV"] ||= 'test'
require File.expand_path(File.join(File.dirname(__FILE__),'../..','config','environment'))
require 'spec/autorun'
require 'spec/rails'
require 'factory_girl'
require 'rspec/instafail'
require "selenium/client"

Spec::Runner.configure do |config|
end

rspec_tester_file_spec.rb

  require "selenium/selenium_helper"
    require "selenium/modules/loginator"

    describe "tester" do
      attr_reader :selenium_driver
      alias :page :selenium_driver

      before(:all) do
        @verification_errors = []
        @selenium_driver = Selenium::Client::Driver.new \
          :host => "localhost",
          :port => 4444,
          :browser => "*firefox",
          :url => "http://localhost:3000",
          :timeout_in_second => 60
      end

      before(:each) do
        @selenium_driver.start_new_browser_session
      end

      append_after(:each) do
        @selenium_driver.close_current_browser_session
      end

      it "login and then try to search for stuff" do
        @login.run_login(page)
        page.click "link=CSR"
        page.wait_for_page_to_load "30000"
        page.type "id=isq_Name", "john smith"
        page.click "css=input[type=\"submit\"]"
        page.wait_for_page_to_load "30000"
        page.is_text_present("Update")
        page.is_text_present("Date")
        page.is_text_present("PIN")      
        page.is_text_present("Name")
      end

关于ruby-on-rails - 我应该使用 Selenium 还是 Jasmine 来使用 RSpec 测试 View 文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9969817/

相关文章:

ruby-on-rails - 按地理位置排序 Solr/sunspot 搜索结果

ruby - 使用 Faraday 通过 Unix 套接字发出 HTTP 请求

javascript - Selenium EventFiringWebDriver JavaScript : SyntaxError: missing ) after argument list

java - 正则表达式最后一次出现,后面仍然有关键字

mysql - MySQL 复合索引中键的高性能排序(WRT Rails 多态关联和 STI)

ruby-on-rails - 无方法错误 : undefined method `fetch' for "QLite version 3.x":String

ruby - Nokogiri to_xml 没有回车

python - 我正在尝试将已刮取的数据写入/粘贴到特定的 Excel 电子表格单元格位置,但我不知道如何去做

ruby-on-rails - Foreman/Puma 未使用开发环境中的指定端口

ruby - 在 block 之前更改 Sinatra 中的参数