Tag: bdd

运行单个function时,Cucumber无法找到步骤

我刚刚将黄瓜安装到一个新的rails项目中(第一次从头开始设置)并且在运行所有测试( bundle exec cucumber )时它运行得非常好,但是当我运行单个function文件时找不到任何步骤。 我怎么开始调试这个? rails (3.2.13) cucumber-rails (1.3.1) cucumber (>= 1.2.0) # file listing features/ ├── campaigns │ ├── donating_campaigns.feature │ └── viewing_campaigns.feature ├── step_definitions │ └── campaign_steps.rb └── support └── env.rb

黄瓜测试 – 获取RoutingError

怎么了,伙计们。 请帮忙。 当我运行我的黄瓜测试时,我遇到了这个错误: No route matches {:action=>”show”, :controller=>”accounts”} (ActionController::RoutingError) ./features/support/paths.rb:40:in `path_to’ 耙路线显示: account GET /accounts/:id(.:format) {:action=>”show”, :controller=>”accounts”} cucumber_test.feature Scenario: Given… And… Then i should be on Show page function/支持/ paths.rb when /^Show page$/ account_path @account 的routes.rb Myapp::Application.routes.draw do resources :accounts

用黄瓜测试时,sql错误无法启动事务内的事务

我是黄瓜的新手,我正在学习BDD 当我尝试填写表单并创建记录时,会显示此sqlite错误,但是当我在浏览器中手动尝试代码时没有错误。 我正在使用rails 4。 这是我的控制器代码 class Admin::ItemsController < ApplicationController def index @items=Item.all end def new @item=Item.new end def create @item=Item.new items_params respond_to do |format| if @item.save format.html { redirect_to admin_items_path } else format.html { redirect_to new_admin_items_path } end end end private def items_params params.require(:item).permit(:name,:price) end end 这是我的function文件 Feature: Manage Items In order to make a […]

RSpec找不到Factorygirl的Factorys

我将在我的Rails3项目中使用RSpec和Factory girl。 我已安装工厂女孩,但它没有找到factorys我有这个错误 Failure/Error: Factory.build(:user).should_be valid No such factory: user spec / factories / user_factory.rb: Factory.define :user do |u| u.username ‘otto’ end 投机/ spec_helper.rb ENV[“RAILS_ENV”] ||= ‘test’ require File.expand_path(“../../config/environment”, __FILE__) require ‘rspec/rails’ require ‘factory_girl’ Dir[Rails.root.join(“spec/support/**/*.rb”)].each {|f| require f} RSpec.configure do |config| config.mock_with :rspec config.fixture_path = “#{::Rails.root}/spec/fixtures” config.use_transactional_fixtures = true end 的Gemfile: group :development, :test do […]

我应该何时在Cucumber和RSpec工作流程中单独测试视图?

经过一段时间的Cucumber和RSpec BDD,我意识到我的许多黄瓜function只是更高级别的视图测试。 当我开始编写我的场景然后转到RSpec时,我不会编写视图规范,因为我可以复制并粘贴部分场景,这将是丑陋的复制。 以这种情况为例 Scenario: New user comes to the site Given I am not signed in When I go to the home page Then I should see “Sign up free” 我知道这不是直接测试视图,但是编写单独的视图规范来检查同样的事情对我来说似乎是多余的。 我接近黄瓜错了吗? 我究竟应该在视图规格中测试什么? 我应该为每个视图编写它们,例如测试视图的操作 def show @project = current_user.projects.first end 或者我应该只测试更复杂的视图?

何时在BDD循环中从黄瓜切换到rspec以进行登录过程

我还在尝试理解BDD循环中cucumber和rspec的组合。 我为一个非常简单的登录系统定义了以下场景: Feature: Log in In order to get access to the application As a user I want to log in Scenario: User logs in successfully Given I exist as a user When I go to the login page And I fill in “username” with “gabrielhilal” And I fill in “password” with “secret” And I […]

RSpec与Cookies – 即使应用程序正常工作(模拟已登录的用户),测试也会失败

我正在阅读Michael Hartl的“Ruby on Rails”Turorial“但我被困在这里。 我写了测试以检查用户编辑/更新的用户授权,我还编写了控制器代码, 它的工作原理如下: 如果用户未登录并尝试访问users#edit或users#update则会将其重定向到登录页面 如果用户已登录并且他尝试编辑另一个用户,则会将其重定向到根目录 问题是在测试第2点的规范中,我检查发送PUT请求到user_path我被重定向到root但运行rspec我得到以下错误: Failures: 1) Authentication authorization as wrong user submitting a PUT request to users#update Failure/Error: specify { response.should redirect_to(root_url) } Expected response to be a redirect to but was a redirect to # ./spec/requests/authentication_pages_spec.rb:73:in `block (5 levels) in ‘ 它似乎被重定向到signin_url而不是root_url ,就像用户根本没有登录一样……这就是我猜测导致问题的原因。 应用程序在cookie中存储令牌以对用户进行身份validation。 为了测试这个,我编写了一个名为signin_user(user)的辅助方法,并将其放在spec/support/utilities.rb文件中: # spec/support/utilities.rb def sign_in(user) […]

阿鲁巴黄瓜试验(ruby1.9.2)

我刚刚安装了aruba gem,它是黄瓜的延伸。 它允许您测试命令行应用程序 – 比如Rails中的生成器(但是,正如文档所指出的,您可以将它用于任何cmd应用程序)。 我一直关注这篇关于使用它的关键实验室文章 ,但由于某种原因它没有超越第一步:第一步是绿色(创建应用程序),但是下一步尝试cd test_app并且可以’找到它并失败。 Given I run “rails new test_app” # features/step_definitions/aruba_steps.rb:95 And I cd to “test_app” # features/step_definitions/aruba_steps.rb:91 tmp/aruba/test_app is not a directory. (RuntimeError) ./features/step_definitions/aruba_steps.rb:92:in `/^I cd to “([^”]*)”$/’ features/generators.feature:9:in `And I cd to “test_app”‘ 看起来应用程序文件夹实际上并没有被创建,虽然查看基础目录我可以看到tmp / aruba / folding 是 。 在探索源头一段时间后,我无法想出任何原因。 有没有其他人有这个gem的经验,发现了同样的事情? 是否有任何不错的BDD替代方案来测试发电机或佣金任务等? 进一步回答Ryans: 一旦我将以下内容添加到features/support/env.rb (从base rails目录开始): Before […]

使用Rails进行应用程序测试

这更像是一般性问题和某种最佳实践讨论。 如何测试Rails应用程序? 有像BDD和TDD这样的咒语和像RSpec和Cucumber这样的框架但是多少就足够了,最好的方法是什么? 使用Cucumber作为集成测试是否足够? 你们也在编写额外的unit testing吗? 那么你的Rails测试策略是什么以及如何? 期待好的意见……

如何使用Cucumber来测试非Ruby,非Rack API

我用黄瓜做很多事情。 我非常喜欢它作为BDD环境。 因此,我想将其用作测试API的外部工具。 我想做的事情如下: Scenario: Hit api /info path and get info back When I visit the API path ‘/info’ Then I should see the following text “Here’s info on the API” 或类似的东西。 我主要想将API视为黑盒子,只测试输入和输出。 我不打算检查API中的任何内容。 我看过的与Cucumber(例如Capybara)合作的大多数库似乎是基于基于Rack的应用程序设计的。 我想要类似的东西,但不依赖于Rack。 存在哪些没有机架依赖性的gem(如果有的话)。 或者有没有办法使用Capybara来测试远程服务器上的API?