class Evertils::Test::Base

Public Class Methods

after() click to toggle source

Run after all tests (check the Rakefile for specifics) @since 0.3.0

# 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() click to toggle source

Run before all tests (check the Rakefile for specifics) @since 0.3.0

# 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

Public Instance Methods

clean() click to toggle source

Remove all seeded data after all tests have run @since 0.3.0

# 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

  tags = tm.all

  if tags.size > 0
    puts "Deleting #{tags.size} tags..."
    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() click to toggle source

@since 0.3.0

# 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, options|
            puts "Creating: #{stack_name.first}/#{key}/#{name}.note..."
            parsed = DateTime.parse(options['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.message
  end
end
setup() click to toggle source

@since 0.3.0

# 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