

Testing $HOME with Cucumber and Aruba
source link: https://www.devroom.io/2014/04/15/testing-home-with-cucumber-and-aruba/?utm_campaign=Feed%3A+ariejan+%28ariejan%7Cdevroom.io%29
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Testing $HOME with Cucumber and Aruba
Posted:
2014-04-15
- Last updated:
2019-06-05
Tagged programming cucumber aruba
Cucumber and Aruba are awesome tools to write acceptance tests for your command line application. The allow you to do things like this:
Scenario: Exit with 0 when no examples are run
Given a file named "a_no_examples_spec.rb" with:
"""ruby
"""
When I run `rspec a_no_examples_spec.rb`
Then the exit status should be 0
And the output should contain "0 examples"
This example was taken from rspec-core.
Aruba basically does three things for you:
- Create and inspect files and directories
- Run commands
- Inspect output and exit status
The problem
Now, if you are writing a CLI that interacts with a configuration file in the user’s home directory, you’d write a cucumber like this:
Scenario: use .my-app configuration
Given a file named "~/.my-app" with:
"""
awesome_enabled: true
"""
When I run `my-app`
Then the output should contain "AWESOME"
But how does your app and Aruba differentiate between this generated test file and your actual configration file in your home directory? It doens’t.
The answer
The solution is quite easy and elegant, in your Before
set the $HOME
environment variable to a custom location inside the tmp/aruba
directory.
In features/support/env.rb
:
Before do
set_env 'HOME', File.expand_path(File.join(current_dir, 'home'))
FileUtils.mkdir_p ENV['HOME']
end
This will set $HOME
to tmp/aruba/home
in the context of your cucumbers (and execute binary). current_dir
automatically points to the right location for the aruba temporary directory.
Recommend
-
62
Single Page Apps are a popular approach to building web applications, but testing them in an end-to-end fashion is not simple; you need to load the backend (potentially a collection of APIs and databases), and make sure t...
-
19
1. JavaScript testing #1. Explaining types of tests. Basics of unit testing with Jest 2....
-
6
聊聊HPE Aruba及其云发展愿景 来源:Forbes 2021-04-22 13:49:54关键字: HPE 我参加了HPE Aruba举...
-
11
Aruba IAP-514 for APoS August 29, 2021 By Rowell Leave a Comment My trusty Aruba IAP-514 ha...
-
4
-
10
本文档中AP运行数据指: Aruba MM平台下,AP每Radio连接数量和总连接数量,Channel使用率。 早期是通过shell来实现数据获取,然后trapper到zabbix server.但是有个明显缺点: AP的名称不是LLD实现的,也就是说近百个AP都是人工手动创建的监控主机。
-
9
Aruba Country Code (CCODE) Generator 2022-05-28 03:01:41 # 网络
-
7
Convert Aruba CAP to IAP Convert Aruba CAP to IAP 2021-03-22 03:10:28 # 网络
-
5
Serial Console Cable for Aruba AP-205H Serial Console Cable for Aruba AP-205H 2022-10-17 20:19:14 #网络
-
9
HPE Aruba Networking widens net to include private 5G, SASE and data center networking
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK