Creating a special assistant in rubymotion

I have some common methods used in several different specifications, I want to extract them to some place, for example, the specification assistant available from all specifications. Does anyone know how to do this?

+6
source share
3 answers

Here is something like quacks like spec_helper.

# _spec_helper.rb module SpecHelper ::App::Persistence = {} # global `before :each` ish def self.extended(base) base.before do ::App::Persistence.clear end end def foo_helper end end 

And then use it:

 # my_view_spec.rb describe "MyView" do extend SpecHelper before do foo_helper end ... 


Two things to remember:

  • The auxiliary specification file is specified in such a way that it is loaded first (leading underscore)

  • When running individual specifications (for example, files=my_view_spec.rb ), the auxiliary file should go - files=spec/my_view_spec.rb,spec/_spec_helper.rb

+1
source

I just throw my general methods used in the specifications (they are not encapsulated in Module or something else) in the spec / support / utilities.rb file, and Rubymotion seems to pick them up fine, although I don’t know if this is " the right "way to do it.

0
source

According to the current http://www.rubymotion.com/developer-center/articles/testing/#_spec_helpers

Spec helpers are created in the spec / helpers directory of the RubyMotion project. An example would be spec / helpers / extension.rb.

0
source

Source: https://habr.com/ru/post/918431/


All Articles