ruby - rails里面的feature文件是干什么用的?平时用的多吗?
高洛峰
高洛峰 2017-04-24 09:09:29
0
3
799

我看了一下,好像还是语义化的,非常神奇,这个特性是怎么用的呢?

Then "I should be served coffee" do
  @machine.dispensed_drink.should == "coffee"
end
高洛峰
高洛峰

拥有18年软件开发和IT教学经验。曾任多家上市公司技术总监、架构师、项目经理、高级软件工程师等职务。 网络人气名人讲师,...

reply all(3)
黄舟

This is not something from Rails, this is the steps definition of Cucumber. Cucumber is a BDD acceptance testing framework. The part you see is a piece of code for testing assertions. Cucumber uses a DSL that is close to natural language, so the syntax is very user-friendly. However, programmers themselves do not pursue the style of Cucumber, which is mostly used for commercial test scripts. Programmers themselves prefer procedural syntax, and proper semantics are enough. In the Ruby world, MiniTest and RSpec are more popular test frameworks.


Addition, after thinking about it carefully, this may not be Cucumber. I thought it was because of Then 这个方法,但是 Cucumber 似乎是在 Scenario 里才用 Then at first, right? (memory blurred)

If it’s RSpec or something like that, is there Then? Maybe extended DSL? It's possible, so jumping to the conclusion that it's Cucumber might be wrong.

But anyway, this is definitely test code and does not belong to Rails itself.

洪涛

In terms of usage, feature is used to make functional feature test cases, not only limited to Cucumber, RSpec can also use this, such as here https://github.com/agilejzl/blog-eye/tree/master/ spec/features, @nightire can have Then class process testing with gem 'rspec-example_steps'.

大家讲道理

It’s the code of cucumber. Then is used in the .feature file to describe the process, or in the _steps.rb file to parse the process. The one mentioned above is obviously the latter one. It is located under the path ../features/step_definitions/.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!