I have a script that I want to run within some tests using RSpec that I want to test the input / output on.
For example,
I have a script 'script.rb' that I run using 'ruby script.rb'
The script then outputs to STDOUT and takes an input using STDIN. I want to test this using RSPec and check that everything works appropriately (a feature test). How would I go about doing this? Just do an execute 'ruby script.rb' within RSPec and then test that the output is what I expect and that it takes input from STDIN?
Since you want to test your script as a black box (only STDIN/STDOUT), you may perfectly do it via system() call: just make sure to clean up all side effects your script is leaving (for example, temporary files).
EDIT: Just create some file with needed content, say stdin.txt.
After that you may run your command this way:
system('cat stdin.txt | ruby myscript.rb')
Related
So I have just created a geb script that tests the creation of a report. Let's call this Script A
I have other test cases I need to run that are dependent on the previous report being created, but I still want the Script A to be a stand alone test. we will call the subsiquent script Script B
Furthermore Script A generates a pair of numbers that will be needed in subsequent scripts (to verify data got recorded accurately)
Is there a way I can setup geb such that Script B executes 'Script Aand is able to pull those 2 numbers fromScript Ato be used inScript B`?
In summary there will be a number a scripts that are dependent on the actions of Script A (which is itself a test) I want to be able to modularize Script A so that it can be executed from other scripts. What would be the best way to do this?
For reuse and not repeating yourself I would put the report creation into a separate method call in a new class such as ReportGenerator, this would generate the report given a set of parameters (if required) and return the report figures for use in whatever test you like.
You could then call that in any spec you want, with no reliance on other specs.
I'm writing a simple applescript script for iTerm2 that generates a bunch of tabs and starts running services within them (I have a lot of microservices, and all need to be running to test things locally).
Things are mostly working, however I'm experiencing some slightly odd behavior which I think is related to applescript sending commands early. Let's look at a concrete example:
create tab with default profile
tell the current session
write text "cd services/myservice"
write text "make build-docker"
write text "make run-docker"
end tell
In theory, this chunk should
1) Create a new tab
2) Change into a new directory
3) Build a docker image and
4) Run that docker image.
This will occasionally work, but more frequently I run into problems on step 4. Specifically, I'll check the tab only to find out that 'make build-docker' was the last command run. This command takes some time, so I'm assuming "make run-docker" is sent while build is running and is ignored. Is there a way to force applescript/iTerm2 to wait for this command to finish so that run is executed correctly?
Hopefully this is clear. Thanks for reading!
If you have iTerm's shell integration enabled, you can poll is at shell prompt to determine if the command has finished:
tell application "iTerm2"
tell current window
create tab with profile "BentoBox"
tell current session
write text "sleep 5"
repeat while not (is at shell prompt)
delay 0.5
end repeat
write text "sleep 5"
end tell
end tell
end tell
Otherwise, you will want to string all the commands together in one tell:
write text "cd services/myservice; make build-docker; etc; etc; etc.."
Or place them in a shell script and execute that:
write text "my_super_duper_shell_script.sh"
Or use AppleScript to write the cmds to a tmp file and execute that:
re : How can I create or replace a file using Applescript?
I have a Rails webapp full of students with test scores. Each student has exactly one test score.
I want the following functionality:
1.) The user enters an arbitrary test score into the website and presses "enter"
2.) "Some weird magic where data is passed from Rails database to bash script"
3.) The following bash script is run:
./tool INPUT file.txt
where:
INPUT = the arbitrary test score
file.txt = a list of all student test scores in the database
4.) "More weird magic where output from the bash script is sent back up to a rails view and made displayable on the webpage"
And that's it.
I have no idea how to do the weird magic parts.
My attempt at a solution:
In the rails dbconsole, I can do this:
SELECT score FROM students;
which gives me a list of all the test scores (which satisfies the "file.txt" argument to the bash script).
But I still don't know how my bash script is supposed to gain access to that data.
Is my controller supposed to pass the data down to the bash script? Or is my model supposed to? And what's the syntax for doing so?
I know I can run a bash script from the controller like this:
system("./tool")
But, unfortunately, I still need to pass the arguments to my script, and I don't see how I can do that...
You can just use the built-in ruby tools for running shell commands:
https://ruby-doc.org/core-2.3.1/Kernel.html#method-i-60
For example, in one of my systems I need to get image orientation:
exif_orientation = `exiftool -Orientation -S "#{image_path}"`.to_s.chomp
Judging from my use of .to_s, running the command may sometimes return nil, and I don't want an error trying to chomp nil. A normal output includes the line ending which I feed to chomp.
In Fitnesse Commands: http://<host>:<port>/<suite path and test name>?responder=suite&startTest=TestTwo. I tried to execute. It is executing the test case which is passed in the url. If we pass the suite path and remove the test name, it is executing the whole suite. Is there any way we can run all tests coming after TestTwo?
No, you can run an entire suite or you can run an individual test. Perhaps you can break the suite into smaller sub-suites?
You can use firstTest parameters when calling the url. In your case, you can do:
http://<host>:<port>/<suite path>?responder=suite&firstTest=TestTwo
Note that, this only works based on alphabetical order of full path names of the test cases as mentioned in the fitnesse wiki here
firstTest: if present, only tests whose full path names are lexigraphically greater (later in alphabetical order) will be run. This is of questionable use since tests are not guaranteed to be run in any particular order.
Alternatively, you can tag certain test cases with tags, and execute them using parameter suiteFilter. You can find the relevant documentation in the same wiki page.
I am using specflow for writing my feature files .my feature files contains "#Tags"(like:#Authentication,#Login,#Permission,etc...) so i want to run all of them except #Authentication..
so can we use tag like:
~#Authentication so this will execute all test cases except test case containing #Authentication tag
As you have stated that you are running the tests from the command line using MSTest.exe then you should be able to run tests that are not in a category (according to the command line options like this:
"%VS100COMNTOOLS%..\IDE\MSTest.exe" /testcontainer:"Project.dll" /category:"!Authentication"