Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/61.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 在Rspec中是否有与之相反的行为?_Ruby On Rails_Ruby_Rspec_Rspec Rails - Fatal编程技术网

Ruby on rails 在Rspec中是否有与之相反的行为?

Ruby on rails 在Rspec中是否有与之相反的行为?,ruby-on-rails,ruby,rspec,rspec-rails,Ruby On Rails,Ruby,Rspec,Rspec Rails,有没有什么东西会影响到“你的行为不像”或“团队会因为(某些错误)而失败”呢?我在文档中没有看到任何内容,但我觉得这将是理想的功能。例如 shared_examples_for "a foo doer for admin" do it "does this" do ... end it "does that" do ... end end context "when logged in as an admin" do let(:admin) { Factor

有没有什么东西会影响到“你的行为不像”或“团队会因为(某些错误)而失败”呢?我在文档中没有看到任何内容,但我觉得这将是理想的功能。例如

shared_examples_for "a foo doer for admin" do
  it "does this" do
   ...
  end

  it "does that" do
   ...
  end
end

context "when logged in as an admin" do
  let(:admin)   { FactoryGirl :admin }
  before(:each) { sign_in_as admin }

  it_behaves_like "a foo doer for admin"
end

context "when logged in as a user" do
  let(:user)    { FactoryGirl :user }
  before(:each) { sign_in_as user }

  # is there something like this?
  group_will_fail_with("a foo doer for admin", SomeError) / it_behaves_not_like "a foo maker" / etc.
end

如果这是一个反模式,或者我的想法有问题,我们欢迎所有的更正。

为什么你不写一个共享的例子,期待负面的结果(
tìu的行为就像“被拒绝的用户”
)?或者是一个期望引发错误的共享示例(
它的行为类似于“引发403的请求”
)?这就是我最终要做的,它工作得很好。似乎这必须是一个足够常见的测试,才能有一种内置的方法来避免代码重复,因为我发送的是相同的请求,只是期望不同的响应?我认为共享示例(期望列表)与期望出现错误是完全不同的。我认为写这两种情况都是值得的——特别是因为RSpec使用不同的语法来指定返回值,而不是期望出现错误。但是您是否知道可以将参数传递给共享示例(请参阅:)?您可能只想传入预期结果:
它的行为类似于“管理员操作”、“失败”
,并处理共享示例中的不同情况?@spickermann这是一个很好的观点。我也不知道共享示例的参数,这是一个很好的提示,可能会按照我的想法做。然而,我想得越多,我同意简单地期望一个测试块以同样的方式失败可能不是开始测试的最佳方式。你只是在寻找“raise_error”匹配器吗?