Rspec 标签和过滤器 - 过滤器的多个值?

发布于 2024-12-18 18:10:28 字数 478 浏览 1 评论 0原文

我有一个测试套件,可以跨软件应用程序的多个版本运行。我希望能够标记那些根据不同版本而变化的测试,以便我设置的过滤器仅运行针对该特定版本的测试。

我正在寻找类似的东西:

describe "the magic page", :version=>["all-magic", "some_magic"]
   it "exists!"
end

describe "the magic page", :version=>["no-magic"]
   it "does not exist!"
end

Rspec.configure do |config|
  this_version= some_version_parameter_passed_in || "no_magic"
  config.filter_run :version includes this_version
end

显然,这不起作用,但它应该让您了解我正在努力实现的目标。

I have a test suite that runs across several versions of a software application. I'd like to be able to tag those tests that vary based on different versions so that the filters I have set up only run the tests for this particular version.

I'm looking for something like:

describe "the magic page", :version=>["all-magic", "some_magic"]
   it "exists!"
end

describe "the magic page", :version=>["no-magic"]
   it "does not exist!"
end

Rspec.configure do |config|
  this_version= some_version_parameter_passed_in || "no_magic"
  config.filter_run :version includes this_version
end

Obviously, that doesn't work, but it should give you an idea of what I'm trying to accomplish.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

魂ガ小子 2024-12-25 18:10:28

实际上,您可以使用 Rspec 来做到这一点。查看文档< /a>,然后尝试这样的操作:

describe "the magic page", :all-magic => true, :some-magic => true
   it "exists!"
end

describe "the magic page", :no-magic => true
   it "does not exist!"
end

然后要使用 magic 标签运行测试,您可以使用以下命令:

rspec --tag magic

或者您可以编辑您的 .rspec

--tag magic

这对您有用吗?

You can actually do this with Rspec. Take a look at the docs, and try something like this:

describe "the magic page", :all-magic => true, :some-magic => true
   it "exists!"
end

describe "the magic page", :no-magic => true
   it "does not exist!"
end

Then to run the tests with the magic tag you can use the command:

rspec --tag magic

Or you can edit your .rspec:

--tag magic

Does this work for you?

荒人说梦 2024-12-25 18:10:28

您可以在过滤器中使用 lambda,如下所示:

config.filter_run_including :foo => lambda {|v| v == 'bar'}

所以您可以执行类似

config.filter_run_including :version => lambda {|v| v.include? current_version}

Or 的操作,仅使用正确的 :versions 运行测试(我认为这就是您正在寻找的),

config.filter_run_excluding :version => lambda {|v| !v.include? current_version}

You can use lambdas in your filter like this:

config.filter_run_including :foo => lambda {|v| v == 'bar'}

So you could do something like

config.filter_run_including :version => lambda {|v| v.include? current_version}

Or to only run tests with the correct :versions (I think this is what you're looking for),

config.filter_run_excluding :version => lambda {|v| !v.include? current_version}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文