Tag: 测试

黄瓜与内置测试?

昨天我问了一个关于不同测试框架的问题。 这个问题可以在这里找到。 现在我对不同的框架有了更好的理解,我有一个非常简单的问题: 有了基本的理解,但是使用rails内置的测试框架(基本断言)编写测试的经验非常有限,我可以直接跳转到使用RSpec,Webrat和Cucumber进行测试吗? 谢谢! 作为旁注:是的,这是一个基于意见的问题,但我觉得收到这个问题的意见对社群来说足够有价值,可以保持这个问题的开放性。 谢谢。

带回形针的夹具

我正在使用Paperclip存储文档,但我找不到如何创建它们的装置,我写道: File.open(Rails.root.join(‘spec’, ‘assets’, ‘image.png’))) %> : asset_file_name: asset_content_type: asset_file_size: asset_updated_at: documentable: party (Event) %> 但是我运行它,文档存在于数据库中,但它没有存储。 我应该自己存储文件(写文件)吗? 或者还有其他方式吗?

使用Capybara + Rails3找不到要点击的元素

背景 :我正在使用Capybara和Rspec来测试Rails 3应用程序。 使用的驱动程序 :Selenium 问题 :我无法找到“登录”按钮,以便在我的测试中点击。 HTML代码: Email Password Forgot password… Cancel 测试失败 it “should login correctly if the right credentials are given”, :js => true do Capybara.default_wait_time = 5 Capybara.reset_sessions! visit ‘/’ click_link(‘login_link’) #this will bring a modal window with the code posted above using js within(“#login”) do fill_in ‘user_email’, :with => “my-email@example.com” […]

测试rake任务中定义的方法

我想测试rake任务中定义的方法。 耙文件 #lib/tasks/simple_task.rake namespace :xyz do task :simple_task => :environment do begin if task_needs_to_run? puts “Lets run this…” #some code which I don’t wish to test … end end end def task_needs_to_run? # code that needs testing return 2 > 1 end end 现在,我想测试这个方法, task_needs_to_run? 在测试文件中我该怎么做? 补充说明:我理想的是也希望在rake任务中测试另一个私有方法……但我可以稍后再担心。

运行function时不会自动加载黄瓜步骤

我最近在我的机器上更新了Cucumbergem(’cucumber’和’cucumber-rails’)并遇到了几个问题。 我目前正在争斗的是,Cucumber没有自动加载我的function的任何已定义步骤。 这导致我的命令行告诉我“我可以为我的function中使用的每个步骤实现这些片段的未定义步骤的步骤定义”。 我跑了: cucumber –verbose ……并且可以看到以下内容: 代码:* vendor / plugins / paperclip / cucumber / paperclip_steps.rb 但是,除非我指定要加载的文件,否则Cucumber不会加载任何步骤: cucumber -r features/step_definitions/web_steps.rb 我认为这可能只是我在我的应用程序结构中的“step_definitions”文件夹中创建的自定义步骤文件,但看起来标准的“web_steps”文件也没有被加载。 非常感谢任何遇到过这个问题的人或者知道为什么会这样。 谢谢。

自动测试无限循环

我在使用带有Rails项目的自动测试时遇到了一个问题,即当测试失败时(即,我修改了测试文件并且自动测试自动运行测试),自动测试会不断尝试运行测试(因为每次测试都失败了文件尚未修改),而不是等到文件再次保存。 随着咆哮通知,这可能会非常烦人,而我正在尝试修复代码以使测试通过。 它不会一直发生,但大部分时间都是如此。 有没有其他人遇到这个并知道解决方案? 谢谢。

Rails测试错误:WHERE的参数必须是boolean类型,而不是类型integer

用户可以通过has_many关联投票给post。 我从运行测试中收到此错误: ActiveRecord::StatementInvalid: PG::DatatypeMismatch: ERROR: argument of WHERE must be type boolean, not type integer 从这个测试: test “should unvote a post the standard way” do @user.vote(@post_2) postvoterelationship = @user.active_post_vote_relationships.find_by(voted_id: @post_2.id) assert_difference ‘@user.postvoting.count’, -1 do delete postvoterelationship_path(postvoterelationship) end end postvoterelationships_controller.rb def destroy @user = Postvoterelationship.find(params[:id]).voter @post = Postvoterelationship.find_by(params[:id]).voted @user.unvote(@post) respond_to do |format| format.html do redirect_to @user […]

如何在测试套件中进行下一次测试之前关闭所有窗口?

[7] pry(#)> page.execute_script “window.close()” Selenium::WebDriver::Error::NoSuchWindowError: Script execution failed. Script: window.close(); The window could not be found [8] pry(#)> page.driver.browser.window_handles => [“f1-2”] 我打开了一个带有两个选项卡的浏览器,上面的命令关闭了一个,但最后一个选项卡从未关闭。 它是开放的,但是当我尝试运行page.execute_script “window.close()”它会给出上述错误。 page.driver.browser.window_handles.each do |handle| page.driver.browser.switch_to.window(handle) page.execute_script “window.close()” end 上面的代码在某个时候对我有用,但不再起作用了。 它给出了同样的错误。 更新: 我用的时候 page.driver.browser.window_handles.each do |handle| page.driver.browser.switch_to.window(handle) page.driver.browser.close end 它给出以下错误Selenium::WebDriver::Error::UnknownError: ‘auto_id’不引用打开的选项卡

Spork + Minitest

任何人都可以解释如何使用Spork与Minitest。 我看到有一个spork-minitestgem ,但目前尚不清楚如何使用它。

exception消息:在rails应用程序中没有要加载此类文件

我在rails应用程序中包含了test_helper.rb 。 我甚至在test->unit下的test.rb文件中包含了require ‘test_helper’ 。 当我在RubyMine中为应用程序运行所有测试时,我收到以下错误: 我有所有RubyMine 3.2,ruby 1.9.2p290和Rails 3.1.0的最新版本。 /Users/im/.rvm/rubies/ruby-1.9.2-p290/bin/ruby -e $stdout.sync=true;$stderr.sync=true;load($0=ARGV.shift) /Applications/RubyMine 3.2.4.app/rb/testing/runner/tunit_in_folder_runner.rb Testing started at 3:19 PM … Work directory: /Users/im/RubymineProjects/BackChannelApp} Loading files…. ========================================= Fail to load: /Users/im/RubymineProjects/BackChannelApp/test/performance/browsing_test.rb:1 Exception message: no such file to load — test_helper /Users/im/RubymineProjects/BackChannelApp/test/performance/browsing_test.rb:1:in `require’ /Users/im/RubymineProjects/BackChannelApp/test/performance/browsing_test.rb:1:in `’ /Applications/RubyMine 3.2.4.app/rb/testing/runner/tunit_in_folder_runner.rb:48:in `require’ /Applications/RubyMine 3.2.4.app/rb/testing/runner/tunit_in_folder_runner.rb:48:in `block in load_scripts_to_object_space’ /Applications/RubyMine 3.2.4.app/rb/testing/runner/tunit_in_folder_runner.rb:40:in `each’ […]