Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Clivern committed Mar 10, 2021
1 parent f62f135 commit 10017d4
Show file tree
Hide file tree
Showing 8 changed files with 119 additions and 3 deletions.
27 changes: 27 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: Ruby CI

on:
push:
branches: [ $default-branch ]
pull_request:
branches: [ $default-branch ]

jobs:
build:

runs-on: ubuntu-latest

strategy:
matrix:
ruby-version: [2.7.x, 2.6.x, 2.5.x]

steps:
- uses: actions/checkout@v2
- name: Set up Ruby ${{ matrix.ruby-version }}
uses: ruby/setup-ruby@v1
with:
ruby-version: ${{ matrix.ruby-version }}
- name: Install dependencies
run: bundle install
- name: Run ci
run: make ci
35 changes: 35 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
RUBY ?= ruby
RDOC ?= rdoc
BUNDLE ?= bundle
RAKE ?= rake


help: Makefile
@echo
@echo " Choose a command run in Lynx:"
@echo
@sed -n 's/^##//p' $< | column -t -s ':' | sed -e 's/^/ /'
@echo


## docs: Generate Docs
.PHONY: doc
doc:
@echo ">> ============= Generate Docs ============= <<"
$(RDOC)


## test: Run test cases
.PHONY: test
test:
@echo ">> ============= Run Tests ============= <<"
$(RAKE) test


## ci: Run all CI tests.
.PHONY: ci
ci: test
@echo "\n==> All quality checks passed"


.PHONY: help
10 changes: 8 additions & 2 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,2 +1,8 @@
require "bundler/gem_tasks"
task :default => :spec
require 'rake/testtask'

Rake::TestTask.new do |t|
t.libs << 'test'
end

desc "Run tests"
task :default => :test
9 changes: 8 additions & 1 deletion lib/lynx.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
require "lynx/version"
require "lynx/translator"

module Lynx
class Error < StandardError; end
# Your code goes here...

class Hola
def hi(language)
translator = Lynx::Translator.new(language)
translator.hi
end
end
end
16 changes: 16 additions & 0 deletions lib/lynx/translator.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
module Lynx
class Translator
def initialize(language = "english")
@language = language
end

def hi
case @language
when "english"
"Hello World"
else
"Hello World"
end
end
end
end
Empty file removed test/.keep
Empty file.
12 changes: 12 additions & 0 deletions test/lynx/test_translator.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
require 'test/unit'
require 'lynx'

class TranslatorTest < Test::Unit::TestCase
def test_english_hello
assert_equal "Hello World", Lynx::Translator.new("english").hi()
end

def test_any_hello
assert_equal "Hello World", Lynx::Translator.new("any").hi()
end
end
13 changes: 13 additions & 0 deletions test/test_lynx.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
require 'test/unit'
require 'lynx'
require 'lynx/test_translator'

class HolaTest < Test::Unit::TestCase
def test_english_hello
assert_equal "Hello World", Lynx::Hola.new.hi("english")
end

def test_any_hello
assert_equal "Hello World", Lynx::Hola.new.hi("any")
end
end

0 comments on commit 10017d4

Please sign in to comment.