turnip-extra_steps 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 78668623baa32beebf1035e632b879c237a855c4
4
+ data.tar.gz: 465f9bd5e7caeb2cfc63959aa90f4999ce8e9cff
5
+ SHA512:
6
+ metadata.gz: 4698a192d56526d48156343c75deb5a89cdeb732ca7cdd62f8d24af9fcf329de0355b7faf123ccf520fdbb70b2f3ac348a9af50bc5d6dce59d6ea2107a840c59
7
+ data.tar.gz: 7a2d42f8c1284181f2cb48449bac230a366ce4f3262d5246f247a86fbce9cb90f4dbf293f61b094f19a651da4c742674297903df8496a90884e85bc15f18439c
data/.gitignore ADDED
@@ -0,0 +1,10 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ /vendor/
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require turnip/rspec
data/.travis.yml ADDED
@@ -0,0 +1,6 @@
1
+ language: ruby
2
+ cache: bundler
3
+ bundler_args: --without production
4
+ rvm:
5
+ - 2.2.2
6
+ env: CODECLIMATE_REPO_TOKEN=f28c26c394133fdd2d87979514fc5b717564e8ebcc3dcefbf59bd0b7a443a07b
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in turnip-extra_steps.gemspec
4
+ gemspec
data/Guardfile ADDED
@@ -0,0 +1,77 @@
1
+ # A sample Guardfile
2
+ # More info at https://github.com/guard/guard#readme
3
+
4
+ ## Uncomment and set this to only include directories you want to watch
5
+ # directories %w(app lib config test spec features)
6
+
7
+ ## Uncomment to clear the screen before every task
8
+ # clearing :on
9
+
10
+ ## Guard internally checks for changes in the Guardfile and exits.
11
+ ## If you want Guard to automatically start up again, run guard in a
12
+ ## shell loop, e.g.:
13
+ ##
14
+ ## $ while bundle exec guard; do echo "Restarting Guard..."; done
15
+ ##
16
+ ## Note: if you are using the `directories` clause above and you are not
17
+ ## watching the project directory ('.'), then you will want to move
18
+ ## the Guardfile to a watched dir and symlink it back, e.g.
19
+ #
20
+ # $ mkdir config
21
+ # $ mv Guardfile config/
22
+ # $ ln -s config/Guardfile .
23
+ #
24
+ # and, you'll have to watch "config/Guardfile" instead of "Guardfile"
25
+
26
+ # Note: The cmd option is now required due to the increasing number of ways
27
+ # rspec may be run, below are examples of the most common uses.
28
+ # * bundler: 'bundle exec rspec'
29
+ # * bundler binstubs: 'bin/rspec'
30
+ # * spring: 'bin/rspec' (This will use spring if running and you have
31
+ # installed the spring binstubs per the docs)
32
+ # * zeus: 'zeus rspec' (requires the server to be started separately)
33
+ # * 'just' rspec: 'rspec'
34
+
35
+ guard :rspec, cmd: "bundle exec rspec" do
36
+ require "guard/rspec/dsl"
37
+ dsl = Guard::RSpec::Dsl.new(self)
38
+
39
+ # Feel free to open issues for suggestions and improvements
40
+
41
+ # RSpec files
42
+ rspec = dsl.rspec
43
+ watch(rspec.spec_helper) { rspec.spec_dir }
44
+ watch(rspec.spec_support) { rspec.spec_dir }
45
+ watch(rspec.spec_files)
46
+
47
+ # Ruby files
48
+ ruby = dsl.ruby
49
+ dsl.watch_spec_files_for(ruby.lib_files)
50
+
51
+ # Rails files
52
+ rails = dsl.rails(view_extensions: %w(erb haml slim))
53
+ dsl.watch_spec_files_for(rails.app_files)
54
+ dsl.watch_spec_files_for(rails.views)
55
+
56
+ watch(rails.controllers) do |m|
57
+ [
58
+ rspec.spec.("routing/#{m[1]}_routing"),
59
+ rspec.spec.("controllers/#{m[1]}_controller"),
60
+ rspec.spec.("acceptance/#{m[1]}")
61
+ ]
62
+ end
63
+
64
+ # Rails config changes
65
+ watch(rails.spec_helper) { rspec.spec_dir }
66
+ watch(rails.routes) { "#{rspec.spec_dir}/routing" }
67
+ watch(rails.app_controller) { "#{rspec.spec_dir}/controllers" }
68
+
69
+ # Capybara features specs
70
+ watch(rails.view_dirs) { |m| rspec.spec.("features/#{m[1]}") }
71
+
72
+ # Turnip features and steps
73
+ watch(%r{^spec/acceptance/(.+)\.feature$})
74
+ watch(%r{^spec/acceptance/steps/(.+)_steps\.rb$}) do |m|
75
+ Dir[File.join("**/#{m[1]}.feature")][0] || "spec/acceptance"
76
+ end
77
+ end
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Celso Fernandes
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,39 @@
1
+ # Turnip Extra Steps
2
+
3
+ [![Build Status](https://travis-ci.org/fernandes/turnip-extra_steps.svg?branch=master)](https://travis-ci.org/fernandes/turnip-extra_steps)
4
+ [![Code Climate](https://codeclimate.com/github/fernandes/turnip-extra_steps/badges/gpa.svg)](https://codeclimate.com/github/fernandes/turnip-extra_steps)
5
+ [![Test Coverage](https://codeclimate.com/github/fernandes/turnip-extra_steps/badges/coverage.svg)](https://codeclimate.com/github/fernandes/turnip-extra_steps)
6
+ [![security](https://hakiri.io/github/fernandes/turnip-extra_steps/master.svg)](https://hakiri.io/github/fernandes/turnip-extra_steps/master)
7
+ [![Dependency Status](https://gemnasium.com/fernandes/turnip-extra_steps.svg)](https://gemnasium.com/fernandes/turnip-extra_steps)
8
+ [![Inline docs](http://inch-ci.org/github/fernandes/turnip-extra_steps.svg?branch=master)](http://inch-ci.org/github/fernandes/turnip-extra_steps)
9
+ Block description
10
+
11
+ ## Installation
12
+
13
+ Add to your Gemfile:
14
+
15
+ `gem 'turnip-extra_steps'`
16
+
17
+ ## Roadmap
18
+
19
+ * Improve climate note and coverage
20
+ * Add custom placeholders
21
+ * Numeric
22
+
23
+ ## Contributing
24
+
25
+ TODO: Write CONTRIBUTING file
26
+
27
+ ### Questions and Bug reports
28
+
29
+ If you have any question, please open an issue! If you discover any bugs, feel free to create an issue on GitHub. Please add as much information as possible to help us fixing the possible bug. We also encourage you to help even more by forking and sending us a pull request.
30
+
31
+ https://github.com/fernandes/turnip-extra_steps/issues
32
+
33
+ ## Maintainers
34
+
35
+ * Celso Fernandes (https://github.com/fernandes)
36
+
37
+ ## License
38
+
39
+ [MIT License](LICENSE)
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ require "bundler/gem_tasks"
2
+
3
+ task :default => [:spec]
4
+
5
+ require 'rspec/core/rake_task'
6
+ RSpec::Core::RakeTask.new(:spec) do |t|
7
+ t.pattern = './spec/acceptance/**/*{_spec.rb,.feature}'
8
+ end
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "turnip/extra_steps"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
data/config.ru ADDED
@@ -0,0 +1,16 @@
1
+ # Combustion stuff
2
+ require 'rubygems'
3
+ require 'bundler'
4
+
5
+ require 'combustion'
6
+
7
+ Combustion.initialize! :all
8
+ run Combustion::Application
9
+
10
+ require 'rubygems'
11
+ require 'bundler'
12
+
13
+ Bundler.require :default, :development
14
+
15
+ Combustion.initialize! :all
16
+ run Combustion::Application
@@ -0,0 +1,8 @@
1
+ require "turnip/extra_steps/version"
2
+ require "turnip/extra_steps/support"
3
+
4
+ module Turnip
5
+ module ExtraSteps
6
+ # Your code goes here...
7
+ end
8
+ end
@@ -0,0 +1,8 @@
1
+ # coding: UTF-8
2
+
3
+ Dir[File.join(File.dirname(__FILE__), '*_steps.rb')].each do |f|
4
+ name = File.basename(f, '.rb')
5
+ unless name == 'all_steps'
6
+ require "turnip/extra_steps/#{name}"
7
+ end
8
+ end
@@ -0,0 +1,32 @@
1
+ # coding: UTF-8
2
+
3
+ # Marks scenario as pending
4
+ #Then /^it should work$/ do
5
+ step "it should work" do
6
+ pending
7
+ end
8
+
9
+ # Starts debugger, or Pry if installed
10
+ #Then /^debugger$/ do
11
+ step "debugger" do
12
+ if binding.respond_to? :pry
13
+ binding.pry
14
+ else
15
+ debugger
16
+ end
17
+
18
+ true # Ruby will halt in this line
19
+ end
20
+
21
+ ::RSpec.configure do |config|
22
+ # Waits 2 seconds after each step
23
+ config.after(slow_motion: true) do
24
+ sleep 2
25
+ end
26
+
27
+ # Waits for keypress after each step
28
+ config.after(single_step: true) do
29
+ print "Single Stepping. Hit enter to continue"
30
+ STDIN.getc
31
+ end
32
+ end
@@ -0,0 +1,148 @@
1
+ # coding: UTF-8
2
+
3
+ require 'turnip/extra_steps/support/mail_finder'
4
+
5
+ ::RSpec.configure do |config|
6
+ # Waits 2 seconds after each step
7
+ config.before do
8
+ ActionMailer::Base.deliveries.clear
9
+ end
10
+ end
11
+
12
+ #When /^I clear my e?mails$/ do
13
+ step "I clear my emails" do
14
+ ActionMailer::Base.deliveries.clear
15
+ end
16
+
17
+ # Example:
18
+ #
19
+ # Then an email should have been sent with:
20
+ # """
21
+ # From: max.mustermann@example.com
22
+ # Reply-To: mmuster@gmail.com
23
+ # To: john.doe@example.com
24
+ # Subject: The subject may contain "quotes"
25
+ # Attachments: ...
26
+ #
27
+ # Message body goes here.
28
+ # """
29
+ #
30
+ # You can skip lines, of course. Note that the mail body is only checked for
31
+ # _inclusion_.
32
+ #Then /^(an|no) e?mail should have been sent with:$/ do |mode, raw_data|
33
+
34
+ step "true with:" do
35
+ end
36
+
37
+ step "an email :whether_to have been sent with:" do |positive, raw_data|
38
+ patiently do
39
+ raw_data.strip!
40
+ header, body = raw_data.split(/\n\n/, 2) # 2: maximum number of fields
41
+ conditions = {}
42
+ header.split("\n").each do |row|
43
+ if row.match(/^[a-z\-]+: /i)
44
+ key, value = row.split(": ", 2)
45
+ conditions[key.underscore.to_sym] = value
46
+ end
47
+ end
48
+ conditions[:body] = body if body
49
+ @mail = MailFinder.find(conditions)
50
+ if positive
51
+ expect(@mail).to be_present
52
+ else
53
+ expect(@mail).not_to be_present
54
+ end
55
+ end
56
+ end
57
+
58
+ # nodoc
59
+ #TODO: improve regexp to this condition
60
+ #Then /^(an|no) e?mail should have been sent((?: |and|with|from "[^"]+"|bcc "[^"]+"|to "[^"]+"|the subject "[^"]+"|the body "[^"]+"|the attachments "[^"]+")+)$/ do |mode, query|
61
+ #patiently do
62
+ #conditions = {}
63
+ #conditions[:to] = $1 if query =~ /to "([^"]+)"/
64
+ #conditions[:cc] = $1 if query =~ / cc "([^"]+)"/
65
+ #conditions[:bcc] = $1 if query =~ /bcc "([^"]+)"/
66
+ #conditions[:from] = $1 if query =~ /from "([^"]+)"/
67
+ #conditions[:subject] = $1 if query =~ /the subject "([^"]+)"/
68
+ #conditions[:body] = $1 if query =~ /the body "([^"]+)"/
69
+ #conditions[:attachments] = $1 if query =~ /the attachments "([^"]+)"/
70
+ #@mail = MailFinder.find(conditions)
71
+ #expectation = mode == 'no' ? 'should_not' : 'should'
72
+ #@mail.send(expectation, be_present)
73
+ #end
74
+ #end
75
+
76
+
77
+ step "an email :whether_to have been sent with :mode" do |positive, query|
78
+ patiently do
79
+ conditions = {}
80
+ conditions[:to] = $1 if query =~ /to "([^"]+)"/
81
+ conditions[:cc] = $1 if query =~ / cc "([^"]+)"/
82
+ conditions[:bcc] = $1 if query =~ /bcc "([^"]+)"/
83
+ conditions[:from] = $1 if query =~ /from "([^"]+)"/
84
+ conditions[:subject] = $1 if query =~ /the subject "([^"]+)"/
85
+ conditions[:body] = $1 if query =~ /the body "([^"]+)"/
86
+ conditions[:attachments] = $1 if query =~ /the attachments "([^"]+)"/
87
+ @mail = MailFinder.find(conditions)
88
+ expectation = positive ? 'should' : 'should_not'
89
+ @mail.send(expectation, be_present)
90
+ end
91
+ end
92
+
93
+
94
+ # Only works after you have retrieved the mail using "Then an email should have been sent with:"
95
+ #When /^I follow the (first|second|third)? ?link in the e?mail$/ do |index_in_words|
96
+ step "I follow the :index_in_words link in the email" do |index_in_words|
97
+ mail = @mail || ActionMailer::Base.deliveries.last
98
+ index = { nil => 0, 'first' => 0, 'second' => 1, 'third' => 2 }[index_in_words]
99
+ url_pattern = %r{(?:http|https)://[^/]+([^"'\s\\]*)}
100
+ mail_body = MailFinder.email_text_body(mail).to_s
101
+ only_path = mail_body.scan(url_pattern)[index][0]
102
+ visit only_path
103
+ end
104
+
105
+ #Then /^no e?mail should have been sent$/ do
106
+ step "no email should have been sent" do
107
+ expect(ActionMailer::Base.deliveries).to be_empty
108
+ end
109
+
110
+ # Checks that the last sent email includes some text
111
+ #Then /^I should see "([^\"]*)" in the e?mail$/ do |text|
112
+ step "I should see :text in the email" do |text|
113
+ expect(MailFinder.email_text_body(ActionMailer::Base.deliveries.last)).to include(text)
114
+ end
115
+
116
+ # Print all sent emails to STDOUT.
117
+ #Then /^show me the e?mails$/ do
118
+ step "show me the email" do
119
+ ActionMailer::Base.deliveries.each do |mail|
120
+ p [mail.from, mail.to, mail.subject]
121
+ end
122
+ end
123
+
124
+
125
+ # Only works after you've retrieved the email using "Then an email should have been sent with:"
126
+ #
127
+ # Example:
128
+ #
129
+ # And that mail should have the following lines in the body:
130
+ # """
131
+ # All of these lines
132
+ # need to be present
133
+ # """
134
+ #Then /^that e?mail should( not)? have the following lines in the body:$/ do |negate, body|
135
+ step "that email :whether_to have the following lines in the body:" do |positive, body|
136
+ expectation = positive ? :should : :should_not
137
+ email_text_body = MailFinder.email_text_body(@mail)
138
+
139
+ body.to_s.strip.split(/\n/).each do |line|
140
+ email_text_body.send(expectation, include(line.strip))
141
+ end
142
+ end
143
+
144
+ # Only works after you've retrieved the email using "Then an email should have been sent with:"
145
+ # Checks that the text should be included in the retrieved email
146
+ step "that email should have the following body:" do |body|
147
+ MailFinder.email_text_body(@mail).should include(body.strip)
148
+ end
@@ -0,0 +1,43 @@
1
+ # Attach a file to the given model's last record.
2
+ #
3
+ # Example (Company has a `file` attribute):
4
+ #
5
+ # Given the file "image.png" was attached to the company above
6
+ #
7
+ # You may specify the attribute under which the file is stored …
8
+ #
9
+ # Example (Company has a `logo` attribute):
10
+ #
11
+ # Given the file "image.png" was attached as logo to the company above
12
+ #
13
+ # … or both a container class and its attribute name
14
+ #
15
+ # Example (Company has many `Image`s, `Image` has a `file` attribute)
16
+ #
17
+ # Given the file "image.png" was attached as Image/file to the company above
18
+ #
19
+ # To simultaneously set the `updated_at` timestamp:
20
+ #
21
+ # Given the file "some_file" was attached to the profile above at "2011-11-11 11:11"
22
+ #
23
+ #Given /^the file "([^"]*)" was attached(?: as (?:([^"]*)\/)?([^"]*))? to the ([^"]*) above(?: at "([^"]*)")?$/ do
24
+ #|path_to_file, container_name, relation_name, model_name, time_string|
25
+ step "the file :path_to_file, was attached as :container_name to the :relation_name above at :time_string" do
26
+ |path_to_file, container_name, relation_name, model_name, time_string|
27
+
28
+ object = model_name.camelize.constantize.last
29
+ time = Time.parse(time_string) if time_string.present?
30
+ relation_name ||= 'file'
31
+
32
+ if container_name.present?
33
+ container = container_name.camelize.constantize.new # Image.file = File... owner: gallery
34
+ container.owner = object
35
+ container.created_at = time if time
36
+ else
37
+ container = object # Person.avatar = File...
38
+ end
39
+
40
+ container.send("#{relation_name}=", File.new(path_to_file))
41
+ container.updated_at = time if time
42
+ container.save!
43
+ end