Skip to content

Commit

Permalink
Merge pull request #5 from sobrinho/master
Browse files Browse the repository at this point in the history
Add tests
  • Loading branch information
whitequark committed Jul 6, 2015
2 parents 18738ef + 695afb8 commit 537a804
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 1 deletion.
1 change: 0 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,3 @@ source "http://rubygems.org"

# Specify your gem's dependencies in furnace.gemspec
gemspec
gem 'hanna-nouveau'
3 changes: 3 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
require 'bundler/gem_tasks'
require 'rspec/core/rake_task'
require 'rdoc/task'

RSpec::Core::RakeTask.new(:test)

Rake::RDocTask.new do |rd|
rd.main = 'README.rdoc'
rd.title = 'RLua Documentation'
Expand Down
1 change: 1 addition & 0 deletions rlua.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ Gem::Specification.new do |gem|
gem.add_development_dependency 'rdoc'
gem.add_development_dependency 'rake'
gem.add_development_dependency 'hanna-nouveau'
gem.add_development_dependency 'rspec'

gem.extra_rdoc_files = Dir['*.rdoc', 'ext/*.c'].to_a
gem.rdoc_options = ['--main=README.rdoc', '--title=RLua Documentation']
Expand Down
41 changes: 41 additions & 0 deletions spec/rlua_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
require 'rlua'

describe Lua::State do
context 'ruby' do
it 'creates a variable in Ruby and pass it to Lua' do
subject.value = 10

subject.__eval 'value = value * 2'

expect(subject.value).to eq 20
end

it 'creates a table in Ruby and pass it to Lua' do
subject.ruby = {
'meaning_of_life' => 42,
'zaphod' => lambda { |table| p "Meaning of life: #{table.meaning_of_life}" }
}

expect { subject.__eval "ruby:zaphod()" }.to output("\"Meaning of life: 42.0\"\n").to_stdout
end
end

describe 'lua' do
it 'creates a variable in Lua and pass it to Ruby' do
subject.__eval 'value = 15'

expect(subject.value).to eq 15
end

it 'creates a function in Lua and launch it from Ruby' do
subject.__eval "ran = false"
subject.__eval "function lua_func() ran = true end"

expect(subject.ran).to be_falsey

subject.lua_func

expect(subject.ran).to be_truthy
end
end
end

0 comments on commit 537a804

Please sign in to comment.