Class: Capybara::AsyncRunner::Command

Inherits:
Object
  • Object
show all
Includes:
Capybara::AsyncRunner::Commands::Configuration, Capybara::AsyncRunner::Commands::Responders, Capybara::AsyncRunner::Commands::Templates
Defined in:
lib/capybara/async_runner/command.rb

Overview

A common class for defining your commands

Every command MUST have a name and a .js.erb file

Examples:

# spec/support/async_runner/commands/some_command.rb
#
class SomeCommand < Capybara::AsyncRunner::Command
  self.command_name = :some_command_name
  self.file_to_run = 'your/path/to/file/without/extension'

  response :done
  response :fail do |data|
    JSON.parse(data)
  end
end

SomeCommand.new({}).invoke
# => result

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Capybara::AsyncRunner::Commands::Templates

#erb

Methods included from Capybara::AsyncRunner::Commands::Responders

included

Methods included from Capybara::AsyncRunner::Commands::Configuration

included

Constructor Details

#initialize(data = {}) ⇒ Command

Returns a new instance of Command.

Parameters:

  • data (Hash) (defaults to: {})

    data is available in template through <%= data %>



33
34
35
36
# File 'lib/capybara/async_runner/command.rb', line 33

def initialize(data = {})
  @uuid = SecureRandom.uuid
  @env = Capybara::AsyncRunner::Env.new(uuid, data, responders)
end

Instance Attribute Details

#envObject (readonly)

Returns the value of attribute env.



38
39
40
# File 'lib/capybara/async_runner/command.rb', line 38

def env
  @env
end

#uuidObject (readonly)

Returns the value of attribute uuid.



38
39
40
# File 'lib/capybara/async_runner/command.rb', line 38

def uuid
  @uuid
end

Instance Method Details

#invokeObject

Invokes the command and returns its result

See Also:



45
46
47
# File 'lib/capybara/async_runner/command.rb', line 45

def invoke
  js_builder.result
end