artichoke 0.0.1

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: a9c35daad5742135d314847c64df4ee0c44b1caf
4
+ data.tar.gz: 34cdaf8a43bcaa5b28fe374615fff4294e398725
5
+ SHA512:
6
+ metadata.gz: 4b405cdf7b2781f4473e7db93bcd25a384e75a593eb42aa7fa9634a9f9c0632cd40a0c8c0a5746795f5e04d86b2aab65c2c5be286892122e0da2e6c63ec8bc6d
7
+ data.tar.gz: 3b7fe0e9c0d8f43cc54e177251fc6c05b4964e98964f3086384d9986cd950e48e3486324f168aa8c5626a501be4c191cdbe03d544f4a729fd943496c73a6e5cb
data/README.md ADDED
@@ -0,0 +1,71 @@
1
+ # Artichoke
2
+
3
+ Artichoke is a library for gmail integration within testing suites. Artichoke is best used in conjuction with integration test tools such as RSpec, Capybara, and/or Cucumber. Artichoke uses Mail objects for storing the emails. The emails will not be marked as read on Gmail.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'artichoke'
10
+
11
+ Or install it yourself as:
12
+
13
+ $ gem install artichoke
14
+
15
+
16
+ ## Configuration
17
+
18
+ Add this to intializer:
19
+
20
+ Artichoke::Connection.configure do |config|
21
+ config.username = 'ninja@gmail.com'
22
+ config.password = 'topsecret'
23
+ end
24
+
25
+ ## Setting Poller Start Time
26
+
27
+ Artichoke uses a email polling system to find and evaluate email(s) information that can be later used for assertions or follow up actions. In order to set the start time for the polling system, you must create an instance of the poller for later use:
28
+
29
+ @poller = Artichoke::Poller.new
30
+
31
+ This is best used prior to an action that should trigger the email you want to evaluate.
32
+
33
+
34
+ ### Find email by subject
35
+
36
+ # You can pass in a defined timeout period for the poller to execute
37
+ # and if not defined, it will default to 75 seconds.
38
+ email = @poller.find({message_subject: "Ninjas are coming!!", timeout: 30})
39
+
40
+
41
+ ### Find email by subject and content(s)
42
+
43
+ # Find email by subject and single content criteria
44
+ email = @poller.find({message_subject: "Shinobi Poetry", timeout: 30, content: ["Blackest day"]})
45
+
46
+ # Find email by subject and multiple content criteria
47
+ email = @poller.find({message_subject: "Shinobi Poetry", timeout: 30, content: ["Blackest day", "Katana night"]})
48
+
49
+ ### Find email by subject and/or content(s) and/or attachment filenames
50
+
51
+ email = @poller.find({message_subject: "Shinobi Poetry", timeout: 30, content: ["Blackest day"], attachments: ["yohashi.pdf", "shuriken.png"]})
52
+
53
+
54
+ ### Assert that no email was sent with given criteria
55
+
56
+ # By default, the poller raises an error if no email was found
57
+ # within the determined timeout. However, you can pass the skip_error parameter
58
+ # in order to silence the error, so that you can assert no email was sent.
59
+ email = @poller.find({message_subject: "I wear Kimonos on weekends", timeout: 30, skip_error: false})
60
+ email.should be_nil
61
+
62
+ ### Evaluating and Manipulating the returned Message object
63
+
64
+ # You can now do evaluations on the email, such as reading the body
65
+ email.body.should have_content "I am forever in your debt master..."
66
+
67
+ # You can also evaluate attachments by calling email.attachments
68
+ # or return the first attachment's filename by using
69
+ email.attachment_name
70
+
71
+ For more operations that can be performed on the Message object, please visit [Mail](http://rubygems.org/gems/mail) rubygem. See its [documentation here](http://github.com/mikel/mail).
data/artichoke.gemspec ADDED
@@ -0,0 +1,19 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $: << File.expand_path('../lib', __FILE__)
3
+ require 'artichoke/version'
4
+
5
+ Gem::Specification.new do |gem|
6
+ gem.authors = ["Nathaniel Ritholtz"]
7
+ gem.email = ["nritholtz@gmail.com"]
8
+ gem.description = %q{A library for gmail integration within testing suites, best used in conjuction with integration test tools such as RSpec, Capybara, and/or Cucumber.}
9
+ gem.summary = %q{A library for gmail integration within testing suites.}
10
+ gem.homepage = "https://github.com/nritholtz/artichoke"
11
+
12
+ gem.files = `git ls-files`.split($\)
13
+ gem.name = "artichoke"
14
+ gem.require_paths = ["lib"]
15
+ gem.version = Artichoke::VERSION
16
+
17
+ gem.add_runtime_dependency 'ruby-gmail-nritholtz', '~> 0.3.3'
18
+ gem.add_runtime_dependency 'activesupport', '>= 3.1'
19
+ end
data/lib/artichoke.rb ADDED
@@ -0,0 +1,7 @@
1
+ require 'gmail'
2
+ require 'active_support'
3
+ require 'active_support/core_ext'
4
+
5
+ require 'artichoke/connection'
6
+ require 'artichoke/message'
7
+ require 'artichoke/poller'
@@ -0,0 +1,15 @@
1
+ module Artichoke
2
+ class Connection
3
+ include ActiveSupport::Configurable
4
+
5
+ config_accessor :username, :password
6
+
7
+ def self.client_username
8
+ config.username || raise("Please configure a username")
9
+ end
10
+
11
+ def self.client_password
12
+ config.password || raise("Please configure a password")
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,22 @@
1
+ module Artichoke
2
+ class Message
3
+
4
+ def initialize(message)
5
+ @message = message
6
+ end
7
+
8
+ def attachment_name
9
+ attachments.first.filename
10
+ end
11
+
12
+ private
13
+ # Delegate all other methods to the Gmail message
14
+ def method_missing(*args, &block)
15
+ if block_given?
16
+ @message.send(*args, &block)
17
+ else
18
+ @message.send(*args)
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,51 @@
1
+ module Artichoke
2
+ class Poller
3
+
4
+ def initialize
5
+ @gmail_start_time = DateTime.now
6
+ end
7
+
8
+
9
+ def client
10
+ username = Artichoke::Connection.client_username
11
+ password = Artichoke::Connection.client_password
12
+ begin
13
+ @gmail = Gmail.new(username, password)
14
+ @gmail.peek = true
15
+ yield
16
+ rescue Net::IMAP::ByeResponseError
17
+ retry
18
+ ensure
19
+ @gmail.disconnect
20
+ end
21
+ end
22
+
23
+
24
+ ### poller.find({message_subject: "Sample Email", timeout:75, content:["specific positioning", "footer"], attachments:["picture.jpg", "spreadsheet.csv"], skip_error: false})
25
+ def find(options={})
26
+ raise ArgumentError.new("Email Subject required") unless options[:message_subject]
27
+ begin
28
+ Timeout::timeout(options[:timeout]|| 75) do
29
+ while true do
30
+ client do
31
+ gm_string = "newer:#{@gmail_start_time.to_i} subject:"+options[:message_subject]
32
+ if options[:attachments]
33
+ options[:attachments].each{|attachment| gm_string += attachment+" "}
34
+ gm_string+= " has:attachment"
35
+ end
36
+ @gmail.inbox.emails(:gm => gm_string).each do |email|
37
+ message = email.message
38
+ if message.date.to_i >= @gmail_start_time.to_i
39
+ body = message.body.to_s.force_encoding('utf-8')
40
+ return Message.new(message) if (options[:content]|| []).all?{|c| body =~ /#{c}/}
41
+ end
42
+ end
43
+ end
44
+ end
45
+ end
46
+ rescue Timeout::Error => e
47
+ raise "No email was found with subject: #{options[:message_subject]} >= #{@gmail_start_time}, content(s): #{options[:content]||'N/A'}, attachment(s) #{options[:attachments]||'N/A'}" unless options[:skip_error]
48
+ end
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,3 @@
1
+ module Artichoke
2
+ VERSION = '0.0.1'
3
+ end
metadata ADDED
@@ -0,0 +1,79 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: artichoke
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Nathaniel Ritholtz
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-12-29 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: ruby-gmail-nritholtz
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 0.3.3
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 0.3.3
27
+ - !ruby/object:Gem::Dependency
28
+ name: activesupport
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '3.1'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '3.1'
41
+ description: A library for gmail integration within testing suites, best used in conjuction
42
+ with integration test tools such as RSpec, Capybara, and/or Cucumber.
43
+ email:
44
+ - nritholtz@gmail.com
45
+ executables: []
46
+ extensions: []
47
+ extra_rdoc_files: []
48
+ files:
49
+ - README.md
50
+ - artichoke.gemspec
51
+ - lib/artichoke.rb
52
+ - lib/artichoke/connection.rb
53
+ - lib/artichoke/message.rb
54
+ - lib/artichoke/poller.rb
55
+ - lib/artichoke/version.rb
56
+ homepage: https://github.com/nritholtz/artichoke
57
+ licenses: []
58
+ metadata: {}
59
+ post_install_message:
60
+ rdoc_options: []
61
+ require_paths:
62
+ - lib
63
+ required_ruby_version: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - ">="
66
+ - !ruby/object:Gem::Version
67
+ version: '0'
68
+ required_rubygems_version: !ruby/object:Gem::Requirement
69
+ requirements:
70
+ - - ">="
71
+ - !ruby/object:Gem::Version
72
+ version: '0'
73
+ requirements: []
74
+ rubyforge_project:
75
+ rubygems_version: 2.2.2
76
+ signing_key:
77
+ specification_version: 4
78
+ summary: A library for gmail integration within testing suites.
79
+ test_files: []