<commit_before>require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
require 'lyber_core'
require 'fakeweb'
require File.expand_path(File.dirname(__FILE__) + "/test_robot.rb")  

describe LyberCore::Robots::Robot do
  
  ROBOT_ROOT = File.expand_path(File.dirname(__FILE__) + "/../../fixtures/")      
  require "#{ROBOT_ROOT}/config/environments/test.rb"
    
  context "environment loading" do
    
    before(:all) do
      wf_name = "sdrIngestWF"
      wf_step = "populate-metadata"
      collection = "baz"
      valid_logfile = "/tmp/fakelog.log"
    end
      
    # it "raises an exception if WORKFLOW_URI is not defined" do
    #   pending "This test passes when run on its own, but undefining WORKFLOW_URI seems to break the other tests"
    #   Object.send(:remove_const, :WORKFLOW_URI) if defined? WORKFLOW_URI
    #   lambda { robot = TestRobot.new("sdrIngestWF", "populate-metadata", :logfile => valid_logfile) }.should raise_exception(/WORKFLOW_URI is not set/)        
    # end
      
  end
  
  context "initial state" do
    
    wf_name = "sdrIngestWF"
    wf_step = "populate-metadata"
    collection = "baz"
    
    before :each do
      require File.expand_path(File.dirname(__FILE__) + "/../../fixtures/config/environments/test.rb")  
    end
  
    it "has accessor methods" do
      robot = TestRobot.new(wf_name, wf_step, :collection_name => collection)
      robot.workflow_name.should eql(wf_name)
      robot.workflow_step.should eql(wf_step)
      robot.collection_name.should eql(collection)
    end
  
    # it "has a workflow after it has started" do
    #   ROBOT_ROOT = File.expand_path(File.dirname(__FILE__) + "/..")      
    #   robot = TestRobot.new("googleScannedBookWF","register-object", :collection_name => collection)
    #   robot.start
    #   puts robot.workflow
    # end
  
  end

  context "logging" do
    
    require 'dor_service'
    require 'dlss_service'
    require File.expand_path(File.dirname(__FILE__) + "/../../fixtures/config/environments/test.rb")  
    
    wf_name = "sdrIngestWF"
    wf_step = "populate-metadata"
    valid_logfile = "/tmp/fakelog.log"
    invalid_logfile = "/zzxx/fakelog.log"
   
    before :each do
      LyberCore::Log.restore_defaults
    end
  
    it "can set the location of the log file when it is created" do
      robot = TestRobot.new(wf_name, wf_step, :logfile => valid_logfile)
      LyberCore::Log.logfile.should eql(valid_logfile)
    end<commit_msg>Added a pending test for SDRTWO-317 but I don't think we're ready to change the way we're setting environment yet<commit_after>require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
require 'lyber_core'
require 'fakeweb'
require File.expand_path(File.dirname(__FILE__) + "/test_robot.rb")  

describe LyberCore::Robots::Robot do
  
  ROBOT_ROOT = File.expand_path(File.dirname(__FILE__) + "/../../fixtures/")      
  require "#{ROBOT_ROOT}/config/environments/test.rb"
    
  context "environment loading" do
    
    before(:all) do
      wf_name = "sdrIngestWF"
      wf_step = "populate-metadata"
      collection = "baz"
      valid_logfile = "/tmp/fakelog.log"
    end
      
    # it "raises an exception if WORKFLOW_URI is not defined" do
    #   pending "This test passes when run on its own, but undefining WORKFLOW_URI seems to break the other tests"
    #   Object.send(:remove_const, :WORKFLOW_URI) if defined? WORKFLOW_URI
    #   lambda { robot = TestRobot.new("sdrIngestWF", "populate-metadata", :logfile => valid_logfile) }.should raise_exception(/WORKFLOW_URI is not set/)        
    # end
      
  end
  
  context "initial state" do
    
    wf_name = "sdrIngestWF"
    wf_step = "populate-metadata"
    collection = "baz"
    
    before :each do
      require File.expand_path(File.dirname(__FILE__) + "/../../fixtures/config/environments/test.rb")  
    end
  
    it "has accessor methods" do
      robot = TestRobot.new(wf_name, wf_step, :collection_name => collection)
      robot.workflow_name.should eql(wf_name)
      robot.workflow_step.should eql(wf_step)
      robot.collection_name.should eql(collection)
    end
    
    it "can tell us what environment it's running in" do
      pending
      robot = TestRobot.new(wf_name, wf_step, :collection_name => collection)
      robot.env.should eql("test") 
    end
  
    # it "has a workflow after it has started" do
    #   ROBOT_ROOT = File.expand_path(File.dirname(__FILE__) + "/..")      
    #   robot = TestRobot.new("googleScannedBookWF","register-object", :collection_name => collection)
    #   robot.start
    #   puts robot.workflow
    # end
  
  end

  context "logging" do
    
    require 'dor_service'
    require 'dlss_service'
    require File.expand_path(File.dirname(__FILE__) + "/../../fixtures/config/environments/test.rb")  
    
    wf_name = "sdrIngestWF"
    wf_step = "populate-metadata"
    valid_logfile = "/tmp/fakelog.log"
    invalid_logfile = "/zzxx/fakelog.log"
   
    before :each do
      LyberCore::Log.restore_defaults
    end
  
    it "can set the location of the log file when it is created" do
      robot = TestRobot.new(wf_name, wf_step, :logfile => valid_logfile)
      LyberCore::Log.logfile.should eql(valid_logfile)
    end
{'fraction_non_alphanumeric': 0.11221374045801527, 'fraction_numerical': 0.0005725190839694657, 'mean_word_length': 2.943566591422122, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 12, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1196011', 'n_tokens_mistral': 1785, 'n_tokens_neox': 1753, 'n_words': 393}