Tag: rspec

如何使用RSpec而不使用Rails?

在没有Rails的情况下使用RSpec进行TDD的过程是什么? 我需要一个Gemfile吗? 它只需要rspec吗? Ruby 1.9.3

Rspec:testing实例variables的赋值

与工厂女孩一起使用Rspec。 尝试检查在我的控制器中分配了什么数据(并对其进行testing)。 我读过的每篇文章都说我应该能够从assigns()中获得一些东西,但是它一直在返回 调节器 def index @stickies = Sticky.where(:user_id => current_user.id) end 规格 it "should assign stickies" do foo = assigns(:stickies) puts "foo = #{foo}" end 产量 foo = 我使用错误的语法? 有一个更好的方法吗? 谢谢!!

Rspec – Rails – 如何遵循redirect

有谁知道如何使rspec遵循redirect(在控制器规范)? (例如,testing/单元具有follow_redirect!) 我试过“follow_redirect!” 和“follow_redirect”,但只能得到 undefined method `follow_redirect!' for #<Spec::Rails::Example::ControllerExampleGroup::Subclass_1:0xb6df5294> 例如: 当我创build一个帐户,该页面被redirect到帐户页面,我的新帐户应该在列表的顶部。 it "should create an account" do post :create, :name => "My New Account" FOLLOW_REDIRECT! response.code.should == "200" accounts = assigns[:accounts] accounts[0].name.should == "My New Account" end 但是FOLLOW_REDIRECT! 需要改变成实际工作的东西。

BDD与黄瓜和rspec – 何时是多余的?

Rails /工具特定版本: 你的unit testing有多深? 现在我写下: 黄瓜function(集成testing) – 这些testing针对我们的应用程序返回的HTML / JS,但有时也testing其他的东西,如调用第三方服务。 RSpec控制器testing(functiontesting),最初只有当控制器有任何有意义的逻辑,但现在越来越多。 RSpec模型testing(unit testing) 有时这是完全必要的; 有必要对模型中的行为进行testing,这对最终用户来说并不是完全明显或可见的。 模型复杂时,一定要进行testing。 但其他时候,在我看来,testing是多余的。 例如,如果你testing方法foo如果它只是由bar调用, bar进行testing? 如果bar是一个简单的辅助方法,在Cucumber特性中使用并且容易testing的模型会怎么样? 你是否在rspec和Cucumber中testing了这个方法? 我发现自己正在为此付出努力,因为编写更多的testing需要花费时间,并且维护实际上相同行为的多个“版本”,这使得维护testing套件的时间更加紧凑,从而导致更改更加昂贵。 总之,你是否相信有一段时间只写黄瓜function就够了? 还是应该经常在各个层面上进行testing? 如果您认为存在灰色地带,您需要进行function/unit testing的门槛是多less? 实际上,你现在做什么,为什么(或为什么不),你认为这是足够的? 编辑 : 这是一个什么可能是“testing矫枉过正”的例子。 诚然,我能够很快写出这个,但这完全是假设的。

水豚testing:js => true …路由错误:没有路由匹配“/ assets”

当我向他们添加“:js => true”时,我在一些testing中遇到类似的错误。 例如: An error occurred in an after hook ActionController::RoutingError: No route matches [GET] "/assets" occurred at /Users/appletart/.rvm/gems/ruby-1.9.3-p0@eventful2/gems/actionpack-3.2.5/lib/action_dispatch/middleware/debug_exceptions.rb:21:in `call' 我之前并没有在我的应用程序中testing启用JavaScript的东西,而只是通过升级到Capybara 2并安装数据库清理程序而设置了这样做。 config.use_transactional_fixtures = false,我已经在我的spec_helper文件中添加了一些前/后钩子(hooks?),我直接从接受的答案复制到这里 。 我在跑: Rails 3.2.5 Rspec-rails 2.12.2。 任何人都可以告诉我如何能攻击这个? 非常感谢! 4) Event pages 'CREATE' submitting a valid form provides a success notification and displays new event's page Failure/Error: Unable to find […]

使用RspectestingRails 3.1可挂载引擎

我开始制作一个Rails 3.1引擎,而且我很难用rspec来testing它。 首先,如果我运行rails g integration_test whatever它在testing/集成中创build常规集成testing而不是spec / requests(rspec-rails gem作为gemspec文件中的开发依赖项安装和需要) 此外,当我运行一个规范testing时,我得到一个错误,说与我正在testing的模型对应的表尚未创build。 我尝试了rake engine_name:install:migrations并运行rake db:migrate从虚拟应用程序内部rake db:migrate ,并得到“表已存在”错误。 一切似乎都是断开的,我觉得我错过了一些东西,使得rspec gem无缝地工作,就像通常使用完整的rails应用程序一样。 我跟着从这里http://rubyx.com/2011/03/01/start-your-engines的所有更改,我可以通过控制台启动虚拟应用程序手动testing引擎,如下所示http:// railscasts。 com / episodes / 277-mountable-engines 。 有没有办法让RSpectestingrails 3.1引擎的默认值?

如何将消息附加到rspec检查?

在rspec中:我是否可以像在xUnit样式testing框架中一样将消息附加到检查中? 怎么样? assert_equal value1, value2, "something is wrong"

FactoryGirl:多次创build相同的对象

在我的一个rspectesting中,我从同一个工厂定义创build了多个对象 例如 FactoryGirl.create(:model_1) FactoryGirl.create(:model_1) FactoryGirl.create(:model_1) 有没有一种方法, factory_girl提供这样做在一行 我知道我可以做到 3.times {FactoryGirl.create(:model_1)} 但是我正在寻找factory_girl提供的用于创build同一模型的多个对象的东西。

RSpec:如何testingRails日志消息的期望?

我正在尝试testingRailslogging器在我的一些规范中接收消息。 我正在使用Logging的gem 。 假设我有这样的课程: class BaseWorker def execute logger.info 'Starting the worker…' end end 和一个规范一样: describe BaseWorker do it 'should log an info message' do base_worker = BaseWorker.new logger_mock = double('Logging::Rails').as_null_object Logging::Rails.stub_chain(:logger, :info).and_return(logger_mock) logger_mock.should_receive(:info).with('Starting the worker…') base_worker.execute Logging::Rails.unstub(:logger) end end 我收到以下失败消息: Failure/Error: logger_mock.should_receive(:info).with('Starting worker…') (Double "Logging::Rails").info("Starting worker…") expected: 1 time received: 0 times 我已经尝试了几种不同的方法来使规范通过。 这适用于例如: […]

如何testing也定义为辅助方法的ApplicationController方法?

在我的ApplicationController中,我有一个方法定义为辅助方法: helper_method :some_method_here 我如何在RSpec中testingApplicationController? 在testing我的视图/帮助器时,如何包含/调用这个帮助器方法? 我使用RSpec2的Rails3