Tag: tdd

是否有任何Haskell土地相当于Ruby-land的Bundler等。 al,如果没有,如何设计一个如此结构的项目?

读者注意 :请耐心等待。 我保证会有一个问题。 我有一个问题要解决,并对自己思考“哦,我会用Ruby做的。” $ bundle gem problemsolver create problemsolver/Gemfile create problemsolver/Rakefile create problemsolver/.gitignore create problemsolver/problemsolver.gemspec create problemsolver/lib/problemsolver.rb create problemsolver/lib/problemsolver/version.rb Initializating git repo in /tmp/harang/problemsolver 删除在s.add_development_dependency “rspec” problemsolver/problemsolver.gemspec对s.add_development_dependency “rspec”的评论,然后 $ bundle exec rspec –init The –configure option no longer needs any arguments, so true was ignored. create spec/spec_helper.rb create .rspec 新测试将进入spec/并且必须位于以_spec.rb结尾的文件中。 例如, spec/version_spec.rb describe ‘Problemsolver’ […]

黄瓜:自动步骤文件创建?

当我运行黄瓜时,它会显示我应该定义的可能步骤,这是RSpec书中的一个例子: 1 scenario (1 undefined) 4 steps (4 undefined) 0m0.001s You can implement step definitions for undefined steps with these snippets: Given /^I am not yet playing$/ do pending end When /^I start a new game$/ do pending end Then /^the game should say “Welcome to CodeBreaker”$/ do pending end Then /^the game should say […]

URI :: InvalidURIError:错误的URI(不是URI?)测试Rails控制器

我得到URI::InvalidURIError测试Rails Home控制器: require ‘test_helper’ class HomeControllerTest < ActionDispatch::IntegrationTest test "should get index" do get :index assert_response :success end end 得到以下错误: E Error: HomeControllerTest#test_should_get_index: URI::InvalidURIError: bad URI(is not URI?): http://www.example.com:80index test/controllers/home_controller_test.rb:7:in `block in ‘ 堆栈如下: Rails 5.0.0.beta3 minitest (5.8.4)

如何在rspec测试中定义一个可以由辅助函数接收的简单全局变量

我无法弄清楚如何在rspec测试中使用一个简单的全局变量。 这看起来像是一个微不足道的function,但经过一番戏剧性的努力,我找不到解决方案。 我想要一个可以在主要规范文件和辅助规范文件中的函数中访问/更改的变量。 这是我到目前为止: require_relative ‘spec_helper.rb’ require_relative ‘helpers.rb’ let(:concept0) { ” } describe ‘ICE Testing’ do describe ‘step1’ do it “Populates suggestions correctly” do concept0 = “tg” selectConcept() #in helper file. Sets concept0 to “First Concept” puts concept0 #echos tg?? Should echo “First Concept” end end 。 #helpers.rb def selectConcept concept0 = “First Concept” end […]

Capybara + RSpec仅在控制器规格中看到空白页。 为什么?

我正在尝试为简单的控制器编写控制器规范。 但是,Capybara没有看到任何页面内容。 但是,在浏览器中查看网站的页面效果很好。 我究竟做错了什么? 谢谢! 我的控制器规格 我的spec_helper.rb 我的Gemfile

Ruby存在C1代码覆盖率分析吗?

我目前正在使用Rcov为我正在开发的rails项目获取C0代码覆盖率分析。 然而,这些结果实际上毫无意义 – 根据rcov,我有100%的覆盖率(因为它仅涵盖C0分析),而且我几乎没有为目前存在的function编写一半的测试用例。 我已经习惯了Visual Studio 2008 Team中的代码覆盖率的有用结果,它具有C1覆盖率。 是否有任何工具可以为ruby提供类似的覆盖范围?

rspec测试的问题,未定义的方法’post’

当有人通过URL发送查询时,我正在编写一个规范来测试mashup_controller的行为。 我需要模拟URL中包含的参数,我读到post()方法会这样做,但是当我收到错误时: 1) MashupController simulates query Failure/Error: post :create NoMethodError: undefined method `post’ for # # ./mashup_controller_rspec.rb:9:in `block (2 levels) in ‘ Finished in 0.20199 seconds 1 example, 1 failure Failed examples: rspec ./mashup_controller_rspec.rb:7 # MashupController simulates query 这是我的代码: require ‘spec_helper’ require ‘mashup_controller.rb’ describe MashupController do it “simulates query” do post :create end end 对不起,如果我没有任何意义。 […]

如何使用黄瓜在场景之间共享状态

我有一个function“从外部网站导入文章”。 在我的第一个场景中,我测试从外部网站导入链接列表。 Feature: Importing articles from external website Scenario: Searching articles on example.com and return the links Given there is an Importer And its URL is “http://example.com” When we search for “demo” Then the Importer should return 25 links And one of the links should be “http://example.com/demo.html” 在我的步骤中,我在@result数组中有25个链接。 在我的第二个场景中,我想采取其中一个链接并测试我正确解析文章的事实。 现在显然我不想每次都去外部网站,特别是现在第一个场景通过了。 我如何继续这里,以便我可以继续测试而不需要为第一个场景发出HTTP请求? 或者我应该运行一次并将@result数组保留在其他方案中,以便我可以继续使用实际结果集吗?

如何用Ruby学习TDD?

我一直在使用ruby大约一个月,我真的很喜欢它。 但是,我使用甚至学习TDD都非常困难。 我的大脑不会那样运作…… 我真的,真的想学习TDD,但说实话我有点困惑。 我在Google上找到的所有文章都主要针对Rails,这对我来说并不感兴趣,因为我想学习如何对任何ruby应用程序进行高效测试,从简单的单文件脚本到复杂的gem,而不是网络应用。 此外,还有很多框架和很少的入门教程。 有人可以给我任何关于如何学习TDD的建议,这样我至少可以开始认为自己是一个有抱负的rubyist吗?

使用MiniTest检查模型上的方法调用

如果我使用RSpec,我可以测试是否正在调用方法: expect(obj).to receive(:method) MiniTest中的等价物是什么? 我有一个模型Post ,它有一个before_validation回调,它运行一个方法create_slug 。 在我的测试test/models/post_test.rb我想确保在调用post.save时调用create_slug方法。 Minitest :: Spec文档说我可以使用方法must_send来检查方法是否被调用。 但是,当我尝试@post.must_send :create_slug我收到以下错误: NoMethodError: undefined method `must_send’ for # 我在test_helper.rb文件中包含Minitest :: Spec: ENV[‘RAILS_ENV’] ||= ‘test’ require File.expand_path(‘../../config/environment’, __FILE__) require ‘rails/test_help’ require ‘minitest/spec’ class ActiveSupport::TestCase # Setup all fixtures in test/fixtures/*.yml for all tests in alphabetical order. # # Note: You’ll currently still have to declare […]