Guest User

Untitled

a guest
May 26th, 2018
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.82 KB | None | 0 0
  1. gem 'pickle', '0.2.11'
  2.  
  3. run 'bundle install'
  4.  
  5. file 'features/support/pickle.rb', <<-EOF
  6. # Make sure that you are loading your factory of choice in your cucumber environment
  7. #
  8. # For machinist add: features/support/machinist.rb
  9. #
  10. # require 'machinist/active_record' # or your chosen adaptor
  11. # require File.dirname(__FILE__) + '/../../spec/blueprints' # or wherever your blueprints are
  12. # Before { Sham.reset } # to reset Sham's seed between scenarios so each run has same random sequences
  13. #
  14. # For FactoryGirl add: features/support/factory_girl.rb
  15. #
  16. # require 'factory_girl'
  17. # require File.dirname(__FILE__) + '/../../spec/factories' # or wherever your factories are
  18. #
  19. # You may also need to add gem dependencies on your factory of choice in <tt>config/environments/cucumber.rb</tt>
  20.  
  21. require 'pickle/world'
  22. # Example of configuring pickle:
  23. #
  24. # Pickle.configure do |config|
  25. # config.adapters = [:machinist]
  26. # config.map 'I', 'myself', 'me', 'my', :to => 'user: "me"'
  27. # end
  28. Pickle.configure do |config|
  29. config.adapters = [:machinist]
  30. end
  31. EOF
  32.  
  33. file 'features/step_definitions/pickle_steps.rb', <<-EOF
  34. # create a model
  35. Given(/^\#{capture_model} exists?(?: with \#{capture_fields})?$/) do |name, fields|
  36. create_model(name, fields)
  37. end
  38.  
  39. # create n models
  40. Given(/^(\d+) \#{capture_plural_factory} exist(?: with \#{capture_fields})?$/) do |count, plural_factory, fields|
  41. count.to_i.times { create_model(plural_factory.singularize, fields) }
  42. end
  43.  
  44. # create models from a table
  45. Given(/^the following \#{capture_plural_factory} exists?:?$/) do |plural_factory, table|
  46. create_models_from_table(plural_factory, table)
  47. end
  48.  
  49. # find a model
  50. Then(/^\#{capture_model} should exist(?: with \#{capture_fields})?$/) do |name, fields|
  51. find_model!(name, fields)
  52. end
  53.  
  54. # not find a model
  55. Then(/^\#{capture_model} should not exist(?: with \#{capture_fields})?$/) do |name, fields|
  56. find_model(name, fields).should be_nil
  57. end
  58.  
  59. # find models with a table
  60. Then(/^the following \#{capture_plural_factory} should exists?:?$/) do |plural_factory, table|
  61. find_models_from_table(plural_factory, table).should_not be_any(&:nil?)
  62. end
  63.  
  64. # find exactly n models
  65. Then(/^(\d+) \#{capture_plural_factory} should exist(?: with \#{capture_fields})?$/) do |count, plural_factory, fields|
  66. find_models(plural_factory.singularize, fields).size.should == count.to_i
  67. end
  68.  
  69. # assert equality of models
  70. Then(/^\#{capture_model} should be \#{capture_model}$/) do |a, b|
  71. model!(a).should == model!(b)
  72. end
  73.  
  74. # assert model is in another model's has_many assoc
  75. Then(/^\#{capture_model} should be (?:in|one of|amongst) \#{capture_model}(?:'s)? (\w+)$/) do |target, owner, association|
  76. model!(owner).send(association).should include(model!(target))
  77. end
  78.  
  79. # assert model is not in another model's has_many assoc
  80. Then(/^\#{capture_model} should not be (?:in|one of|amongst) \#{capture_model}(?:'s)? (\w+)$/) do |target, owner, association|
  81. model!(owner).send(association).should_not include(model!(target))
  82. end
  83.  
  84. # assert model is another model's has_one/belongs_to assoc
  85. Then(/^\#{capture_model} should be \#{capture_model}(?:'s)? (\w+)$/) do |target, owner, association|
  86. model!(owner).send(association).should == model!(target)
  87. end
  88.  
  89. # assert model is not another model's has_one/belongs_to assoc
  90. Then(/^\#{capture_model} should not be \#{capture_model}(?:'s)? (\w+)$/) do |target, owner, association|
  91. model!(owner).send(association).should_not == model!(target)
  92. end
  93.  
  94. # assert model.predicate?
  95. Then(/^\#{capture_model} should (?:be|have) (?:an? )?\#{capture_predicate}$/) do |name, predicate|
  96. if model!(name).respond_to?("has_\#{predicate.gsub(' ', '_')}")
  97. model!(name).should send("have_\#{predicate.gsub(' ', '_')}")
  98. else
  99. model!(name).should send("be_\#{predicate.gsub(' ', '_')}")
  100. end
  101. end
  102.  
  103. # assert not model.predicate?
  104. Then(/^\#{capture_model} should not (?:be|have) (?:an? )?\#{capture_predicate}$/) do |name, predicate|
  105. if model!(name).respond_to?("has_\#{predicate.gsub(' ', '_')}")
  106. model!(name).should_not send("have_\#{predicate.gsub(' ', '_')}")
  107. else
  108. model!(name).should_not send("be_\#{predicate.gsub(' ', '_')}")
  109. end
  110. end
  111.  
  112. # model.attribute.should eql(value)
  113. # model.attribute.should_not eql(value)
  114. Then(/^\#{capture_model}'s (\w+) (should(?: not)?) be \#{capture_value}$/) do |name, attribute, expectation, expected|
  115. actual_value = model(name).send(attribute)
  116. expectation = expectation.gsub(' ', '_')
  117.  
  118. case expected
  119. when 'nil', 'true', 'false'
  120. actual_value.send(expectation, send("be_\#{expected}"))
  121. when /^[+-]?[0-9_]+(\.\d+)?$/
  122. actual_value.send(expectation, eql(expected.to_f))
  123. else
  124. actual_value.to_s.send(expectation, eql(eval(expected)))
  125. end
  126. end
  127.  
  128. # assert size of association
  129. Then /^\#{capture_model} should have (\d+) (\w+)$/ do |name, size, association|
  130. model!(name).send(association).size.should == size.to_i
  131. end
  132. EOF
  133.  
  134. git :add => '.'
  135. git :commit => "-am 'Added Pickle for Cucumber'"
Add Comment
Please, Sign In to add comment