search

Home  >  Q&A  >  body text

ruby - rails里面的feature文件是干什么用的?平时用的多吗?

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

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

reply all(3)I'll reply

  • 黄舟

    黄舟2017-04-24 09:11:29

    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.

    reply
    0
  • PHP中文网

    PHP中文网2017-04-24 09:11:29

    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'.

    reply
    0
  • 大家讲道理

    大家讲道理2017-04-24 09:11:29

    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/.

    reply
    0
  • Cancelreply