Class: PigSpec::Test

Inherits:
Object
  • Object
show all
Includes:
Cleanroom
Defined in:
lib/pigspec.rb

Overview

TestCase of PigSpec

Class Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Class Attribute Details

.bridgeObject (readonly)

Returns the value of attribute bridge.



14
15
16
# File 'lib/pigspec.rb', line 14

def bridge
  @bridge
end

Class Method Details

.constructObject



15
16
17
18
19
# File 'lib/pigspec.rb', line 15

def construct
  @bridge ||= JavaBridge.new
rescue ArgumentError
  raise 'Environment variable PIG_HOME does not found or does not correct. It must point to your installation of Apache Pig.'
end

Instance Method Details

#override(name, value) ⇒ Object



52
53
54
# File 'lib/pigspec.rb', line 52

def override(name, value)
  @override.push name: name, value: value
end

#pickup(name) ⇒ Object

to ‘expose’



58
59
60
# File 'lib/pigspec.rb', line 58

def pickup(name)  # rubocop:disable Style/TrivialAccessors
  @pickup = name
end

#runObject



63
64
65
66
67
68
69
70
71
# File 'lib/pigspec.rb', line 63

def run
  # If no output alias, must result nil
  return nil unless @pickup

  test = Test.bridge.create_test @script, *@args
  test.register_script
  apply_override test
  test.run_script @pickup
end

#script(text) ⇒ Object



37
38
39
# File 'lib/pigspec.rb', line 37

def script(text)
  @script = text.split("\n")
end

#script_file(path) ⇒ Object



42
43
44
# File 'lib/pigspec.rb', line 42

def script_file(path)
  @script = open(path, 'r') { |f| f.each_line.to_a }
end

#setupObject



22
23
24
25
26
27
28
# File 'lib/pigspec.rb', line 22

def setup
  Test.construct
  @script = []
  @args = []
  @override = []
  @pickup = nil
end

#shutdownObject



30
31
32
33
34
35
# File 'lib/pigspec.rb', line 30

def shutdown
  # Rjb unload -> load is not work.(current restriction.)
  # s.a https://github.com/arton/rjb/issues/34
  # If the JNI bug fixed then we can uncomment follow line.
  # @bridge.unload
end

#with_args(*args) ⇒ Object



47
48
49
# File 'lib/pigspec.rb', line 47

def with_args(*args)
  @args = args
end