Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Betty unit test. #88

Open
wants to merge 17 commits into
base: dev
Choose a base branch
from
21 changes: 21 additions & 0 deletions test/count_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#
# count_spec.rb
#
# Author: Muhammad Hussein Nasrollahpour
# Date: 2014
# Copyright: See the license agreement
#

require File.expand_path ".." + '/main.rb'
require File.expand_path ".." + '/lib/count'

# task: count executor unit tests which tests all the functionality
# coded in count module
describe "Count" do
context "count stuff" do
it "should count the total number of files located in specified location" do
command = Count.interpret("how many words are in this directory")[0][:command]
command.should eq("find . -type f -exec wc -w {} \\; | awk '{total += $1} END {print total}'")
end
end
end
38 changes: 38 additions & 0 deletions test/datetime_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#
# datetime_spec.rb
#
# Author: Muhammad Hussein Nasrollahpour
# Date: 2014
# Copyright: See the license agreement
#

require File.expand_path ".." + '/main.rb'
require File.expand_path ".." + '/lib/datetime'

# task: datetime executor unit tests which tests all the functionality
# coded in datetime module
describe Datetime do

context "time" do
it "should shows the current time" do
command = Datetime.interpret("what time is it")[0][:command]
command.should eq("date +\"%T\"")
end
end

context "date" do
it "should shows todays date" do
command = Datetime.interpret("what is todays date")[0][:command]
command.should eq("date +\"%m-%d-%y\"")

command = Datetime.interpret("whats today")[0][:command]
command.should eq("date +\"%A\"")
end

it "should shows month" do
command = Datetime.interpret("what month is it")[0][:command]
command.should eq("date +%B")
end
end

end
21 changes: 21 additions & 0 deletions test/find_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#
# find_spec.rb
#
# Author: Muhammad Hussein Nasrollahpour
# Date: 2014
# Copyright: See the license agreement
#

require File.expand_path ".." + '/main.rb'
require File.expand_path ".." + '/lib/find'

# task: find executor unit tests which tests all the functionality
# coded in find module
describe "Find" do
context "find stuff" do
it "should find stuff that user asks for it" do
command = Find.interpret("find me all files that contain california")[0][:command]
command.should eq("grep --include=\\* -Rn california .")
end
end
end
35 changes: 35 additions & 0 deletions test/internet_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#
# count_spec.rb
#
# Author: Muhammad Hussein Nasrollahpour
# Date: 2014
# Copyright: See the license agreement
#

require File.expand_path ".." + '/main.rb'
require File.expand_path ".." + '/lib/Internet'

# task: internet executor unit tests which tests all the functionality
# coded in internet module
describe "Internet" do
context "download" do
it "should download the contents of specified URL" do
command = Internet.interpret("download http://www.mysite.com/something.tar.gz to something.tar.gz")[0][:command]
command.should eq("curl -o something.tar.gz http://www.mysite.com/something.tar.gz")
end
end

context "uncompress" do
it "should uncompress the specified file" do
command = Internet.interpret("uncompress something.tar.gz")[0][:command]
command.should eq("mkdir something && tar -zxvf something.tar.gz -C something")
end
end

context "compress" do
it "should compress the specified file" do
command = Internet.interpret("compress /Ch0c0late/Cocoa/")[0][:command]
command.should eq("cd /Ch0c0late/Cocoa/; tar -czvf /Ch0c0late/Cocoa/.tar.gz *")
end
end
end
64 changes: 64 additions & 0 deletions test/itunes_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
#
# itunes_spec.rb
#
# Author: Muhammad Hussein Nasrollahpour
# Date: 2014
# Copyright: See the license agreement
#

require File.expand_path ".." + '/main.rb'
require File.expand_path ".." + '/lib/itunes'

# task: itunes executor unit tests which tests all the functionality
# coded in itunes module
describe "iTunes" do
context "mute and unmute" do
it "should mute iTunes" do
command = ITunes.interpret("mute itunes")[0][:command]
command.should eq("osascript -e 'tell application \"iTunes\" to set mute to true'")
end

it "should unmute iTunes" do
command = ITunes.interpret("unmute itunes")[0][:command]
command.should eq("osascript -e 'tell application \"iTunes\" to set mute to false'")
end
end

context "stop the music" do
it "should stop the music" do
command = ITunes.interpret("stop the music")[0][:command]
command.should eq("osascript -e 'tell application \"iTunes\" to stop'")
end

it "should pause the music" do
command = ITunes.interpret("pause the music")[0][:command]
command.should eq("osascript -e 'tell application \"iTunes\" to pause'")
end
end

context "start playing" do
it "should start playing music" do
command = ITunes.interpret("start the music")[0][:command]
command.should eq("osascript -e 'tell application \"iTunes\" to play'")
end
end

context "change song" do
it "should play next song" do
command = ITunes.interpret("next song")[0][:command]
command.should eq("osascript -e 'tell application \"iTunes\" to next track'")
end

it "should play previous track" do
command = ITunes.interpret("prev track")[0][:command]
command.should eq("osascript -e 'tell application \"iTunes\" to previous track'")
end
end

context "what song" do
it "should shows what song is playing" do
command = ITunes.interpret("what song is playing")[0][:command]
command.should eq("osascript -e 'tell application \"iTunes\" to get name of current track'")
end
end
end
21 changes: 21 additions & 0 deletions test/map_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#
# map_spec.rb
#
# Author: Muhammad Hussein Nasrollahpour
# Date: 2014
# Copyright: See the license agreement
#

require File.expand_path ".." + '/main.rb'
require File.expand_path ".." + '/lib/map'

# task: map executor unit tests which tests all the functionality
# coded in map module
describe Map do
context "show map" do
it "should show map of where user asked for it" do
command = Map.interpret("show me a map of mountain view")[0][:command]
command.should eq("open https://www.google.com/maps/search/mountain%20view")
end
end
end
32 changes: 32 additions & 0 deletions test/meta_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#
# meta_spec.rb
#
# Author: Muhammad Hussein Nasrollahpour
# Date: 2014
# Copyright: See the license agreement
#

require File.expand_path ".." + '/main.rb'
require File.expand_path ".." + '/lib/meta'

# task: meta executor unit tests which tests all the functionality
# coded in meta module
describe "Meta" do
context "betty's version" do
it "should shows betty version" do
command = Meta.interpret("what version are you")[0][:say]
command.should eq("0.1.5")

command = Meta.interpret("version")[0][:say]
command.should eq("0.1.5")
end

it "should shows betty website" do
command = Meta.interpret("url")[0][:say]
command.should eq("https://github.com/pickhardt/betty")

command = Meta.interpret("website")[0][:say]
command.should eq("https://github.com/pickhardt/betty")
end
end
end
23 changes: 23 additions & 0 deletions test/os_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#
# os_spec.rb
#
# Author: Muhammad Hussein Nasrollahpour
# Date: 2014
# Copyright: See the license agreement
#

require File.expand_path ".." + '/main.rb'
require File.expand_path ".." + '/lib/os'

# task: os executor unit tests which tests all the functionality
# coded in os module
describe OS do

context "find platform name" do
it "should find the OS it's running on and shows it" do
command = OS.interpret("what OS is used")[0][:command]
command.should eq("echo 'Linux'")
end
end

end
24 changes: 24 additions & 0 deletions test/permissions_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#
# permissions_spec.rb
#
# Author: Muhammad Hussein Nasrollahpour
# Date: 2014
# Copyright: See the license agreement
#

require File.expand_path ".." + '/main.rb'
require File.expand_path ".." + '/lib/permissions'

# task: permissions executor unit tests which tests all the functionality
# coded in permissions module
describe "Permissions" do
context "Change Ownership" do
it "should give ownership of a file to specified user" do
command = Permissions.interpret("give me permission to this directory")[0][:command]
command.should eq("sudo chown -R `whoami` .")

command = Permissions.interpret("give anotheruser ownership of myfile.txt")[0][:command]
command.should eq("sudo chown anotheruser myfile.txt")
end
end
end
32 changes: 32 additions & 0 deletions test/process_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#
# process_spec.rb
#
# Author: Muhammad Hussein Nasrollahpour
# Date: 2014
# Copyright: See the license agreement
#

require File.expand_path ".." + '/main.rb'
require File.expand_path ".." + '/lib/process'

# task: process executor unit tests which tests all the functionality
# coded in process module
describe "Process" do
context "Manipulate a running process" do
it "should list all the processes" do
Process.interpret("list of all processes")[0][:command].should eq("ps -afx")
end

it "should list all the processes running by the root user" do
Process.interpret("processes by user root")[0][:command].should eq("ps -U0")
end

it "should shows matching processes to specified thing running by the user" do
Process.interpret("show me my processes matching log")[0][:command].should eq("ps -U503 | grep log")

Process.interpret("show me all processes by root containing grep")[0][:command].should eq("ps -afx")

Process.interpret("show me all my processes containing netbio")[0][:command].should eq("ps -U503 | grep netbio")
end
end
end
36 changes: 36 additions & 0 deletions test/spotify_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#
# spotify_spec.rb
#
# Author: Muhammad Hussein Nasrollahpour
# Date: 2014
# Copyright: See the license agreement
#

require File.expand_path ".." + '/main.rb'
require File.expand_path ".." + '/lib/spotify'

# task: spotify executor unit tests which tests all the functionality
# coded in spotify module
describe "Spotify" do
context "Start playing" do
it "should start playing the music" do
Spotify.interpret("play spotify")[0][:command].should eq("osascript -e 'tell application \"spotify\" to play'")
end
end

context "Pause the music" do
it "should pause the music that is playing" do
Spotify.interpret("pause spotify")[0][:command].should eq("osascript -e 'tell application \"spotify\" to pause'")
end
end

context "Change track" do
it "should play next track" do
Spotify.interpret("next spotify")[0][:command].should eq("osascript -e 'tell application \"spotify\" to next track'")
end

it "should play previous track" do
Spotify.interpret("prev spotify")[0][:command].should eq("osascript -e 'tell application \"spotify\" to previous track'")
end
end
end
18 changes: 18 additions & 0 deletions test/translate_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#
# translate_spec.rb
#
# Author: Muhammad Hussein Nasrollahpour
# Date: 2014
# Copyright: See the license agreement
#

require File.expand_path ".." + '/main.rb'
require File.expand_path ".." + '/lib/translate'

# task: translate executor unit tests which tests all the functionality
# coded in translate module
describe "Translate" do
it "should translates a language to another one" do
Translate.interpret("translate something from English to Spanish")[0][:command].should eq("open https://translate.google.com/#English/Spanish/something")
end
end
Loading