Class: Evertils::Test::Base
- Inherits:
-
Minitest::Test
- Object
- Minitest::Test
- Evertils::Test::Base
- Defined in:
- lib/evertils/test/base.rb
Overview
Class Method Summary collapse
-
.after ⇒ Object
Run after all tests (check the Rakefile for specifics).
-
.before ⇒ Object
Run before all tests (check the Rakefile for specifics).
Instance Method Summary collapse
-
#clean ⇒ Object
Remove all seeded data after all tests have run.
- #seed ⇒ Object
- #setup ⇒ Object
Class Method Details
.after ⇒ Object
Run after all tests (check the Rakefile for specifics)
21 22 23 24 25 26 27 28 29 |
# File 'lib/evertils/test/base.rb', line 21 def self.after inst = Base.new(nil) Notify.spit "Performing teardown tasks" inst.setup Notify.spit "Deleting test data" inst.clean end |
.before ⇒ Object
Run before all tests (check the Rakefile for specifics)
8 9 10 11 12 13 14 15 16 17 |
# File 'lib/evertils/test/base.rb', line 8 def self.before inst = Base.new(nil) Notify.spit "Preparing to execute tests" inst.setup inst.clean Notify.spit "Seeding test data" inst.seed end |
Instance Method Details
#clean ⇒ Object
Remove all seeded data after all tests have run
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 |
# File 'lib/evertils/test/base.rb', line 79 def clean nb = Evertils::Common::Entity::Notebooks.new nbm = Evertils::Common::Manager::Notebook.instance notes = Evertils::Common::Entity::Notes.new auth = Evertils::Common::Authentication.instance tm = Evertils::Common::Entity::Tags.new = tm.all if .size > 0 puts "Deleting #{tags.size} tags..." .each do |tag| auth.call(:expungeTag, tag.guid) end end notebooks = nb.all if notebooks.size > 0 puts "Deleting #{notebooks.size - 1} notebooks..." # -1 for default notebook default = nbm.find_or_create('Default') notebooks.each do |nb| next if nb.guid == default.to_s auth.call(:expungeNotebook, nb.guid) end end notes = notes.all('testing') if notes.size > 0 puts "Deleting #{notes.size} notes..." notes.each do |note| auth.call(:expungeNote, note.guid) end end puts "Sample data deleted" end |
#seed ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/evertils/test/base.rb', line 43 def seed full_path = File.join(File.dirname(__FILE__), 'seed/all.yml') return unless File.exist? full_path begin conf = YAML::load(File.open(full_path)) nb = Evertils::Common::Entity::Notebook.new note = Evertils::Common::Entity::Note.new conf.each do |stack_name| stack_name.last.each_pair do |key, arr| puts "Creating: #{stack_name.first}/#{key}-#{@@test_time}..." ch_nb = nb.create({ title: "#{key}-#{@@test_time}" }, stack_name.first) arr.each do |child_note| child_note.each_pair do |name, | puts "Creating: #{stack_name.first}/#{key}/#{name}.note..." parsed = DateTime.parse(['created_on']) # created_on = (parsed.to_time.to_i.to_s + "000").to_i note.create(title: name, body: "Body for test note", parent_notebook: ch_nb, created_on: parsed) end end end end puts "Sample data seeded" rescue ArgumentError => e puts e. end end |
#setup ⇒ Object
33 34 35 36 37 38 39 |
# File 'lib/evertils/test/base.rb', line 33 def setup entity = Evertils::Common::Manager::Sync.instance Notify.error('Could not determine connection to the Evernote API, exiting') unless entity.state.is_a?(Evernote::EDAM::NoteStore::SyncState) @@test_time = Time.now.to_i end |